AQSense is an air quality monitoring project that leverages a Raspberry Pi and the SDS011 sensor to measure air quality. Data is stored in a SQLite database and visualized through a web server.
- Air Quality Measurement: Collects data from the SDS011 sensor.
- Data Logging: Stores air quality measurements in a SQLite database.
- Web Visualization: Provides a web server for real-time visualization of air quality data.
- Automated Services: Uses systemd services for automatic startup and management of both measurement and web server components.
Clone the repository to your local machine:
git clone https://github.com/xelemir/AQSense.git
cd AQSense
Create and activate a Python virtual environment:
python -m venv .venv
source .venv/bin/activate
With your virtual environment activated, install the required packages:
pip install -r requirements.txt
After installing the required packages, you can deactivate the virtual environment:
deactivate
AQSense uses two systemd services: one for the web server and one for the air quality measurement daemon.
Note: Replace USERNAME with your actual username and adjust paths if needed.
Create the file /etc/systemd/system/webserver.service with the following content:
[Unit]
Description=Web Server for AQSense
After=network.target
[Service]
User=USERNAME
WorkingDirectory=/home/USERNAME/AQSense
ExecStart=/home/USERNAME/AQSense/.venv/bin/python /home/USERNAME/AQSense/web_app.py
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
Create another service file (for example, /etc/systemd/system/air_quality.service) with the following content:
[Unit]
Description=Air Quality Measurement for AQSense
After=network.target sound.target
[Service]
User=USERNAME
WorkingDirectory=/home/USERNAME/AQSense
ExecStart=/home/USERNAME/AQSense/.venv/bin/python /home/USERNAME/AQSense/main.py
ExecStop=/home/Python/AQSense/.venv/bin/python /home/USERNAME/AQSense/stop_script.py
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
First, reload the systemd daemon:
sudo systemctl daemon-reload
Then, enable and start the services:
sudo systemctl enable webserver.service
sudo systemctl start webserver.service
sudo systemctl enable air_quality.service
sudo systemctl start air_quality.service
To check the status of the services, use:
sudo systemctl status webserver.service
sudo systemctl status air_quality.service
Stop the services with:
sudo systemctl stop webserver.service
sudo systemctl stop air_quality.service
Completly disable the services with:
sudo systemctl disable webserver.service
sudo systemctl disable air_quality.service
Now that the services are running, you can access the web server by navigating to http://:1337 in your web browser. The web server provides real-time visualization of the air quality data collected by the SDS011 sensor (Replace with the actual hostname or IP address of your device, e.g. the Raspberry Pi).
AQSense builds upon ideas and code from other projects. Special thanks to the py-sds011 repository by Ivan for providing the SDS011 sensor interface.