A Perl-based project designed as an Internet of Things (IoT) server, implemented as a mod_perl2 module for the Apache HTTP Server. It likely acts as a central hub for data collection, device communication, and management, leveraging Apache's robust web serving capabilities. The name "wiot" suggests a focus on Wireless IoT or a "Web of IoT" integration.
(As the detailed code content is not directly available, this section will list potential features based on the identified Perl server component and general IoT practices.)
- Apache HTTP Server Integration: Designed to run efficiently as a
mod_perl2handler, leveraging Apache's features for web serving and request handling. - IoT Device Server: Functions as a centralized backend for receiving data from and sending commands to IoT devices.
- Data Persistence: Integrates with SQLite to store sensor data, device information, and other relevant IoT metrics.
- Perl-based Backend: Utilizes Perl for robust server-side logic and processing.
- Scalable Architecture: Benefits from Apache's ability to handle concurrent connections, making it suitable for a growing number of IoT devices.
- API/Protocol Handling: (Assumed) Implements specific protocols for device communication (e.g., HTTP APIs, custom RESTful endpoints).
- Session Management: Likely handles user or device sessions for authentication and authorization.
These instructions will guide you through setting up the wiot server as a mod_perl2 module under Apache on your local machine for development and testing.
- Apache HTTP Server: Version 2.x
mod_perl2: The Apache Perl module, compatible with your Apache version.- Perl 5.x: (Ensure you have a recent version of Perl installed)
- CPAN: Perl's comprehensive archive network, for managing Perl modules.
- SQLite: For database storage.
- Required Perl modules: You will need to identify and install modules used by
Wiot::Server2(e.g.,DBI,DBD::SQLite,Apache2::Request,Apache2::Const,JSONif dealing with JSON data, etc.).
-
Clone the repository:
git clone [https://github.com/walley/wiot.git](https://github.com/walley/wiot.git) cd wiot -
Install Perl dependencies: Navigate to the
perldirectory within the cloned repository. You'll need to install any Perl modules thatWiot::Server2depends on.cd perl # Example modules - you will need to determine the actual dependencies from the code. sudo cpan install DBI DBD::SQLite Apache2::Request Apache2::Const JSON
If you encounter issues, you can run
sudo cpanand then use theinstallcommand for each module at the CPAN prompt. -
Database setup: The project uses SQLite for data storage. You need to create the database file and initialize its schema. The schema is defined in the
sqlite_schemafile at the root of the repository.# Assuming you are in the project root after cloning: sqlite3 wiot.db < sqlite_schema
(The name of the database file
wiot.dbis an assumption; it might be configured withinServer2.pmor Apache's configuration.) -
Configure Apache for
mod_perl2: Ensuremod_perl2is enabled in your Apache configuration (e.g.,httpd.confor a separate configuration file inconf.d/ormods-enabled/). You might need to add lines like:LoadModule perl_module modules/mod_perl.so <IfModule perl_module> PerlRequire /path/to/your/wiot/perl/Wiot/Server2.pm </IfModule>
Replace
/path/to/your/wiot/with the actual path to your clonedwiotrepository. -
Configure a Virtual Host or Location for
wiot: You'll need to configure an ApacheVirtualHostor<Location>block to handle requests and route them to yourWiot::Server2module. Here's an example:<VirtualHost *:80> ServerName your.iot.server.com DocumentRoot "/path/to/your/wiot/htdocs" # If you have static files <Location /api/wiot> SetHandler perl-script PerlHandler Wiot::Server2 # Optional: Set Perl variables that Server2.pm might use # PerlSetVar WiotDbPath /path/to/your/wiot/wiot.db Options +ExecCGI </Location> ErrorLog "${APACHE_LOG_DIR}/wiot_error.log" CustomLog "${APACHE_LOG_DIR}/wiot_access.log" combined </VirtualHost>
ServerName: Replace with your desired domain or IP.DocumentRoot: Adjust if your project includes a web root for static files.<Location /api/wiot>: This defines a URL path where your Perl module will handle requests. All requests tohttp://your.iot.server.com/api/wiot(or similar) will be processed byWiot::Server2.PerlHandler Wiot::Server2: This is the core directive that tellsmod_perl2to use theWiot::Server2module to handle requests for this location.PerlSetVar: If your Perl module requires configuration variables (e.g., database paths, API keys), you can pass them usingPerlSetVar. CheckServer2.pmfor expected variables.Options +ExecCGI: Often necessary formod_perlhandlers.
-
Restart Apache: After configuring Apache, you need to restart it for the changes to take effect:
sudo systemctl restart apache2 # On Debian/Ubuntu sudo apachectl restart # On RHEL/CentOS or general
-
Access the server: Once Apache is running, your
wiotserver will be accessible via the configured URL (e.g.,http://your.iot.server.com/api/wiot). You can then send requests from your IoT devices or client applications to this endpoint.(Further instructions will depend on the specific API or communication protocol
Wiot::Server2implements. Examples of how to send data or commands might be added here.)
The core Perl server logic is located at: /wiot/ ├── perl/ │ └── Wiot/ │ └── Server2.pm # The main mod_perl2 module ├── sqlite_schema # Database schema definition └── ... (other files, e.g., Apache config snippets, client examples)
perl/Wiot/Server2.pm: The main Perl module that handles HTTP requests when run undermod_perl2.sqlite_schema: Defines the SQLite database structure used by the server.
As identified from the sqlite_schema file, the project uses the following tables to manage IoT data:
sensors: Stores information about individual sensors.id(integer primary key AUTOINCREMENT)sn(numeric unique) - Serial Numbernote(varchar)
data: Stores the actual sensor readings or data points.id(integer primary key AUTOINCREMENT)sn(numeric) - Sensor Serial Number (referencessensors.sn)ts(numeric) - Timestamppq(varchar) - Physical Quantity (e.g., "temperature", "humidity")value(varchar) - The recorded valuesystemts(DATETIME DEFAULT (strftime('%s','now'))) - System timestamp
input: Possibly for incoming data or commands to devices.id(integer primary key AUTOINCREMENT)sn(varchar)variable(varchar)value(numeric)type(varchar)
session: For user sessions or device authentication.acc(varchar)sessid(varchar primary key)username(varchar)
house: To organize devices by location.id(integer primary key AUTOINCREMENT)name(varchar)address(varchar)location(varchar)
room: Sub-division within a house.id(integer primary key AUTOINCREMENT)house(numeric) - Referenceshouse.idname(varchar)
devices: Detailed information about individual IoT devices.id(integer primary key AUTOINCREMENT)name(varchar)type(varchar)image(varchar)room(integer) - Referencesroom.idnote(varchar)
Indexes:
tsindexondata(sn,pq,systemts)stsindexondata(systemts)pqindexondata(pq)snindexondata(sn)
We welcome contributions to the wiot project! If you'd like to contribute, please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix:
git checkout -b feature/your-feature-nameorbugfix/your-bug-fix-name. - Make your changes and commit them with clear, concise messages.
- Push your changes to your forked repository.
- Open a pull request to the
mainbranch of this repository, describing your changes in detail.
Please ensure your Perl code adheres to any existing coding standards and includes appropriate tests.
This project is likely licensed under an open-source license. (Please specify the exact license here once confirmed, e.g., MIT, Apache 2.0, GPLv3. If no license file exists, consider adding one.)
Example:
This project is licensed under the MIT License - see the LICENSE file for details.
If you have any questions, suggestions, or issues, feel free to open an issue on the GitHub repository or contact the project owner directly.