SIP
Design thoughts about plugins - Printable Version

+- SIP (https://nosack.com/sipforum)
+-- Forum: SIP (Sustainable Irrigation Platform) (https://nosack.com/sipforum/forumdisplay.php?fid=1)
+--- Forum: Writing plugins (https://nosack.com/sipforum/forumdisplay.php?fid=8)
+--- Thread: Design thoughts about plugins (/showthread.php?tid=119)



Design thoughts about plugins - astrogerard - 2018 Jan 07

As you might know I want to make the mqtt plugin more reliable on whether or not the mqtt broker is available. The problem (if one may speak of a problem Smile  ) is that when the broker is not available the plugin never ever attempt to connect to it on a later moment.

I would like to change this and make it more robust. There are however different approaches possible to do this. The job as such is easy, just try to connect once every x seconds until the broker is reachable.  My design thoughts are on which this should be done in a separate thread or, and this is unfortunately to my knowledge not (yet) possible, via a kind of trigger/heartbeat call from the framework to the plugin so that inside the plugin this could be handled.

Question; Is there a way to periodically get a trigger/heartbeat from the SIP framework (e.g. from the timer_loop) to wake-up the plugin to do "some work"?  With "some work" I not only mean to start the mqtt connection but also other things like reading lots of sensors om which the plugin can decide to alter the irrigation schema.

Please let me know if there are any thought on this.

Thanks,
--Gerard


RE: Design thoughts about plugins - dan - 2018 Jan 07

There is a system in place for SIP to communicate with plugins. It is done with the Blinker module which is included with SIP:
https://pythonhosted.org/blinker/

The current blinker signals are listed (with usage examples) in signaling_examples.py in the plugins directory. It would be trivial to add a "heartbeat" signal from the timing loop.

Another option might be to install an MQTT broker on the Pi:
https://xperimentia.com/2015/08/20/installing-mosquitto-mqtt-broker-on-raspberry-pi-with-websockets/

Dan


RE: Design thoughts about plugins - astrogerard - 2018 Jan 08

Thanks Dan,

At the moment I have installed a broker on the Pi. But since it is broker number four in the house I want to reduce the number of brokers to only one well maintained and one for development and testing.

The blinker functionality I totally overlooked. I saw the word blinker and with the many hours a week I spend on Arduino I thought it was a blinking LED. Silly me. But it is definitely something I can and will use.

If someone is interested in the progress I can post updates.

--Gerard


RE: Design thoughts about plugins - dan - 2018 Jan 08

Yes. Please keep us up updated on your progress.

I have been using Arduinos to build sensor nodes for SIP. My favorite is the Micro which has 2 hardware serial ports.
Weather proof electrical junction boxes make really good inexpensive enclosures.

   


There are inexpensive rs-485 serial adapters that plug into a USB port on the Pi:
https://www.amazon.com/RS485-Converter-Adapter-Smart-Meter/dp/B07797T9HC/ref=sr_1_124?s=industrial&ie=UTF8&qid=1515431220&sr=1-124&keywords=rs-485+USB+adapter

It allows to connect many remote sensor nodes without even using any GPIO pins in the Pi.

Dan


RE: Design thoughts about plugins - astrogerard - 2018 Jan 08

Nice!
Indeed the micro is great although uploading a new sketch can be easily made impossible and I had to rescue several times the 32U4 via SPI. So I keep a spare Nano as an SPI programmer :-)

So far I've implemented the heartbeat functionality and have the mqtt plugin working independent of the broker being online or offline during the start of, and while running SIP.
However the changes also have some effect on the MQTT zone broadcaster and MQTT Scheduler plugins. This was of course expected and they need some attention.

To be continued....