OpenSprinkler Forums Hardware Questions OpenSprinkler Pi (OSPi) Using MQTT to log data Reply To: Using MQTT to log data

#34730

Ian
Participant

Update

I have been working on the Node Red application to process the MQTT messages that are sent in response to events in OSPI. These events are either users changing the configuration through data entry, or for stations starting and stopping.

To simplify things I added a new web call. If you enter in your browser http://ospi-host:port/gv?pw=password then you will get all of the variables in the gv module sent as a JSON encoded string. See gv.reference.txt in the OSPi directory for a description of these variables. I also added the ability to specify the QOS and Retain features of the MQTT messages to make testing easier.

This simplified the Node Red processing as it was no longer necessary to track where I was in requesting data from OSPi.

The resulting Node Red flow is shown in the attached jpeg. The section labelled “Initialisation and polling” requests the gv data from OSPi. This section builds the request, then processes it. The function fnProcessOSPIhttpresponse places all the gv variables into globals within the Node Red environment. These globals can be accessed from any Node Red function in a similar manner that modules in OSPi can access these variables by importing gv (Python talk there!). This section of the Node Red flow is triggered once an hour and this will form the basis of a system to inform me of failures in the OSPi system.

The remainder of the flows simply respond to MQTT messages. The “Respond to events” section processes messages such as login events, reboot events or failure of the OSPi system to respond to  http requests.

The section labelled “something started or stopped” responds to changes in the status of stations (ie sprinklers start or stop events). The start events are sent to my TV and email, and the stop events are similar. The duration is calculated and the stop event plus run time is also sent to Emoncms to log.

The section labelled “Someone changed something” responds to someone changing the OSPi configuration by entering changes in the web interface. I have simply processed tthe “change station names event”. These changes are mirrored in the Node Red global variables, and sent to email and XBMC for display on my TV.

I am sure that I don’t need all these notifications but this was proving the concept. With this system, you can be notified of most significant events in OSPi, and process them as you wish, either logging them into systems such as Emoncms or Openhab (or others). All the important variables OSPi uses are available in Node Red.

I will continue testing and will soon make the Node Red flows, and the update MQTT.html, MQTT.py and MQTT.html modules available.

The attached file is a screenshot of the Node Red flows involved.  I am surprised that this application is so straightforward. There is very little code involved in total.

I will continue testing but hope to have the updates to the OSPi modules I posted and the Node Red flows ready by the weekend together with updated documentation.

 

Regards

Ian

 

Attachments: