Using Node-RED to display temperatures from MySQL database
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.
I will start with the timestamp inject node, this node signals the next node to run once every minute:
The next node is a function node to setup a SQL query to pass to a database node:
The database node contains the database connection and runs the SQL query passed to it:
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:
The debug node is used to make sure that the output of the database query is returning valid data:
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.
And lastly the second gauge node:
The following is a screen capture of the Node-RED UI page with the two gauges:
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
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!
Congratulations @mytechtrail! You received a personal badge!
Wait until the end of Power Up Day to find out the size of your Power-Bee.
May the Hive Power be with you!
You can view your badges on your board and compare yourself to others in the Ranking
Check out the last post from @hivebuzz: