(Ken Struys' Blog)

web-developer, serious schemer

Just Let Me In: Hacking with the Twilio API

My apartment has a fairly standard phone system. You dial an extension, my cell is called and I can allow the caller to enter the building by dialing nine.

To let myself in I have a dongle that it's hooked into the system and to let you in. Unfortunately, when my girlfriend and I moved into the apartment, we were only given one dongle and were told we we're not able to get a second one.

For three months I've been using the system to call my own cellphone and letting myself in. The biggest problem with this solution is my android phone dies all the time and I've been left a couple times stuck outside.

I decided I needed a better system to just let me in my own building. Twilio provides the perfect service to solve the problem. Twilio is a web service API for building Voice and SMS based applications. When you signup, you get a San Francisco phone number for development and you can code simple XML documents to automate Dialing other numbers, Messaging, Playing audio, etc for basically pennies. Once you've coded you application you can pay around $1/month for a local number.

When I dial into my front door, audio is played asking whether you want to speak to myself (press one) or my girlfriend (press two). When you press either key, one of our two numbers are dialled and the system works as normal. Since I don't want to dial myself anymore, I also added a pin (some other combination of keys) that just opens the door by fooling the system into thinking I've dialed nine.

The Twilio code was really simple (it was about 20 lines of PHP). The only difficultly I had was getting the dialling 9 to work. Twilio does support dialling keys, but only after Dialing out to another number. I emailed the Twilio team and they said the easiest way to get it working was to use a program called audacity to record a 9 key tone. Playing this tone tricked the door system into thinking I had actually pressed the key. I was a little surprised to find out such a hacky solution would actually work, but then again a lot software solutions are hacks :P.

In the future I think I'll try to port my PHP solution over to a more Rackety approach. You could very easily use send/suspend provided by the web server to make the script even shorter/more clear.

Overall my experience with the Twilio API was fantastic, it's probably the easiest API I've ever had the pleasure of using and it's really impressive in it's simplicity.