The blog of a dedicated radio amateur and electronics enthusiast

"Having fun on the air and in the workshop - communicating and creating"

27 March 2021

Using Node-RED with the Soil Moisture Meter

Node-RED is a programming tool for event-driven applications. 'Flows' to connect inputs to outputs, hardware and online services via 'nodes' are created in a browser based editor in a similar way to 'MIT App Inventor' which I use for my Android apps. I thought of an application for Node-RED with my Soil Moisture Meter ( post 16.03.2021 ).
The events I wanted to handle were to trigger an email to be sent when the soil moisture level was low, save the moisture measurements to a text file and also publish them to an MQTT* broker. The image below shows how I 'wired' nodes together in Node-RED to achieve that.
My Node-RED flow - from input (blue) to outputs (mauve & light green)
Starting at the top left of the flow, every hour the most recent data packet containing the moisture value is read from the webpage ( /Moisturevalue ) hosted by the moisture meter receiver. Only if the text 'dry' or 'partched' is found in the packet string is an email sent. I have preset the body of the email to read "The SpacerLabs Soil Moisture Meter ( Sensor 1 ) has notified a 'low moisture level' alert".
My moisture meter data published on the HiveMQ broker
All packets ( unfiltered ) are published under the topic 'SpacerLabs/Moisture1' to an online MQTT broker. I chose the free public broker 'HiveMQ'. My topic is 'open'; so anyone can connect to www/hivemq.com/demos/websocket-client and subscribe to the above topic to read my hourly data packets under the messages tab. But only when my Node-RED server and the moisture meter are running. I also publish the status, ( ONLINE, OFFLINE or DISCONNECTED ), of the moisture meter to the separate topic 'SpacerLabs/Status'.
More information on Node-RED can be found at nodered.org.
* MQTT Message Queuing Telemetry Transport https://mqtt.org      

No comments: