A Nerds Way of Keeping Track of When the Next Bus Leaves

This post is just me nerding out with a open api, raspberry pi, blink(1) and some node.js code.


Outside my house, about 50 meters away there is a bus stop. In my struggle to not use the car so much we are trying to take the bus or bike to the kids school more. So on the morning I open the app for the commuting time tables and check when an appropriate bus will leave. Then I keep track of the watch to time that buse with the kids.

I wanted to do this more effortless.

The project

wall-pi-02When it’s 10 minutes left the blink(1) lights up in green, then it changes to yellow, then red to do some flashing last minute.

To do this I used:
* API-keys for SL’s realtime api (through www.trafiklab.se)
* Raspberry Pi 2
* blink(1)
* USB WiFi adapter for the Raspberry Pi
* Some node.js code (https://github.com/nippe/when-does-the-bus-leave)

Getting the Pi in shape

Install the Raspberry Pi OS, I used Raspian Jessie and followed the instructions.

Then I connected my Pi to a monitor and configured the wifi using the graphical interface (if it boots to prompt, write startx) and made sure the SSH server was up and running by default.

Made sure everything was up to date sudo apt-get update && sudo apt-get upgrade

Node.js – I tried to get nvm upp and running but did not succeed so I did a `sudo apt-get install nodejs’.

Get the code

Got the code from my repo (developed on a Mac), git clone git@github.com:nippe/when-does-the-bus-leave.git and then a npm install. (The node-blink npm package depends on node-HID which has different instructions for different node versions, so just be aware and do what’s right for your situation. Read more on the node-blink1 repo)

Run it

So a simple node busStatus.js does the trick. However that process dies when the ssh connections goes down. So the correct thing would probably be to set it up as a proper demon process and I was about to when I stumbled upon screen. A nice little tool to keep a virtual screen session going even if the client is not connected.

sudo apt-get update
sudo apt-get install screen

Start it:

> screen
> cd when-does-the-bus-leave
> node busStatus.js 

The leave the session by hitting ctrl + a + d.

When connecting to the raspberry pi again screen -r reconnects you to the screen-session. Nice little utility!

I’ll probably do updates of code and docs on github: https://github.com/nippe/when-does-the-bus-leave



E-postadressen publiceras inte. Obligatoriska fält är märkta *