This combines the BSEC library from Bosch and bme68x-rust to read and process data from the BME688 sensor, and send it to a graphite server. The project runs on a Raspberry Pi 4B with a armv7l 32-bit OS, with the sensor on a Adafruit breakout board connected with I2C.
- Raspberry Pi 4B
- Adafruit BME688
- STEMMA QT / Qwiic JST SH 4-pin Cable with Premium Female Sockets
-
Bosch BSEC Library
2.2.0Download from the Bosch website.
Located in the dowloaded zip archive,
algo/normal_version/bin/RaspberryPi/PiThree_ArmV6/, copy the filesbsec_datatypes.h,bsec_interface.h,libalgobsec.a
into the project folder
lib/.
The Graphite server location is configured via environment variables. You can also create file .env in the project root, and input the graphite server location:
GRAPHITE_URL=<your-graphite-server>:2003Build the program in release mode:
cargo build --releaseThen the CLI program can be run in the background with:
nohup {project directory}/target/release/bme-sensors & disownYou can also setup a systemd service such that it runs on startup.
[Unit]
Description=BME Sensors service
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
Environment="RUST_LOG=warn"
User=<current-user>
WorkingDirectory=/<project directory>
ExecStart=/<project directory>/target/release/bme-sensors
[Install]
WantedBy=multi-user.targetUse VictoriaMetrics Agent to buffer data in case of network issues:
[Unit]
Description=Victoria Metrics Agent service
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
User=root
WorkingDirectory=/tmp
ExecStart=/usr/local/bin/vmagent -remoteWrite.url=http://<server-url>:8428/api/v1/write -graphiteListenAddr=:2003
[Install]
WantedBy=multi-user.target