At the end of my previous blog post, my Arduino board was sending real data from the ZMOD4510 sensor, via MQTT, to my Node-Red server, which then allowed me to view the results on a dashboard that shows all of the values. However, it's always a good thing to be able to go back and view trends over the course of a day, or maybe days or weeks or longer.
So the next step is to save the incoming data, and set up some graphs to show the values over the course of the day.
The first thing that was required to accomplish that goal was to save the data in InfluxDB to store all of the values, and thankfully that's almost automatic: just having a database is enough - the individual bits of information are stored automatically as they come in from Node-Red. Node-Red does the work of talking to the database. Since I already had InfluxDB set up with a "sensors" database for my hummingbird monitoring sensors, I didn't actually have to do anything in InfluxDB to get it ready.
In Node-Red I simply added a node that saves the data as it comes in. It has a built-in InfluxDB node for that. In the Node all I had to do was specify a new name for the set of measurements. I named it "air_quality_sensor". The Node then just sends the data from the flow straight to InfluxDB, which stores the data. Quite easy actually. No complex SQL or special coding required!
After running the test sketch to send some sample data to the server, I was able to verify that the data was being stored properly:
Once that was done, I went back into Node-Red to add the graphs to track how the information changes over time.
This was not too different from the graphs I had previously built for my hummingbird feeder monitoring system, so I was thankfully able to copy and modify my existing nodes without too much pain.
Since I didn't actually get real temperature and humidity data, I decided to remove those gauges, and also to not send those values from the sensor or store those values in the database. It would be easy to add that back in if I decided to add the extra sensor in the future.
After running the sensor for about a day in my office, this is what my dashboard now looks like, complete with the daily graphs. For my project, daily graphs should be enough to see if any fluctuations happen around the time we use the vehicles. (Hovering over a data point shows the details - I've done that for this screen capture to this to help identify the lines)
The charts show when I started data collection: in the dips at the start, and when I re-started data collection, by the middle dips. I re-started data collection because for the first while I had it plugged into my computer so I could look at the debug data on the Arduino Serial Monitor. I then moved it away from my computer and plugged it into a USB charger to run it independently.
This finishes the building and coding part of the project!
Now I need to run it for a few weeks in a few different places to see what kind of data it collects.
I've attached the node-red flow export to this blog post