This project showcases a weather monitoring system using Raspberry Pi 2 with DHT11/DHT22 and AHT20/BMP280 sensors. The collected data is displayed in Grafana through InfluxDB for real-time weather visualization.
-
Sensor Data Collection:
- Reads data from DHT11/DHT22 and AHT20/BMP280 sensors using C programs and the wiringPi library.
- Supports indoor (garage) and outdoor data collection.
-
Line Protocol Integration:
- Outputs data in InfluxDB's line protocol format, making it compatible with Telegraf for seamless ingestion.
-
Time-Series Data Storage:
- Utilizes InfluxDB for storing time-series weather data.
-
Visualization with Grafana:
- Displays real-time weather dashboards using InfluxDB as a data source.
-
Hardware:
- Raspberry Pi with GPIO pins
- DHT11 or DHT22 sensor
- AHT20 or BMP280 sensor
-
Software:
- wiringPi C library
- Telegraf
- InfluxDB
- Grafana
Ensure that the wiringPi library is installed before compiling.
Run the following commands to compile the sensor scripts:
gcc aht20+bmp280.c -o aht20+bmp280 -l wiringPi
gcc dht11+22.c -o dht11+22 -l wiringPi
Set up Telegraf to collect sensor data and send it to InfluxDB. Below is an example configuration:
[[inputs.exec]]
commands = [
"/etc/telegraf/scripts/dht11+22 -dhtpin 15 -sensor dht22",
"/etc/telegraf/scripts/dht11+22 -dhtpin 3 -sensor dht22",
"/etc/telegraf/scripts/aht20+bmp280 -sensor bmp280"
]
timeout = "30s"
data_format = "influx"
Refer to the official documentation for setting up Telegraf and InfluxDB:
- In Grafana, go to Dashboards > New > Import Dashboard.
- Import the dashboard JSON file provided in the project directory.
- Connect Grafana to your InfluxDB instance as a data source.
flowchart TD;
A[Hardware sensors]-->B[C Programs **wiringPi**];
B-->C[Telegraf agent];
C-->D[InfluxDB time series database];
D-->E[Grafana dashboards];
- Sensors: DHT11/DHT22 and AHT20/BMP280 measure temperature, humidity, and pressure.
- C Programs: Fetch data from sensors and format it for Telegraf.
- Telegraf: Collects and sends data to InfluxDB.
- InfluxDB: Stores time-series weather data.
- Grafana: Visualizes the data on a customizable dashboard.
Here is an example of the data output in InfluxDB's line protocol format:
Weather,host=stork,pinnum=15,sensor_type_name=dht22 humidity=72.9,temperature=10.0
Weather,host=stork,pinnum=3,sensor_type_name=dht22 humidity=51.1,temperature=17.2
Weather,host=stork,sensor_type_name=bmp280 pressure=1009,temperature=18.4
Below is a screenshot of the Grafana dashboard showing the final visualization:
- Add support for additional sensors.
This project is licensed under the Apache License.
Contributions are welcome! Please feel free to submit pull requests or file issues for improvements.