This is a simple project to read temperature, humidity, air pressure, gas resistance and co2 density from a BME680 sensor and a MH-Z19C sensor and send the data to InfluxDB. The data is then visualized during a Grafana dashboard.
- Raspberry Pi 4B
- BME680 sensor
- MH-Z19C sensor
Applications are run in Docker containers. The following software is required:
- Docker
- Docker compose
Applications are as follows:
- InfluxDB(container name is db)
- Grafana(grafana)
- Sensor data collector(sensor, coded in Rust)
These instructions are for a Raspberry Pi running Raspbian OS.
-
Clone the repository
git clone https://github.com/Penpen7/my-room-sensor
-
Change directory
cd my-room-sensor
-
Enable I2C interface and Serial interface on Raspberry Pi
sudo raspi-config
- Select
Interface Options
- Select
I2C
and enable it - Select
Interface Options
- Select
Serial
and enable it - Reboot the Raspberry Pi
- Check if the I2C and Serial interfaces are enabled
i2cdetect -y 1 ls -l /dev/ttyS0
- Select
-
Create containers by running the following command
docker-compose up
-
Access Grafana by opening a web browser and going to
http://localhost:3000
or http://raspberrypi.local/. -
Check if the data is being collected by watching the logs of the sensor data collector and Grafana.
-
If you want to stop the containers, run the following command
docker-compose down
-
If you want to create a systemd service to start the containers automatically when the Raspberry Pi is booted, run the following command
-
Create a systemd service file (my-room-sensor.service)
[Unit] Description=managed by docker-compose Requires=docker.service [Service] Type=simple WorkingDirectory=/home/naoki/docker-grafana ExecStart=/usr/bin/docker compose up --abort-on-container-exit ExecStop=/usr/bin/docker compose stop TimeoutStartSec=10min Restart=always RestartSec=10s User=naoki [Install] WantedBy=multi-user.target
-
Copy the systemd service file to the systemd directory
sudo cp my-room-sensor.service /etc/systemd/system/ sudo systemctl daemon-reload sudo systemctl enable my-room-sensor sudo systemctl start my-room-sensor
-
Even if you don't have the hardware, you can develop the sensor data collector on your local machine.
- Clone the repository
git clone https://github.com/Penpen7/my-room-sensor
- Change directory
cd my-room-sensor
- Create containers by running the following command
docker-compose -f compose_dev.yml up
- Access Grafana by opening a web browser and going to
http://localhost:3000
. - You can edit the source code of the sensor data collector in the
sensor
directory and the changes will be reflected in the container. - If you apply the changes to Raspberry Pi, you can build the source code by running the following command
- Build the source code
cd sensor ./build.sh
- Copy the binary(sensor/my-room-sensor) to the Raspberry Pi