I'm working from a coworking space in Toulouse, France called Tau. People working there are called "Taunauts" and we are about 15 people using it every week.
One problem we face was to open the main door of the building : it uses a wall mounted intercom with a button or RFID cards. Trouble is we don't have 15 rfid cards and we wanted to make something fun.
The idea was simple : be able to click on a link or tell a bot to open the door.
The intercom is just a switch : you press a button, it closes a circuit and send happy electrons (they are always happy) toward the electromagnet's relay to switch it open, releasing the door.
The idea is then simple : use a relay to do the same thing the button does when pressed.
- To command a relay from a computer you need some kind of controller and a cheap and nice one is the Arduino Board : http://www.arduino.cc & http://snootlab.com/lang-en/arduino/142-arduino-uno-rev3.html.
- To be able to trigger an action on of the Arduino pins from a network you need a network extension for the Arduino (called shields) : an ethernet shield : http://snootlab.com/arduino/163-ethernet-shield-r3.html.
- To simply handle a relay you can order a 2 or 4 Relays shield : http://seeedstudio.com/wiki/Relay_Shield_V1.0.
To have something really working with those you need :
- a 9V power supply (to power the arduino uno and then the relays)
- arduino raisers to be able to add the relay shield on top of the ethernet shield without causing short circuits
You then need a basic web server listening on a TCP port on the ethernet running on the Arduino. Based on an example available from Arduino website, @madflo own code I wrote one with what we need, it available on one of my github accounts : https://github.com/Arbousier/tau_door.
This gives you a simple url to go to and to trigger the relay. A simple port forwarding from your router, a little web app and voila you can open the door with a click.
This is not enough
This solves our problem, but it's not a plain simple for everyone. Authenticating via a web form, clicking a link, you need a phone for that, and it's not that easy. Everyone got a phone, not everyone got a web friendly phone.
Wait, everyone got a phone ?
So yes the next step was to jump to Twilio, read the FAQs and write a simple sinatra app :
- Twilio receives a call and send a request to the app passing some params like From (the calling number)
- The app check if the number is white listed, if it is, the door is opened and a message is played back to the caller; if it's not the door stays shut and the caller is asked if he wants to speak to a human.
This app is quite simple in fact and I was surprised to see how easy it is to handle calls with Twilio. It's a sinatra app, under MIT license, it uses Cloudant to store the phone numbers but obviously with some little tweaks any database could do. You can find the code on github : https://github.com/Arbousier/Door-Opener-Twilio.
The two apps work together nicely, through a private router. The Sinatra app is hosted on heroku using a 1 dyno setup. The thing is fast enough and you don't wait more than 5 sec in front of the door ...