Tuesday, July 22, 2008

Accessing Trimet Arrival Times with SMS

I discovered the Portland Trimet API about a month ago and was very inspired by the amount of real-time information available and the ease of accessing it through their web service. One feature of the service is that for a given stop id you can get the arrival times for the buses/trains for that stop. These are not the scheduled times but rather the real-time estimated arrival time based on the known GPS coordinates of the actual vehicles on their routes.
You can get to this data through IVR system by dialing 503-238-RIDE or on the web.

In the mean time, I have also been working with extending existing APIs with additional access such as SMS and XMPP (jabber). So it was natural to take on this trimet service as my first proof of concept.
For SMS access, you simple text "pdxt {stop_id}" to the short code DOTORG (368674)

so for example, for the stop 8334 (Pioneer Square South MAX Station Eastbound), you would text...

"pdxt 8334" to DOTORG (368674)

The result is shown below (with the same request through the web for comparison)



There is slight differences in the times since it is difficult to coordinate the SMS and web request precisely.

In my trials, response times for SMS were in the 5-10 second range which for me is acceptable.

I'll next be working on an XMPP (Jabber) wrapper around the service so you will then be able to access the service with an IM client (which many phones now have). XMPP will give the same mobility benefits of SMS but removes the 155 char limit for the returned text allowing for more information to be included in the returned message.

Once I have completed SMS and XMPP around this service, I plan to refactor the technique so it can be easily applied to other services. I will also document the steps I took to integrate with SMS and XMPP. Look for that on google code soon.