A real-time bus display

A real-time bus display

The aim of this week's project is to show you a new application of our Yocto-MaxiDisplay. The application is the following: to display in real time the arrival of local public transport buses.

Actually, you may find useful to have at home a display indicating the arrival times of local buses, thus helping you to avoid waiting for too long at the bus stop.

The project

In Geneva, we have a public transport service which provides an application allowing users to consult at any time the arrival time of a bus at a given bus stop. The idea this week is to retrieve the bus schedules on the public transport server, and to display them on the screen. To do so, we have a Raspberry on which a Python script performs HTTP requests to the server and treats the data to then display them on the screen.

View of a bus stop Display provided by the public transport services
Views of the existing display system

Our system can display the schedule of a single bus line, in both directions, and display the arrival times of the next two buses.

Our display
Our display

The assembly

So that we can easily move this display, the screen is connected to a YoctoHub-Wireless-g which takes care of the wireless connection to the home network. We mounted the display in a YoctoBox-Display. We fixed the wifi hub behind the screen with Fix-2.5mm, thus making a very compact system.

Assembly view Assembly view
View of the complete system

You must however power the system through the micro USB socket of the hub.

In our particular assembly, we added a Yocto-Buzzer to beep when a bus is coming. In this post, we didn't implement this option, but it may become the topic of a further post.

The software

As briefly touched upon in the introduction, the Raspberry here is an intermediary between the public transport server and our screen. We developed a specific Python script for this application. The script takes care of HTTP requests to the server, of decoding the answer, and of displaying the result on the screen.

By searching the Internet page of our public transport services, we found the requests of the web page to the server, which returns all the data concerning a given bus as a JSON object. By copying the URL in our Python code and using the requests library, we can perform the same request as what the web page does. Below is an example showing the HTTP request:

url = 'http://www.tpg.ch/TempsReel-portlet/TRService?method=GetProchainsDepartsTriLigneSens&codeArret=MOLL&lignes=L&destinations=ATHENAZ'
reponse = requests.get(url)

When we have received from the server the answer in the form of a character string representing a JSON object, we must interpret this string into a Python object of type "JSON". Then we build the message to be displayed from these data. Below is a display example of the character string extracted from the Python JSON object.

layer0.drawText(1, 55, YDisplayLayer.ALIGN.TOP_LEFT, stringBuild)

Adapting this system to the public transport services of other cities is quite possible. You would only need to modify the requests to the public transport servers and display the results in the same way on the screen. Below is an example on how to extract the name of the final destination of the bus line from the JSON object.

stringBuild = str(mollaz1['prochainsDeparts']['prochainDepart'][0]['destination'])

Moreover, in most cases, public transport services provide APIs to programmers to ease access to their databases. You must first look at the site of the public transport services of interest to see if they already provide an API.

The code is available on our GitHub page, right here.

The working diagram of the system
The working diagram of the system

Add a comment No comment yet Back to blog

Yoctopuce, get your stuff connected.