I’ve spent a fair chunk of today playing with, and learning about, MQTT. Not the Adafruit IO implementation of MQTT (although I give them props for trying to simplify what could be a confusing protocol), but the original beast itself.
I was disappointed in being unable to keep the Adafruit IO script running for any longer than about 15 minutes and decided that I should grab the bull by the horns, and go directly to the source.
So, I’m not entirely sure how I ended up here, but after some toying with the paho-mqtt package, and bagging myself a free mosquitto broker instance courtesy of CloudMQTT, I’ve managed to write myself a couple of little scripts:
generate-rgb.py file is designed to fire off random values between
255 to the three colour (red, green, blue) channels I’m using. This is for testing purposes and will be replaced by other number generating sensors, just as soon as I figure them out.
The more interesting one is
hub.py, which subscribes to the RBG channels above, and uses the data passed to light up my UnicornHAT.
The top line of colour is the combination of the three lines below it. It’s very jumpy right now, with colour changes once per second, but once I have some better inputs (which are going to take the form of boxes with the aforementioned ambient sensors) it should be a far more gradual affair.
Anyway, the basic idea is my sisters and I will each have our own input boxes (Emily will be red, I’ll be green, and Jessica will be blue), which will feed data back into the hub box (at my parents’ house) which will use it to power an RGB lightbox.
Right now this is nothing more than a concept, than a solid idea, but the code above is the first step towards making something of it. The next step is working out what sensors I can use to get meaningful data from the feed boxes.