DLR time to station help

Hi. Im new here. Im also new to python.
I had an idea to try and make a peice of art that was a TFL poster with addressable LEDs for each station.

When a train is less than 25 seconds from a station it lights the LED in the correct colour for the line. It’s a thing of beauty and i have enjoyed creating it.

However… every line works, aprart from the DLR. If i say time to staion is less than 59 seconds, no LEDs light (pretty much, somtimes one comes on every 10 mins…). If i say 60 seconds, it works, but inevitably most are lit as most stations will have a train due on one platform or the other in 60 seconds.

Is there somthing about the arrivals api for the dlr that is different? It works for all tube lines and overground and trams.

Any ideas to help me finish my project better?

Many thanks for the imput for a newbie like me.

Welcome @bennyt

OK… I’m not quite sure what you’re asking for.

From a CSS colour point of view the DLR is #00afad

There is a feed for the whole of the the DLR which is https://api.tfl.gov.uk/line/dlr/arrivals

The output - which is always at GMT by the way (they end in Z) - has a slightly different way of working from the tube data.

For each train it shows up multiple times.

You can spot the arrivals by using the “naptanId”: “940GZZDLCGT” and “expectedArrival”: “2024-03-29T07:24:43Z”

You can use these to work out the arrivals time for the upcoming trains. You don’t need to keep calling because the expectedArrival times don’t change that much - the DLR is driven by computers not humans - so you can work out your own “timeToStation”: 762 values and flash them when they would be within your 25 seconds.

Of course the DLR many trains at the node stations (Poplar, Canary Wharf, Canning Town and Stratford) so you might, in peak, have lights that flash all the time).

Of course, the DLR info, like all TfL info is ARRIVALS and not departures but you can see the starting points in the above link.

So, basically consume the above API every minute and then work from there.

Dear @briantist
Thank you so much for your reply.
Let me try and be clearer in what I meant.

My python programme is calling each line one at a time. For the DLR it is getting data from: https://api.tfl.gov.uk/Line/dlr/Arrivals

The program then looks at the “timeToStation” data, displayed in seconds. If the timeToStation < 25 seconds, the relevant LED lights up.

If you call the dlr api and do a quick search for ’ “timeToStation”:30 ’ or 29, or 28… or 3 or 2 or 1 you will never* see a result.

*Very very rarely, like once every 10 mins, but the reality is DLR trains arrive and leave more frequently, I think the api data is not returning.

On all the other lines (including overground and trams), you will have maybe 5 results where timeToStation is less than 25s. But the dlr never* returns this.

My question was, why is this?
Is there somthing different about the DLR data?

Many thanks.

And a picture for anyone interested.

And the business end…

1 Like

The DLR data comes from a different source so it could well be different.

My guess would be it’s something to do with the refresh rate and resolution of the predictions.

Knowing ‘why’ isn’t going to help you in any case so you’re best bet is to look at Brian’s suggestion; that is, use the most recent value of expectedArrival and compare that to the current time. When the difference becomes less that 30s bingo.

The expectedArrival prediction can be assumed to be valid until the timeToLive has expired or a new prediction arrives.

Rather more complicated programming but it should work I think.

1 Like


Nice looking work!

As @netstruggler says, ignore the “timeToStation” and use it use “expectedArrival" with it’s miliseconds in there.

You should be able to sync your time on your server/machine using Network Time Protocol - Wikipedia

Our system has taken the seconds out at the moment

but you can see the live DLR lines in this staging version (press the orange “plus in a circle”)

Thank you both ( @netstruggler @briantist ) so much… I shall attempt that (and learn some more coding as I go).

Much appreciated.