A simple project to read temperature from a sensor and store it in a postgres database. The data is then displayed in a grafana dashboard.
- ESP8266
- DHT22 Sensor
- Postgres
- Grafana
- Install the required libraries:
$ arduino-cli lib install "DHT sensor library"
$ arduino-cli lib install "Adafruit Unified Sensor"
- Create a database in postgres:
$ psql
$ CREATE DATABASE temp_sensor;
$ \c temp_sensor
$ CREATE TABLE temp_data (id SERIAL PRIMARY KEY, temperature FLOAT, humidity FLOAT, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
-
Update the
config.hfile with your wifi and database credentials. -
Upload the code to the ESP8266.
-
Create a new datasource in Grafana with the following settings:
Name: temp_sensor
Type: Postgres
Host: <host>
Database: temp
User: <user>
Password: <password>
- Create a new dashboard in Grafana with a new graph panel. Set the datasource to the one created in the previous step and the query to:
SELECT
$__time(created_at),
temperature
FROM temp_data
- Enjoy your new dashboard!
- DHT11 Sensor:
- VCC -> 3.3V
- GND -> GND
- DATA -> GPIO5

