An air quality monitoring service with a Raspberry Pi and a SDS011 sensor.
Find a file
2023-11-29 04:30:51 +03:00
nix add missing port variable to systemd service 2023-11-29 04:30:51 +03:00
src handle serial port unavailable 2023-11-29 03:36:33 +03:00
.envrc direnv 2023-11-29 02:01:54 +03:00
.gitignore ignore nixos test history 2023-11-29 02:17:09 +03:00
flake.lock use flake-parts 2023-11-29 00:26:20 +03:00
flake.nix init flake checks 2023-11-29 02:02:15 +03:00
README.md rename settings.device to settings.serialPort 2023-11-29 03:20:30 +03:00

Raspberry Pi Air Quality Monitor

A simple air quality monitoring service for the Raspberry Pi.

Installation

There are multiple ways to install this program. The main highlight of this fork is Nix & NixOS support, which would be the recommended way. If you depend on Docker for running this program, refer to the original repository.

With Nix

If you are on non-NixOS, but still have Nix installed on your system; you can install the package with

nix profile install github:notashelf/air-quality-monitor

After which you can use the installed package inside screen or with a Systemd service.

On NixOS

This flake provides a NixOS module for automatically configuring the systemd service as well as the redis database for you. A sample configuration would be as follows:

# flake.nix
{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    pi-air-monitor.url = "github:notashelf/air-quality-monitor";
  };

  outputs = { self, nixpkgs, ... } @ inputs:  {
    nixosConfigurations."<yourHostname>" = nixpkgs.lib.nixosSystem {
      # ...
      services.pi-air-quality-monitor = {
        enable = true;
        openFirewall = true; # if you want your service to only serve locally, disable this - defaults to true

        settings = {
          port = 8081; # serve web application on port 8081
          user = "pi-aqm";
          group = "pi-aqm";
          serialPort = "/dev/ttyUSB0"; # this is the serial port that corresponds to your sensor device

          redis.createLocally = true;
        };
      };
      # ...
    };
  };
}

The above configuration will set up a systemd service and configure necessary environment variables for you without any additional input. Plug in your sensor, and observe.

For a more hands-on approach, you may also choose to add pi-air-monitor package exposed by this flake to your systemPackages and use it manually, or write your own systemd service.

Example Data

Some example data you can get from the sensor includes the following:

{
  "device_id": 13358,
  "pm10": 10.8,
  "pm2.5": 4.8,
  "timestamp": "2021-06-16 22:12:13.887717"
}

The sensor reads two particulate matter (PM) values.

PM10 is a measure of particles less than 10 micrometers, whereas PM 2.5 is a measurement of finer particles, less than 2.5 micrometers.

Different particles are from different sources, and can be hazardous to different parts of the respiratory system.

Useful references