Amazon don't sell their IoT Button in the UK. But that didn't stop Aran and I from making a pretty sweet hack over the weekend...
...and winning Best Use of AWS, at my first ever international hackathon! (I'm the scared-looking chap on the right, if you must know.)
Our hack was simple, or so it seemed: use the Dash button to make a low-cost, low-effort panic button to rival the overpriced and less-than-sexy alternatives.
Aran's already gone into some of the problems we faced around networking. But I think it's worth talking a little bit about AWS -- after all, that was what we won the prize for!
Here's the best explanation I can give: a hasty scribble of the system architecture in my HackCampus notebook (always reppin'), electronicized by draw.io.
So there's a local server, listening out for the Dash button sending ARP requests. Or, in our case, just plain UDP packets.
That server sends a POST to Amazon API Gateway whenever a button is registered (more on this later), or pressed.
That gateway is in turn backed by a couple of Lambda functions: one of which handles button-registration and the other of which handles button-pressing.
The button-pressing Lambda reads the GUID of the button that it's been sent, and retrieves some info about who we're gonna be waking up in the middle of the night from a Redis instance.
(Incidentally, this is where the button-registration Lambda comes in: instead of reading that info from the Redis instance, we're writing to it.)
When we've got the info we need -- maybe including a phone number to text, using Twilio's API -- we send a POST request to our Transformer server.
That Transformer server is running Express and Socket.io: it also happens to be the backend of the main site, notifi.click.
So whenever anyone connects to notifi.click, they'll start a websocket connection with our Transformer server!
That means any time a button relevant to them is pressed, we'll be sending them a "ping" via a websocket connection -- so on the frontend we can flash some warning lights or some other crazy stuff. We chose to keep it simple for the demo, and just update a big heading with the message text.
Maaaaaybe this is a complicated way of doing things. After all, it might have been easier to set up a simple polling system where any client connected to notifi.click would just ask (over and over again) whether there was a new message.
But where's the fun in that?