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.
To do this I used:
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’.
Got the code from my repo (developed on a Mac),
git clone email@example.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)
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
> 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