Transportation Schedule on RPi

Published on July 17, 2017

I hate missing my train or arriving at the station to find out that my train is being delayed. This happens often, because German public transports are so unpredictable ! Since I take the train every day for work, it is also a pain to check online every time I leave. I found a solution to this problem, using a Raspberry Pi.

The Solution

A Raspberry Pi computer shows in my corridor the departure times for the next trains or public transports (bus, etc.) for a set of chosen lines. Let me first show you how the solution looks like !

Ok Rpi, show me the next trains

The display can show information about the next trains for various destinations. So this can be useful not only for me, but also for my girlfriend or our flatmate. By the way, this video shows only the first prototype, the software was quite improved afterwards.

Hardware Setup

If you take a Raspberry PI 3 you won’t need the wifi dongle :). The touchscreen constructor provides a pre-configured Raspbian image, to download on its website, so it works out-of-the-box !

Then I bought some on/off hook strips from Tesa to put it in my corridor ! Hiding a part of the cable behind the mirror, it looks like this:


Software Setup

Getting an official Deutsch Bahn API key is impossible if you are not a business company. So I used schiene, a tiny Python library for interacting with, developed by Kevin Kennell. Basically it crawls the mobile website to retrieve the next time table. It is like an unofficial API. I wrote a small script that wraps around it and handles the presentation of the results (including incidents and delay) in the standard output with a periodic refresh of the results. It is available on my GitHub here.

This works for any connection in Germany. The script should be started with a few arguments, to specify the start and end stations of your trip(s). I’ve created a small bash script to start the program in the terminal of my Raspberry Pi with my desired connections:

cd ~/github/deutsche-bahn-time-display/
sudo python "Stuttgart Hbf" "Karlsruhe HbF" "==KA==>" True

To make it executable, don’t forget to do:

pi@rasp:~/$ sudo chmod 774

The script lives in my home folder. Then, I’ve put a script launcher.desktop with the following content on the Desktop:

[Desktop Entry]
Comment=Starts Python dbtime program

So when I double-click launcher.desktop on the touchscreen, it will starts the program directly in a new terminal. It will display the next trains from Stuttgart to Karlsruhe with the little prefix ==KA==>, considering only direct connections (True). It looks like this:

==KA==> 23,36,82,143,165
IC  | 11:06 | 0:57 +0
RE  | 11:19 | 1:20 +0
IC  | 12:05 | 0:44 +0
IC  | 13:06 | 0:53 
ICE | 13:28 | 0:36 

If you add more trips, it will alternatively display each of them. The information is refreshed after a number of seconds (by default 45 seconds).

To make it look better on the touchscreen, I changed the police to DejaVu Sans Mono Book with size 17 and changed the default dimensions of the terminal. To do so, just add the following line in the file /usr/share/raspi-ui-overrides/applications/lxterminal.desktop

Exec=lxtermnal --geometry=37x15

At first I considered not having a GUI on the Touchscreen, and simply start the program in the console, but then I would not be able to shutdown the Raspberry Pi from the touchscreen anymore.

My friend Daniel is doing something similar, with a much fancier design, you can check it out here.

Have a good trip !