Using Node-RED to display temperatures from MySQL database

avatar

Here I will show how I use Node-RED running on a Raspberry Pi computer to get some temperatures from a MySQL database running on another Linux computer and display them on a webpage. The following image is of the Node-RED flow I created and the following images will be of the nodes that make up the flow.
nodered-flow.png
I will start with the timestamp inject node, this node signals the next node to run once every minute:
nodered-inject0.png
The next node is a function node to setup a SQL query to pass to a database node:
nodered-function.png
The database node contains the database connection and runs the SQL query passed to it:
nodered-mysql0.png
The output of the database query then is passed to a gauge node as well as a debug node. The gauge node displays the temperature on the UI webpage:
nodered-gauge0.png
The debug node is used to make sure that the output of the database query is returning valid data:
nodered-debug.png
After watching some YouTube videos and reading some blog posts I discovered that I could directly inject a SQL query from the inject node for the second gauge part of the flow.
nodered-inject1.png
nodered-mysql1.png
And lastly the second gauge node:
nodered-gauge1.png

The following is a screen capture of the Node-RED UI page with the two gauges:
nodered-ui.png

Please feel free to ask any questions in the comments below. I am still learning how to document the things I am learning.

Posted with STEMGeeks



0
0
0.000
2 comments
avatar

Awesome stuff! Node-Red is "stateless" by default (meaning it forgets everything it has done once the flow is complete); using a database to store data is the best way to make it stateful. Love it!

0
0
0.000