A personal public transport departure display

Submitted by oliver on Wed, 04/05/2017 - 10:50
Tram 11 leaving in 2–3 minutes and S18 leaving in 6–7 minutes to Stadelhofen

Tram 11 leaving in 2–3 minutes and S18 leaving in 6–7 minutes to Stadelhofen. The other lines (with no pending departures) are buses 31 (to Schlieren), 33 (to Tiefenbrunnen) and 77 (to Im Walder).

Transport, the swiss public transport API, provides public timetable data for any station in Switzerland (mostly) in real time. In this project, I have used it to create a display that shows the next departures of trams and buses from our nearby stop – Zurich, Hegibachplatz – towards the city centre.

Square brackets in GET request don't work...

We get realtime departure information for our particular stop with a request to transport.opendata.ch/stationboard with the parameter id, the ID of our station. A second parameter, limit, determines how many result "rows" we will get. However, the JSON returned from the API still contains many details which we don't need for this application, such as platform, station coordinates, train capacity etc. Even though the API offers the fields parameter to limit the response data, we can't use it because it requires elements in square brackets, something the Arduino HTTP Client library doesn't support...

My workaround was to write a PHP script that parses the JSON response from transport.opendata.ch and reduces the data to the minimum required for our display. So the Arduino actually sends its requests to the script (on my webserver) which in turn sends requests to transport.opendata.ch.

The 5 x 5 Neopixels are connected to a single strip on an old CD tray. The display currently refreshes every 30 seconds.