Simple C++ application to monitor IAQ (Indoor Air Quality) using a Raspberry Pi and a BME680/BME688 sensor accessed via the I2C bus.
The values are published to a given instance of HomeBridge. All configuration including the HomeBridge URL is now handled through a runtime configuration file (YAML format).
The application uses a YAML configuration file to manage all settings without requiring recompilation. On first run, a default config.yaml file will be created automatically.
Command Line Usage:
# Use default config.yaml
./air-quality-monitor
# Use custom configuration file
./air-quality-monitor --config /path/to/my-config.yaml
./air-quality-monitor -c /path/to/my-config.yaml
# Show help
./air-quality-monitor --helpConfiguration Keys:
| Key | Type | Default | Description |
|---|---|---|---|
homebridge_url |
string | "" |
Homebridge URL for publishing sensor data. Empty string disables Homebridge. |
homebridge_publish_interval_seconds |
int | 15 |
Interval in seconds for publishing data to Homebridge |
iaq_temp_offset |
float | 9.0 |
Temperature offset in Celsius to compensate for RPi heat |
iaq_i2c_bus_device |
string | "/dev/i2c-1" |
I2C bus device path for the BME68x sensor |
iaq_saved_state_dir |
string | "./saved_state" |
Directory to store BSEC algorithm state |
iaq_saved_state_file |
string | "bsec_state_file" |
Filename for BSEC state file |
Example Configuration:
# Enable Homebridge publishing
homebridge_url: "http://192.168.1.100:51828"
homebridge_publish_interval_seconds: 30
# Sensor settings
iaq_temp_offset: 5.5
iaq_i2c_bus_device: "/dev/i2c-1"
# State persistence
iaq_saved_state_dir: "./saved_state"
iaq_saved_state_file: "bsec_state_file"See example-config.yaml for a complete configuration template.
sudo apt update
sudo apt install build-essential cmake libssl-dev libspdlog-dev libi2c-dev
# Optional: Install yaml-cpp (if not installed, will be fetched automatically during build)
sudo apt install libyaml-cpp-devπ Complete BSEC Setup Guide β
Quick Setup:
- Download BSEC from Bosch Sensortec (search: "BSEC Software Library")
- Accept the license and extract the archive
- Set environment variable:
export BSEC_DIR=/path/to/extracted/BSEC - Validate installation:
./scripts/require_bsec.sh
sudo raspi-configSelect 3 Interface Options β I5 I2C β Yes to enable I2C.
Connect your BME680/BME688 sensor to the Raspberry Pi I2C bus:
- VCC β 3.3V
- GND β Ground
- SCL β GPIO 3 (Pin 5)
- SDA β GPIO 2 (Pin 3)
First, validate your BSEC installation:
./scripts/require_bsec.sh# Method 1: Using environment variable
export BSEC_DIR=/path/to/your/BSEC
mkdir build && cd build
cmake ..
make
# Method 2: Specifying BSEC_DIR directly to CMake
mkdir build && cd build
cmake -DBSEC_DIR=/path/to/your/BSEC ..
makeFor release builds with full optimization:
cmake -DCMAKE_BUILD_TYPE=Release ..
make -j$(nproc)cd build
./air-quality-monitorNote: It takes time for the IAQ accuracy to improve. The sensor needs to establish a baseline for gas resistance measurements.
The project uses BSEC_SAMPLE_RATE_LP (Low Power mode) by default. You can modify this in the source code if needed.
-
"BSEC library not found":
- Run
./scripts/require_bsec.shto diagnose BSEC installation - Ensure
BSEC_DIRpoints to correct directory - See BSEC Setup Guide
- Run
-
I2C permission errors:
sudo usermod -a -G i2c $USER # Log out and back in
-
Sensor not detected:
i2cdetect -y 1 # Should show device at address 0x77 (BME680) or 0x76
- IAQ accuracy is 0: This is normal initially. The sensor needs time to calibrate.
- Values seem incorrect: Ensure proper sensor mounting and ventilation.
cmake -DCMAKE_BUILD_TYPE=Debug ..
make
gdb ./air-quality-monitorThe build system automatically optimizes for your Raspberry Pi model:
- Pi 4/5 (ARM64): Uses Cortex-A72 optimizations
- Pi 3 (ARM32): Uses Cortex-A53 optimizations
- BSEC Library: Proprietary software from Bosch Sensortec. Users must download and accept Bosch's license terms.
- Project Code: [Your chosen license - specify here]
- BSEC-related issues: Contact Bosch Sensortec
- Integration/build issues: Open an issue in this repository
- Hardware issues: Check connections and I2C configuration
- BSEC: v2.x recommended
- Sensors: BME680, BME688
- Platform: Raspberry Pi 3/4/5
- OS: Raspberry Pi OS (Debian-based)
For production deployment, you can install the air quality monitor as a systemd service:
# Build the project first
mkdir -p build && cd build
cmake .. && make && cd ..
# Install as system service (requires sudo)
sudo ./scripts/install-service.sh# 1. Copy files to system location
sudo mkdir -p /opt/rpi-iaq-monitor
sudo cp build/air-quality-monitor /opt/rpi-iaq-monitor/
sudo cp example-config.yaml /opt/rpi-iaq-monitor/config.yaml
sudo chown -R pi:pi /opt/rpi-iaq-monitor
# 2. Install systemd service
sudo cp iaq-monitor.service /etc/systemd/system/
sudo systemctl daemon-reload
# 3. Configure and start
sudo nano /opt/rpi-iaq-monitor/config.yaml # Edit configuration
sudo systemctl enable iaq-monitor.service
sudo systemctl start iaq-monitor.service# Check status
sudo systemctl status iaq-monitor.service
# View logs
sudo journalctl -u iaq-monitor.service -f
# Restart after configuration changes
sudo systemctl restart iaq-monitor.service
# Stop service
sudo systemctl stop iaq-monitor.service
# Disable service
sudo systemctl disable iaq-monitor.serviceThe service runs with the configuration file at /opt/rpi-iaq-monitor/config.yaml. You can:
- Edit configuration:
sudo nano /opt/rpi-iaq-monitor/config.yaml - Restart service:
sudo systemctl restart iaq-monitor.service - Monitor logs:
sudo journalctl -u iaq-monitor.service -f
The service will automatically:
- Run as the
piuser - Restart on failure
- Log to systemd journal
- Use the specified configuration file
- Create required directories