Skip to content

1wErt3r/pisensor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PiSensor - Raspberry Pi Environmental Sensor Monitor

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.

Features

  • 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

Hardware Requirements

  • Raspberry Pi (any model with I2C support)
  • Si7021 temperature/humidity sensor
  • CCS811 air quality sensor (eCO2/TVOC)
  • I2C connections between sensors and Raspberry Pi

Software Dependencies

Required Libraries

  • 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)

Installing Dependencies (Raspberry Pi OS)

# 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

Building from Source

  1. Clone or download the source code

  2. Generate build configuration

    autoreconf --install
  3. Configure the build

    ./configure

    Optional configuration flags:

    ./configure --with-service-user=pi --enable-warn-strict
  4. Build the project

    make
  5. Install (optional)

    sudo make install

Usage

HTTP Server Mode

Run the main sensor server:

./pisensor

The 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

Command-Line Monitor

Build and run the CLI monitor:

make
./monitor

Options:

  • -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.0

Running as a Service

After installation, enable and start the systemd service:

sudo systemctl enable pisensor
sudo systemctl start pisensor
sudo systemctl status pisensor

View logs:

sudo journalctl -u pisensor -f

Configuration

Service User

By default, the service runs as the pi user. Change this during configuration:

./configure --with-service-user=youruser

Network Configuration

The HTTP server binds to all interfaces (0.0.0.0) on port 8080. To change this, modify the source code and rebuild.

Sensor Details

Si7021 (Temperature/Humidity)

  • I2C Address: 0x40
  • Temperature Range: -40°C to 125°C
  • Humidity Range: 0-100% RH
  • Accuracy: ±0.4°C, ±3% RH

CCS811 (Air Quality)

  • I2C Address: 0x5A
  • eCO2 Range: 400-8192 ppm
  • TVOC Range: 0-1187 ppb
  • Warm-up time: ~20 minutes for stable readings

Troubleshooting

Build Issues

Missing dependencies:

# Check for required packages
make check-deps

wiringPi not found:

# Install wiringPi
sudo apt-get install wiringpi
# OR build from source if needed

Runtime Issues

I2C not enabled:

# Enable I2C interface
sudo raspi-config
# Navigate to: Interface Options → I2C → Enable
sudo reboot

Permission denied:

# Add user to i2c group
sudo usermod -a -G i2c $USER
# Log out and back in

Sensor not detected:

# Check I2C devices
i2cdetect -y 1
# Should show 0x40 (Si7021) and 0x5A (CCS811)

CCS811 Issues

The CCS811 sensor requires a 20-minute warm-up period for accurate readings. The software includes automatic error recovery and baseline management.

Development

Project Structure

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

Build System

The project uses GNU Autotools:

  • configure.ac: Defines build configuration and dependencies
  • Makefile.am: Specifies build targets and installation rules

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

Raspberry Pi air quality readings with the CCS811 and the SI7021

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published