Buswarn: RasPi-based Transit Bus Tracking

Public transportation is like a magnifying glass that shows you civilization up close. ~ Chris Gethard

What is Buswarn?

During the COVID year, I moved off-campus. I didn’t realize at the time, but my only lifeline to my in-person classes, study rooms, and meals would be the Texas A&M Bus Transit System. Problems manifested themselves quickly. Buses ran at seemingly random intervals, and the website that displayed the schedule often had errors rendering on my mobile phone. What I needed was a simple device that displayed how many minutes I had to wait until the next bus arrived at my apartment. This device wouldn’t require me to have the foresight of googling the schedule and doing mental math to determine what time to leave my apartment in order to make the next bus. Armed with these design goals, I set to work with a Raspberry Pi and few 7-segment displays I had lying around.

Design

Here’s the birds-eye view of how the code works.

  1. Download the schedule website for the desired route from the internet every morning
  2. Process the timetable, and generate a list of times buses will arrive at my bus stop
  3. Compare the current time with next bus arrival time, and print the difference to a 7-segment display
  4. Gracefully handle website outages and power cycles to the pi.
  5. Turn the pi off at the end of the day and repeat

Implementation

Buswarn was written in Python, and I have bits of it written in C in case I want to implement it on a Arduino later down the road.

  • I wanted to use this as an opportunity to bone up on my HTML skills, and ended up using the BeautifulSoup library to parse the HTML table into a Python array.
  • The LCD is controlled by a custom Python library that can be used on using on future projects.
  • This is the first project I’ve developed entirely remotely through SSH on a headless machine.
image

prototype working fine!

Constraints and Challenges

This project’s main challenge was writing an extremely resilient program that could be left to run without breaking for extended periods of time. In practice, this meant handling a LOT of edge cases. For example, on football game days the website I pulled information from was essentially offline. Handling these edge cases individually offered me total control over the program’s stability. It’s been running for a few months now with no errors whatsoever! Here’s the Github Repo.

Future Changes

in order from least to most difficult to implement

  • The Nokia 5110 display suits this project much better than 7-segments. The 5110 is a 84x48 px lcd display with a backlight, which consumes less power and is much more visible in high-brightness environments. I’ve been having problems getting it to work on the Pi, so it’s currently on the drawing board.
  • A classic engineering problem: it works, but it’s not exactly pretty. even a 3d printed enclosure would go a long way to make it more presentable.
  • I’d love to eventually build these as low-power self-contained nodes in a LORA mesh. This would allow these stations to be installed at any bus station that has sunlight, no internet or power required. I’ll explore this possibility when I delve more into my self-contained LORA mesh project.

Final Words

This project taught me loads about building a program to an incredibly high reliability standard, and directly influenced my development mindset when tackling programming challenges at Stanley Black & Decker.