Temperature monitor using DHT22 + Grafana + InfluxDB (and a PI) – Part 3

In Part 1 and 2 we made it possible to read out the DHT22 sensor and save the data in an InfluxDB database. But this is not so useful if you can’t visualise the data. In this part we will install Grafana on the RPi and visualise the data in the browser.

Install Grafana

Unfortunatelly, the company behind Grafana doesn’t provide a repository for the RPi, but it does provide a debian package. The following commands wil download and install the package:

wget https://dl.grafana.com/oss/release/grafana-rpi_6.2.5_armhf.deb
sudo dpkg -i grafana-rpi_6.2.5_armhf.deb

Note 1: you can get the URL from the latest version on the web page of grafana: https://grafana.com/grafana/download?platform=arm

Note 2: I received the error: grafana-rpi depends on libfontconfig1; however: Package libfontconfig1 is not installed. This was solved with the command: apt --fix-broken install

Edit the file /etc/grafana/grafana.ini and remove the semicolon in front of protocol and http_addr. This will make the grafana interface accessible on all IP’s using a webbrowser

Next we enable and restart the service:

sudo systemctl enable grafana-server
sudo systemctl restart grafana-server

Open a webbrowser and surf to http://<ip-RPi>:3000 where the <ip-RPi> stands for the IP of you raspberry pi.

Configure Grafana

Once you have access to the web page, log in with the username and password: admin

After clicking on Log In for the first time, the option appears to change the password. This can be skipped by clicking skip

Once logged in, click on Add data source

Click on InfluxDB and change the following fields:

NameInfluxDB
URL http://localhost:8086
Database temperature
Useradmin
PasswordSame password used to configure the admin
account of InfluxDB

Click on Save & Test to add the Data Source and click on the + sign > Dashboard. Click on Add Query

Two queries will be created, one for the temperature and one for humanity. For query A, click on the edit icon (Toggle text edit mode) and enter the following query:

SELECT "temperature" FROM "TemperatureSensor" WHERE $timeFilter

Enter Temperature for ALIAS BY for query A. Click on Add Query, click on the edit icon
(Toggle text edit mode) for query B and enter the following query:

SELECT "humidity" FROM "TemperatureSensor" WHERE $timeFilter

Enter Humidity forALIAS BY for query B. On the left side click on General

Enter a panel title and (optional) a description. Finally on top, click the save icon, enter a dashboard name and click Save again.

Now the dashboard can be found under recent dashboards and you have a visual overview of the temperature/humidity.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.