sumnerboy12 / mqtt-gpio-monitor

Python script for sending/receiving commands to/from GPIO pins via MQTT messages
46 stars 23 forks source link

Add ability to run in non-blocking/background thread #8

Closed cosmocracy closed 8 years ago

cosmocracy commented 8 years ago

Currently the script is designed as a standalone application with a blocking loop for polling. To make for easier inclusion into other projects (e.g., IoT creations), consider a variation/adjustment that would allow the monitoring to instead occur in a background thread. Users of this script would then be able to include it in their apps--while still having some control of settings, looping/polling, etc. during startup.

cosmocracy commented 8 years ago

I would be happy to contribute some refactoring effort toward this issue if you would like.

bgewehr commented 8 years ago

I started the script with a & at the end after a blank. It perfectly runs in background now. Did you mean that or something different?

cosmocracy commented 8 years ago

Your usage suggestion meets most of the need. My suggestion was more that the script be something you could embed in another "larger" script. For example, perhaps you have an IoT app in which you'd like to include MQTT/GPIO bridging. Instead of using the script standalone (and doing daemon setup, etc.), this enhancement would make the script more like a library that could be included and activated from inside the larger codebase. (I might not be describing this well.)

Anyway, I think what I was getting at was shifting from the idea of a "utility script" toward something a little more like an include-able library (that wouldn't block the foreground thread in python).

Cheers, EK

bgewehr commented 8 years ago

Got it. I had very good results with multiple standalone scripts polling and pushing towards the MQTT broker. I started them as separate daemons. Worked very well. See my RPiMower set of scripts.

sumnerboy12 commented 8 years ago

Thanks guys, yeah this script is very much written as a standalone process. If you would like to library-ise it then feel free to fork or copy the bits you find useful, but I think I would prefer to keep it nice and simple in its current state. As @bgewehr mentioned, you can run multiple instances of it if required, I use supervisor to control all my daemon scripts which provides remote monitoring and control.

Cheers, Ben