In this tutorial we will look at how you retrieve and display data from a node-red database.
The tutorial uses data I collect for monitoring several of my websites.
The data consists of a
- timestamp
- site name
- page load speed
We have a web form that lets us select a website a time range and a page speed range and is shown below:
The results are displayed in a table.
The flow is shown below:
Besides the dashboard nodes there are two function nodes.
The store data node builds the database query based on the user selection and the convert time function converts the timestamp from a millisecond time to a human readable time before displaying it.
Notes about the store data node:
- Stores data in a context variable called data until you click submit
- The time is stored in milliseconds and the select time drop downs use milliseconds
- The results are limited to 100 results and ordered by timestamp in descending order. The query is shown below:
Data from the SQL node is passed to the convert time function which changes the time to a more user friendly form before sending it to the display.
Video Reading Data from a SQL Database
Related tutorials and Resources:
- Storing IOT Data in a SQLite Database-Node-RED
- Storing and Retrieving JSON Data In SQLite
- Working With Time- Node-Red Programming
- Working with JSON Data And JavaScript Objects in Node-Red