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

#34355

Ian
Participant

Hi Dan, munnecke

I have hacked the email_adj plugin (as Dan suggested), and have it sending MQTT messages as follows

– to topic OSPI/system when the system starts (presumably when the ospi service is restarted

– to topic OSPI/start when a station turns on

– to topic OSPI/run when a station turns off

– to topic OSPI/rain when the rain sensor detects rain

There is still some more work to tidy it up, but essentially the plugin has a loop running every second. It detects changes in state by looking at variables in gv and comparing them against the previous values.  Almost any variable can be monitored providing it is accessible within my plugin (called surprisingly MQTT!). Doing the detection of events from within the one module by monitoring the content of the variables is going to be far easier than trying to modify the routines that make the changes to the variables. To do that you would need to scan code in all modules, and also rely on authors of as yet unwritten modules to add the necessary hooks in their plugins – very tricky.

There is a web page accessible from the plugins menu item that allows you to set parameters such as the hostname, and the port of the MQTT broker.  There are check boxes to select which of these messages you want. I will probably allow the user to input the topic for each of these events, but that is not in place yet.

It would be easy to check for changes in any of the variables in gv. So detecting changes to station names, programs, watering percentage etc are all possible.

This method has much less load on the OSPi. However if the OSPi goes down (or the service stops and doesn’t restart), then you would get no messages. I will look at a mechanism for detecting this, as I am concerned that my sprinklers may not go on if the OSPi doesn’t recover properly say from a power failure.

I am interested in hearing any comments as to ideas for  improvements/ things I have done wrong, suggestions for alternatives or anything relevant, etc etc.

One warning for people regarding the MQTT broker – don’t install it from the Raspbian repository -it will just hang when called from a Raspberry Pi. Go to the link I ooriginally provided in my initial post and install it from there.

Regards

Ian

 

 

 

I think that the MQTT Retain feature will automatically provide Node-red with the latest state, making life much simpler.

munnecke  – I have put station run times into Emoncms (running on another Pi). I will also be collecting water metering data and placing this in the Emoncms database. From there it is simple to use the facilities of Emoncms to calculate running totals, convert units, apply calculations (including combining data from other feeds) etc. It is however only suitable for analog data (including pulse counter data) ie it is not suitable for status information eg enabled/disabled, and so on.

Once I have got the plugin to a more advanced stage I will make it available for  testing and feedback.

In node-red I will take this data and direct it to different systems, such as Emoncms, XBMC, email etc. I will also develop flows that will effectively give node-red a set of globals that mirror the OSPI variables. That should allow people to come up with some inventive uses of the data.