Thursday, April 25, 2013

Node.js on a Raspberry Pi and Tropo.com


This evening I tried out some of the Phone/Voice/SMS features available from the site Tropo.com, and I'm definitely interested in going "Back to the Future" and composing a "User Interface" based on an Interactive Voice Response and the Plain Old Telephone Service.  The APIs at Tropo.com give you two options of building your app:
  • You can compose a script or JSON file that they'll "host" on their server. This means that any/all incoming requests are processed using these rules, which means that your "app" can't do anything dynamic.
  • You provide the URL for your own web server that communicates via JSON (using your favorite server-side programming language) and it returns dynamic responses for the current conversation. This is my "preferred" route -  the only catch is that it requires a dedicated and "constantly connected" Internet web server that can be reached by the Tropo.com servers.

I had the opportunity to see this kind of technology in action earlier this month at a MinneBar session, presented by Kevin Whinnery at twilio.com, where he made it look super easy to hook up code with the phone system.  Since I finally had a few hours of "free time", I had to try it out for myself.


Lately, I've been converting my web-app development from Java/Spring/Tomcat over to Node.js/Express.  The folks at Tropo.com have provided a Node.js library, and a few samples, which makes it easy to get up and running in no time.  In a matter of minutes, I had a demo app running, and I was able to dial into my app and "talk" with it.

The most difficult part was finding a way to host it with an "always on" Internet connection. My initial thought was a Node.js PaaS provider (Joyent, Heroku, etc), but all of the companies that I could find only offered "limited duration" samples that would eventually expire after a few months, or the servers would go to sleep after a period of inactivity, which causes latency (I hate waiting for computers).



Since my Tropo/Node app needs a simple (low-bandwidth) text/JSON interface, I figured I could host it from my own home Internet connection. The obvious catch is that I would need a "server" within my house to always be on, and connected to the Internet.  I have plenty of Linux boxes that are "always on", the problem is that they're all safely hidden behind a firewall - for good reason.




The "safest" box I have to throw at the Internet is a Raspberry Pi. The next catch is that Node.js doesn't provide an ARM based binary - you have to manually compile it. This brought back memories of the Linux servers I used in the late 90's, which required me to custom compile the kernel to support the SCSI controllers that I used. Anyway, there's no shortage of helpful blog posts that provide the simple steps needed to get Node.js running on the RasPi. Helpful note: you have plenty of time to go watch a movie while the compile/build runs.

For now, I just have the app report the current time, but I have some thoughts on providing "useful information" similar to the old Moviefone service (yeah, before cell phones were ubiquitous). We'll see if I can string together enough "free nights" to make that happen!