A C-based environmental monitoring system for Raspberry Pi that reads data from Si7021 (temperature/humidity) and CCS811 (eCO2/TVOC) sensors, providing both a command-line interface and HTTP server for data access.
- Multi-sensor support: Reads from Si7021 (temperature & humidity) and CCS811 (eCO2 & TVOC) sensors
- HTTP API: Built-in web server providing sensor data in plain text format
- Command-line monitoring: Real-time sensor readings with customizable intervals
- Systemd integration: Can run as a system service
- Baseline management: CCS811 baseline calibration support
- Error handling: Robust sensor error detection and recovery
- Logging support: Optional CSV output for data logging
- Raspberry Pi (any model with I2C support)
- Si7021 temperature/humidity sensor
- CCS811 air quality sensor (eCO2/TVOC)
- I2C connections between sensors and Raspberry Pi
- wiringPi: GPIO and I2C library for Raspberry Pi
- GLib 2.40+: Core application framework
- libsoup 3.0+: HTTP server functionality
- autotools: Build system (autoconf, automake)
# Update package list
sudo apt-get update
# Install build tools and dependencies
sudo apt-get install -y build-essential autoconf automake pkg-config
sudo apt-get install -y libglib2.0-dev libsoup-3.0-dev
# Install wiringPi
sudo apt-get install -y wiringpi-
Clone or download the source code
-
Generate build configuration
autoreconf --install
-
Configure the build
./configure
Optional configuration flags:
./configure --with-service-user=pi --enable-warn-strict
-
Build the project
make
-
Install (optional)
sudo make install
Run the main sensor server:
./pisensorThe server will start on port 8080 and provide sensor data at:
http://localhost:8080/reading- Returns plain text with all sensor readings
Example output:
72.50 F, 45.20 %, eCO2: 400 ppm, TVOC: 0 ppb
If the CCS811 sensor is warming up, you'll see:
72.50 F, 45.20 %, eCO2: 400 ppm, TVOC: 0 ppb (warming up: 5 min)
If there's an error reading sensors:
Error: latest Si7021 reading unavailable
Build and run the CLI monitor:
make
./monitorOptions:
-i, --interval <seconds>: Set sampling interval (default: 5.0 seconds)-o, --output <file>: Log readings to CSV file-h, --help: Show help message
Examples:
# Basic monitoring
./monitor
# Custom interval and CSV logging
./monitor -i 10.0 -o sensor_data.csv
# Quick test with 2-second intervals
./monitor -i 2.0After installation, enable and start the systemd service:
sudo systemctl enable pisensor
sudo systemctl start pisensor
sudo systemctl status pisensorView logs:
sudo journalctl -u pisensor -fBy default, the service runs as the pi user. Change this during configuration:
./configure --with-service-user=youruserThe HTTP server binds to all interfaces (0.0.0.0) on port 8080. To change this, modify the source code and rebuild.
- I2C Address: 0x40
- Temperature Range: -40°C to 125°C
- Humidity Range: 0-100% RH
- Accuracy: ±0.4°C, ±3% RH
- I2C Address: 0x5A
- eCO2 Range: 400-8192 ppm
- TVOC Range: 0-1187 ppb
- Warm-up time: ~20 minutes for stable readings
Missing dependencies:
# Check for required packages
make check-depswiringPi not found:
# Install wiringPi
sudo apt-get install wiringpi
# OR build from source if neededI2C not enabled:
# Enable I2C interface
sudo raspi-config
# Navigate to: Interface Options → I2C → Enable
sudo rebootPermission denied:
# Add user to i2c group
sudo usermod -a -G i2c $USER
# Log out and back inSensor not detected:
# Check I2C devices
i2cdetect -y 1
# Should show 0x40 (Si7021) and 0x5A (CCS811)The CCS811 sensor requires a 20-minute warm-up period for accurate readings. The software includes automatic error recovery and baseline management.
pisensor/
├── main.c # HTTP server implementation
├── monitor.c # Command-line monitor
├── configure.ac # Autoconf configuration
├── Makefile.am # Automake build rules
└── pisensor.service.in # Systemd service template
The project uses GNU Autotools:
configure.ac: Defines build configuration and dependenciesMakefile.am: Specifies build targets and installation rules
This project is licensed under the MIT License. See the LICENSE file for details.