A couple of weeks ago I wanted to look into Amazon’s IoT service and conceived a slightly less-dry “hello world” project I could build as a vehicle for this research. You have probably seen the “Useless Box” concept before - its simply a box with a switch on it. When you flip the switch, a flap opens in the box and some kind of finger comes out and switches it back. I wanted to build that, but IoT-enable it, using the MQTT broker to listen for the state change in the switch, and notify the servo-listener to kick into action and put the world back to rights.
Right now, I’m building this on a Raspberry Pi. I’m using the same Jessie/Raspian image I used for the Smart Mirror and I was able to quickly get a proof of concept working with a little python code to rotate the servo in response to a MQTT message. Ideally I would have two physically seperate devices managing the switch and the servo respectively. But in the interest of both money and KISS (irony notwithstanding) I’m just using two processes: a switch script to respond to switch state changes and (debounce and) publish to the broker, and a servo script to listen for “on-ness” and rotate the servo to flip the switch back off and return the arm (and close the box lid.)
So far so good, but something wasn’t working when I tried to hook this up to AWS. My published messages appeared not to reach the broker. As AWS offers a more industrial-strength IoT service, I decided rather than troubleshoot the many potential points of failure (keys, certificates, policies etc) I would switch to Adafruit’s similar but much simpler offering.
That’s the first bit working. I can flip the switch and the resulting message shows up in the widget bound to that feed. The 2nd bit though where my subscriber receives the message and triggers the servo.. that’s not working. I’ve tried using the mosquitto_sub client and so far, although clearly adafruit.io is getting the message, it does not seem to be relaying it. I’m not sure if I’m confusing adafruit.io somehow by re-using the same feed id, or what. I guess I’ll fiddle with it.