A few of us Many have been playing around with hardware here over the past year or two. Being a purely software orientated person myself I found hardware and specifically electronics to be of a different world.
When the Arduino and Raspberry Pi came out however, it felt a lot more accessible and I could use my skills in software to power something special.
Our office comes with an archaic door opening system that is also somewhat broken. Unfortunately we aren't allowed to change it due to external cable routing and our building being a listed building. So we did what any reasonable developer would do: we hacked it with a Raspberry Pi!
Callum put together an awesome circuit board complete with zombie finger, 12V power supply and a cheap USB WiFi dongle from Amazon and then we just needed some software!
We needed two components, a small program running on the Raspberry Pi and some sort of app or tool to open the door from your laptop or even iPhone.
For the Raspberry Pi server we decided to write some Python using Tornado and instead of using an HTTP like API - HTTP and APIs built on it using REST etc are in my opinion often used too often when plain old sockets will do the job! - we decided to negotiate a socket using WebSockets and then communicate messages as small as possible over that socket so that the latency was negligible.
Why use WebSockets instead of just creating a pure socket? Well WebSockets takes cares of quite a few things I'd rather not have to worry about about like connection negotiation and framing. However it doesn't currently support a "heartbeat", a way to detect if a client has disconnected or the server is unavailable, so we've had to roll our own which we can see an example of below.
The full code is available at https://github.com/madebymany/bzzzt
The server is essentially quite simple and is responsible for the state of the door. Events are broadcast to all other clients, so for example when a client opens the door the other clients are notified who has opened the door.
To open the door itself I built an OS X taskbar item, the code of which is at https://github.com/madebymany/bzzzttray
I've had a few thoughts of what else I could extend it with:
- An iPhone app that uses iBeacons to detect when you're in the office and use the local network to open the door
- Add a camera to the door and send a picture of whose at the door back to the clients
Security wise (I knew you were wondering) the server is only accessible on the local network, which is of course encrypted and protected with a key. You also need the software; it has no other client. But I'm sure there could be extra layers.
Any questions? Feel free to contact me on twitter @alexrbarlow!
This is the first of a series of blogs about using Swift, Apple's new programming language that was annouced at WWDC 2014. They are not in any particular ...
Innovation is hard. Doing things that haven’t been done before, by collaborating with people you’ve never worked with, to navigate obstacles that no one c...
Last week we hosted another of our Small Talks events - this time focusing on 3 different perspectives around disruptive making. During the course of the ...