header text

a blog of things that I (eventually) make work

Sunday 24 January 2016

Fun with the TfL API, Yahoo Weather and Processing

Recently I've been playing around with pulling data from the Transport for London API in Processing. There's a crazy amount of possibilities for what you can do with the data that TfL can serve up, but my idea is relatively simple.

I'm pulling live data on bus arrival times for the stop at the end of my street, as well as the current status of the Northern Line (my nearest tube line) and the current weather. The end idea is to have a small screen set up in my hall with a Processing sketch running on a Raspberry Pi that will constantly provide me with data about when my next bus to work is, if I would be better off taking the tube, and whether I should maybe take an umbrella.

By default, the TfL API returns data in JSON format. Before starting this project I'd never worked with JSON before, so there was a bit of a learning curve involved. Processing can natively import and manipulate JSON objects (since Processing is essentially Java), but some of its abilities are somewhat limited.

Because of this, my sketch takes the useful info from the JSON object (bus number, destination and arrival time) and turns it in to a Table, which Processing is much better at manipulating. This allows me to sort the data by arrival time, so I can display the next bus arrivals.

The result I currently have is something which mimics the electronic arrivals boards seen at some bus stops:

Compared to my version:

Check out that Helvetica.

At the bottom you can see the fruits of my efforts with the Yahoo Weather API. This is slightly easier to work with in Processing as it will directly serve XML to the sketch.

Code snippets will follow when I've properly optimised it and added in error handling. This is important since this sketch is intended to run indefinitely.

1 comment:

  1. To top it off it has a welcome bonus worth $1000 over the primary three deposits and an Arabic language version too. This is the perfect free spins supply for the blockchain enthusiast. Now, you’ll need to examine your major inbox for a verification link from Spin Casino. If you don’t see an e 메리트카지노 mail from their web site within a couple of minutes, be sure to|make sure to|remember to} examine your “promotions” folder. The welcome bonus of Slots.lv comes with a wagering requirement of just 35x, which may be very aggressive. Royal Panda offers a very beneficiant welcome bonus for brand spanking new|for brand new} sign-ups.