How to monitor a thermal sensor with a Raspberry Pi, Node-RED, InfluxDB and Grafana
Hi, today we will see how to monitor values from a thermal sensor using a Raspberry Pi, Node-RED, InfluxDB and Grafana.
- Raspberry Pi
- SD card
- Sensor DS18B20
The first part is to connect the sensor with the Raspberry Pi. We have to connect all cables referencing this diagram.
The Raspberry Pi is a series of small single-board computers developed in the United Kingdom by the Raspberry Pi Foundation to promote teaching of basic computer science in schools and in developing countries. It now is widely used even in research projects, such as for weather monitoring because of its low cost and portability.
Then we have to install RaspbianOS on the Raspberry Pi. We just have to activate two options in the Raspberry Pi settings.
- SSH : To access our Raspberry Pi with SSH.
- Wire : To enable the wire interface for our sensor.
The setup is ready. The next step is to check that our values are correctly captured. It’s time to use Node-RED.
Node-RED is a programming tool for wiring together hardware devices, APIs and online services in new and interesting ways.
Node-RED is installed by default on RaspbianOS. To start it use this command (default port is 1880)
Go to “https://raspberry-ip/1880” to use the graphic interface. We have to install two palettes.
The palette contains all of the nodes that are installed and available to use.
To display our values we will use two nodes.
We have to configure the sensor node :
- Sensor ID : ID of our sensor.
- Periodic : Check to capture a value periodically. (We have to check it)
- Period (secs) : Interval of captures in second. (For exemple every 5s)
Then we can link our two nodes and start a deploy. A measurement must be displayed every 5s.
Fine, now we want to send these measurements to a database.
InfluxDB open source time series database, purpose-built by InfluxData for monitoring metrics and events, provides real-time visibility into stacks, sensors, and systems. Use InfluxDB to capture, analyze, and store millions of points per second and much more.
First we have to install InfluxDB
sudo apt install influxdb
Then we can start the service (default port is 8086)
influx -precision rfc3339
We want to create a new database called “TEMPERATURES”
CREATE DATABASE TEMPERATURES
We can show all databases
In Node-RED we can add a node called “influxdb out” and configure it.
We have to add a new server :
- Host : raspberry_ip
- Port : 8086 (default port)
- Database : Name of our database (TEMPERATURES)
Then we have to put a name for our measurements in the measurement field. (for exemple : temp)
Finally we can link our nodes and restart a deploy.
To check that the values are correctly sent to the database go back to InfluxDB.
We can select our TEMPERATURES database.
Display the list of measures.
The measurement “temp” must be displayed.
To display the values of “temp”.
SELECT * FROM temp
Values are in our InfluxDB database. We just have to monitor them.
Grafana is a multi-platform open source analytics and interactive visualization web application. It provides charts, graphs, and alerts for the web when connected to supported data sources.
To install Grafana
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add - echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list sudo apt-get update sudo apt-get install -y grafana
Then start the service (default port is 3000)
sudo service grafana-server start
We have to add a data source :
- Name : Name of data source (for exemple : Temperatures)
- Type : Type of database (influxDB)
- URL : raspberry_ip:8086 (default port)
- Databases : Name of our database (TEMPERATURES)
After that we can create a dashboard and add a new panel.
We can select “Temperatures” for the Data Source. Put the measure “temp” in the section “FROM”. After that we can adjust the settings according to the desired result.
We saw how to set up a small monitoring system using a Raspberry Pi and different services.
Have a nice day !