Show HN: Tracking my local bus with a RaspberryPi
purplehoisin.com
purplehoisin.com
There is an application called woob travel that shows timetables: https://woob.tech/applications/travel. It plugs back ends, each of which is a website. Once parsed, the data is programmatically available for anything.
Bonus point for OP: it is all written in python !
TFL do have some quite good APIs so you could use those rather than scraping the HTML.
https://tfl.gov.uk/info-for/open-data-users/api-documentatio...
I think you need to register but they seem happy to have amateurs and enthusiasts using them and they work quite well.
There’s a legal obligation in the UK for bus operators to supply live vehicle location positions and static timetable data to the Bus Open Data Service here : https://data.bus-data.dft.gov.uk
Probably HN killed the server.
BTW, where did you buy the Pi, or did you already have it at home?
With a Raspi, you not only have Raspian/RPiOS that fully supports all models back to the first one from 2011, but a decent number of really good alternatives like Fedora, Ubuntu and special appliance variants, e.g. for console emulation etc.
In contrast, my last experiments with some other SBCs consisted of downloading some ancient ISO files of questionable provenance from some shady .cn domains. It might have gotten better, but one should carefully investigate the software situation before buying a non-RPi SBC.
The last time I made this sort of comment one of the top replies was that Pis are notoriously picky about their power supplies. Be that as it may I've not run into any trouble with my Pis (Zero W + 3B). Hence I'm using my Pis while my C1 sits unused.
Or you can do this work in code, and put a countdown timer beneath each bus time (such that you walk out the door before time expires and you will make it).
Among this is the time of civil dawn, because at this time I don't want to be riding bike anymore since it's getting dark (and colder).
Next to it is a countdown timer with an offset of minus two hours, since I do ride my bike around 1 to 1.5 hours. So when I see that this timer is reaching 0, I know that I'm at my last opportunity to go for a bike ride that day. Once it reaches 0, it shows the countdown to the correct, non-offsetted time of civil dawn, but in another color, so that I know that I still have time to make a shorter ride.
I barely look at the time of dawn, since the countdown timer is so much more informative for me. It let's me know how many hours or minutes I still have to do things.
Do you mean civil dusk?
Some years ago there was a student union at the university where I was studying. We had a space dedicated to us in one of the buildings near the campus area.
Some of the members wrote a program to retrieve subway departures and show them on a screen in our space.
The authors of said program made it simple but friendly. It would show all upcoming departures from the subway station, with the number of minutes until departures, and color coding.
A countdown with green color coding meant that you were likely to make it since there was a lot time left.
Orange color meant that you’d have to hurry up and go to make it.
Red meant that you’d really have to run, and that even then you might not make it.
Very handy system, especially for late nights when you had to pay attention so that you’d get on the last subway for the night that would take you home.
I loved that student union. Easily the best part of studying at the university for me was being a member of that student union. I have so much in my life to thank for the experiences I made from being a member in that student union :D
https://web.archive.org/web/20221102223146/https://purplehoi...
That stupid bus clock will become not only possible, but trivial to build in just a few more weeks. It took a many meetings with company executives and government officials, freedom-of-information requests, hours of reverse engineering apps and subsequently arguing with lawyers... I accidentally stumbled onto two entirely separate multi-million-euro cases of clear corruption in public tenders, several CVSS >= 7 vulnerabilities, got both job offers and legal threats (once from the same company) and throughout the process learned more about multiple different CS fields than I did about even a single one in 3 years of university.
So if anyone else wants to build such a clock, but is disappointed that their local bus company doesn't have an API, don't be discouraged. There is always a way. It might cost you a year's worth of free time and most of your sanity, but you will end up with some shiny LEDs on that wall that still won't prevent you from missing the bus and a bunch of extremely niche knowledge. 10/10 would recommend
As a public transit user, I too have written a dashboard for my transit system on top of the smashing dashboard. It runs on a raspberry pi hooked up to a TV in my front room.
As others below have complained about arrival estimations being unreliable (or these days where we are low on operators and have a bunch of ghosts buses!), I found having a map with real time location gives me a better idea when I should leave:
https://blog.line72.net/2019/08/02/announcing-realtime-bus-t...
* the current temperature
* the high or low over the next 12 hours
* graphical forecast of the 12 hours (including chance of precipitation)
which is all the info I need to know to dress for wherever I'm taking the bus to. You can get all this info (including graphics!) from weather.gov DWML, e.g. https://forecast.weather.gov/MapClick.php?lat=40.7143&lon=-7...
I’ve fantasized for years about engineering a network of self contained + solar powered microcontroller / camera units that I could place on top of bus stops to track them myself.
Then again, by the time I get around to it the official arrival times will likely have become more reliable.
Any rate, great write up- thanks for sharing!
A lot of transportation services have tracking now.
For example, here in Prague, trams always arrives on time schedule or few minutes after that. (you can wait 2minutes lol)
Also all of our public transport has publicly accessible GPS tracking. Buses are more off of the time schedule, but you can check the GPS and compute the live time.
And subway doesn't make sense to track, since it arrives every few minutes at any station.
I don’t think this is very typical, but I have even had a bus driver stop mid route, say “this is as far as I’m going today”, kick everybody off, and drive away
You would have to replace the batteries fairly regularly and I have a feeling that without funding anything I cowboy rig would be super flaky.
2007 means that the network would probably have been an issue as well. Though, I’m less worried about that these days.
There are two types of RFID [active|passive] active required a battery which was rather small but the pings were so low power that the battery lasts a really long time.
We pivoted and built a tracking system for the cannabis industry - but cannabis growers didnt want to pay for anything they werent legally mandated to do so - we built a system called GreenScale which could track all employees in your growfields, bins etc... but again we are a bunch of engineers (my partner designs and builds the crazy sensors for TDK currently but designed the sensors for Google's RF hand sensors)
However, currently, we have a medical tracking system we have built for elderly care which integrates with Alexa and will tell you where your elderly care person is, if they accessed the restroom, if they fell... etc - but its based on a custom Ras PI basically and it uses RF as opposed to video etc with highly sensitive pressure sensors and other metrics to determine human action in a room....
When I was Director of OPs for Cognitive networks we buil spying bullshit on every single Vizio (and a couple other brands) TVs and could get a screenshot from any single TV connected to the internet...
We were always 5 years too early with our designs... and then all sorts of companies got founded upon things we were already doing 5 years prior... but people didnt undersrtand wtf we were trying to do and we are nerdy engineers and not salesmen so had a shitty time trying to get people to see our visions...
One of my partners now in eng manager at netflix instead.
Oh and if your public transit service has GTFS then just install home assistant and get maps and arrival times.
When Transit captures this information from their own users, it's much more trustable— basically all they'd have to watch for is someone maliciously poisoning the data by telling the app they're on a bus when they're really in a car, but that would be a lot of effort to go to just to be a jerk and end up shadowbanned.
However, I played around with one provider (Availtec's) estimations for Birmingham, AL's bus system.
This looked at the GPS position of the vehicle to see when they actually arrived at a stop and back compared it to the running estimation time. As we can see, it isn't great.
https://blog.line72.net/2019/08/06/validating-availtecs-bus-...
Of course sudden traffic, letting an elderly passenger get etc will mean that the countdown won't be the same to the second. But that's going to be the same if you used roadside cameras too.
Generally it should be seen as more of an estimate based on how long the last bus took to arrive from the same point rather than an exact prediction but it's usually useably accurate in my experience.
https://tfl.gov.uk/bus/route/254/
I was at a TfL hackathon once, at QMW along this route, but that is irrelevant.
Strangely TfL seemed to be beholden to Ordnance Survey for some copyright issue, it couldn't have been for the Natrional Grid reference could it?
Converting between lat/long to OSgrid was a bit tricky when you have to take the curvature of the Earth into account to get that last bit of accuracy.
https://www.movable-type.co.uk/scripts/latlong-os-gridref.ht...
PS For some reason I almost wrote Couverture of the Earth, just trying to reduce chocolate intake.
Take a look at Home Assistant, which runs nicely on the same hardware. You get a reasonably capable platform that knows when you're home and can be told a schedule, so you can then limit the checks to times when you'll actually need to know.
Either your usage fits into one of the zillions integrations (especially via HACS), or you can easily build something alongside with pyscript.
The state machine in HA is excellent, I use it for unrelated projects instead of a bus or something like that.
The UI is good and is getting better. I wrote years ago my own dashboard (that uses data from HA, among others) but I am slowly getting used to the idea that I may simply replace it with a full-screen page from HA's UI (especially when I manage to have widgets written in Quasar/Vue running correctly)
Bus & Mag-Lev?
I think the biggest difference is that I wrote my version as a web app without any backend (it gets data from a REST API + a hardcoded schedule as a fallback), so that I could host it on GitHub pages and display it on a cheap Android tablet. I still use it every day and am glad that I made it :)
Transitland offers an API that's easier to use than parsing the agency's XML imho: https://www.transit.land/
None of this will still solve the issue of ghost busses, though. ;)
> then we stored a moving average of time between each pair of stops and that was about it.
Modest. It got a little more sophisticated once we brought code inhouse.
The best solution here would be to secretly implant a RPI zero with gps into every bus
Ha and then you can also create an API for others with that data :)
From the title, this was what I was actually expecting the article to be about. :-)
You don't have to. If the program knows that the bus is 20 minutes away, it could wait 10 minutes or so before doing a refresh (assuming the bus doesn't magically gain a lot of speed in the meantime).
It's a shame that the WMATA bus data here in DC is so bad. The APIs are fine, but the data is all over the place.
The TfL API is really pretty good - no need to scape pages.
The key line. RPi aren't any more available as like before, for your new projects.
And it truly is a sad time for rpi-based projects... it really plugs a gap between cheap microcontrollers and power-hungry servers/PCs,...
It was a lazy update every 5 seconds loop/webpage updates image url with time query. Not great but did it's job.
I don't even want smart electrical outlets.
- Step 1. Know nothing about computer technology, and think it's magic.
- Step 2. Begin to learn about computer technology, and think it's fascinating.
- Step 3. Learn a lot about computer technology, and lose your trust in most developers/engineers that aren't yourself, and avoid said technology.
[0] https://www.windytan.com/2013/11/decoding-radio-controlled-b...
Or you can try to monitor https://rpilocator.com more than the scalpers do, and you might be able to get one for $100 instead.
[1] https://www.ebay.com/sch/i.html?_from=R40&_trksid=p2380057.m...