Skip to content

NJ Transit Mobile Scheduler

Not everyone has the funds or interest in browsing the somewhat slower internet connections you experience on on cell phones, so there are quite a few mobile-texting applications that have sprung up. Of course, this implies that you can send a quick SMS message from your phone, but in my opinion this action is much less tedious and distracting than a full browser open, navigate, select, view operation. Here are some of my favorites: directions on google, google 411, directions on sms hopstop or voice hopstop, weather and flight information on google, and flight alerts on flightalerts.com.

Background

I don't use it that frequently, and there is an 800 number to call, but I thought it would be an interesting exercise to create a mobile texting system that retrieves the nearest schedule for train travel on NJ Transit. Thanks to the users/admins at dreamhost.com for their useful procmail tutorials.

Usage

To use my mobile scheduler just send a text message or email message to this email address...

The basic syntax is to type the first few letters of the origin and destination of your travel and optionally provide the hour that you want to start your journey.  Incorporated is a little bit of logic like rolling over the departure time to the next day and determining am/pm for the hour. Below are a few examples of queries and what you might get as a reply.  While it's intended for a text messaging system (or with your favorite email client), a live web demo is available below.  Check out the NJ Transit rail map to get the names of some destinations and try it out. To minimize delay and server load, some things are cached here on my server, so it's possible that over time there will be some synchronization errors for station names.

Examples

Example 1: Example 2: Example 3:
"convent to long branch" "newark to middletown @ 6am" "newa1 to midd1 @ 6am"
demonstrates basic query operation and simple form of return including all transfers and the total price at current time of query demonstrate look-up on a partial hit; both terms 'newark' and 'middletown' have partial hits on multiple stations so the system asks for a resolution resolved look-up for a partial hit; the system first matches against the short form and then the full length name and notes the 6am morning train
Result 1:
[1] 5:31 P.M. @ CONVENT(On NEW YORK PENN STATION)
to 6:26 P.M. @ FRANK R LAUTENBERG SECAUCUS UPPER LEVEL
[2] 7:16 P.M. @ FRANK R LAUTENBERG SECAUCUS UPPER LEVEL(On LONG BRANCH)
to 8:38 P.M. @ LONG BRANCH
Fare:$12.00 ($5.50)

Result 2:
Please enter a shortcut or full name from below. Sorry, 'newark' is confusing.
[ ] NEWA1 or Newark Airport (Northeast Corridor)
[ ] NEWA2 or Newark Broad Street (Montclair-Boonton Line)
[ ] NEWA3 or Newark Penn Station (Northeast Corridor)
Sorry, 'middletown' is confusing.
[ ] MIDD2 or Middletown New York (Main and Bergen County Line)
[ ] MIDD1 or Middletown New Jersey (New Jersey Coast Line)

Result 3:
[1] 6:03 A.M. @ NEWARK AIRPORT RAILROAD STATION(On LONG BRANCH)
to 6:53 A.M. @ MIDDLETOWN NJ
Fare: $13.75 ($9.25)

Live Demo

Returned text message.

No query entered yet. Try something like "New York to Long Branch @ 5pm". You can look for other stations on the NJ Transit rail map.

Technical Mechanics

  • procmail - back end to receive email for a certain address and have a script run on receipt of that email
  • mysql - cache the names of different train stations and their abbreviations
    • cache the results after each query for the specific time, start, and end destinations

  • php - server-side processing of messages and database interaction

    • curl - fetch pages from external websites; first done during the caching process to retrieve all names then for queries by users
    • smtp, mime, JSON from pear - secure mail delivery in valid mime format to standard mail clients

Special Notes

  • Mail headers - some of the phone companies have very specific header requirements; specifically, there is a particular form the 'from' address (i.e. "Bob McClusky <bob@doesnotexist.com>")
  • Body encoding - you'll need to encode your message with 'base64' and not '7bit' or '8bit' to avoid some strange problems regarding unwanted newline characters
  • Max length - don't forget that older phones/systems may truncate your message at 160 characters!

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*
CAPTCHA Image
*