Lab Notes: Node-Red Part II

Phillip Espinoza
Mission Data Journal
4 min readJan 12, 2017

After finding Node-Red particularly interesting, we continued our exploration of the platform by making our climate monitoring system a little more robust and letting Node-Red do more of the heavy lifting. Initially, Node-Red was a simple middle-man that collected data from our climate sensor and passed it along to our backend server for further processing. This time, we used Node-Red to communicate with a local Postgres database and provide the stored data in a more user-digestible form. For the climate data we are collecting, a typical use might be a dashboard that operations managers could use to understand the current state of a plant floor along with the near-term history so that they could take action if they see anything out of the ordinary.

What We Did

Our first objective was to get Node-Red communicating directly with a database, eliminating the dependency on a separate machine for data handling and enabling the system to gather and store data even without connection to the Internet. After setting up a Postgres server on our Raspberry Pi, we looked for a suitable node for our objective. Fortunately there are several existing nodes for Node-Red that enable communication with databases, including one for Postgres named node-red-contrib-postgres. The Postgres nodes execute received queries and return the results as output. To use it, we added function nodes to construct payloads containing SQL queries that get sent to the Postgres nodes, and then added further nodes to receive and process the results.

Our next objective was to add visualization to our system. As with databases, we were happy to find that there are several Node-Red nodes available for data visualization. We tried out Node-Red Freeboard and node-red-contrib-graphs before settling on node-red-contrib-ui due to simplicity and ease of use. The Contrib-UI nodes are able to take data directly from the DHT22 node, which made it easy to get started with some simple graphs.

Off to a good start, we continued on to our next goal of displaying data from our database, instead of directly from the sensor. We spent some time studying the nodes and eventually found that they take data in the format [{“key”:”Title1”, “values”:[[t1, y1], [t2, y2], … ]}, … ]. Because the chart input is an array containing the actual data points it is possible to display more than 1 set of data within the same chart by simply adding additional data sets in the correct format. A potential future application of this would be to display data points from several of our offices side-by-side, but for now we marked this as a sidenote and continued fine-tuning our dashboard.

Having gotten an understanding of how the Postgres and Contrib-UI nodes work, we were able to get back to working on our Node-Red flow. We collect data from our sensor once every minute and store it in our Postgres database. In separate flows, directly from the database, we retrieved the latest climate data points to allow users to quickly check current conditions, as well as data for the past hour, day, and week, allowing users to easily get an idea of what conditions have been like lately.

After processing the datasets in function nodes, we were able to feed the data to our various dashboard displays. We used gauges to display current data and graphs to display data for the past hour, day, and week. The following image shows the resulting gauges on a screen and it is worth noting that if you wanted to see the temperatures in fahrenheit it would be easy enough to add another node to the pipeline that did that conversion.

Challenges

The process of adding database and dashboard functionality to our Node-Red system was made pleasant thanks to the existing Postgres and Contrib-UI nodes that we used. However, we did find that the lack of detailed and centralized documentation again slowed down the development process. While the nodes we used are simple and easy to use when understood, developing an understanding of their functionality took some searching online, as well as trial-and-error using debug nodes to determine what inputs and outputs are supposed to be. In comparing our expanded system with the initial version, Node-Red shows it can handle more than just basic flows and it can handle them well, but its lack of documentation comes at the cost of time and effort.

Node-Red has had impressive results so far, and we are interested in continuing our exploration of this unique IoT platform. Up next, we will again expand our climate-monitoring system and see how Node-Red performs as a controller for a Slack bot and Alexa.

Teaser graphic with text that states “Transform your business with innovative digital products.”

About Mission Data

We’re designers, engineers, and strategists building innovative digital products that transform the way companies do business. Learn more: https://www.missiondata.com.

--

--