[HN Gopher] Show HN: Tracking my local bus with a RaspberryPi
       ___________________________________________________________________
        
       Show HN: Tracking my local bus with a RaspberryPi
        
       Author : fersarr
       Score  : 170 points
       Date   : 2022-11-04 10:44 UTC (12 hours ago)
        
 (HTM) web link (purplehoisin.com)
 (TXT) w3m dump (purplehoisin.com)
        
       | rakoo wrote:
       | This is _exactly_ what Web Out Of Browsers (https://woob.tech/)
       | aims to do: get information stored in websites, and offer a
       | programmatic way to use them.
       | 
       | 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 !
        
       | allenbina wrote:
       | I'm amazed at my own programming progress over the past 10 years.
       | I used to read these posts in awe of how people knew how to do
       | such fascinating things that seemed so magical to me. 5 years ago
       | I got myself a raspberry pi and an Arduino starter kit and just
       | started playing around with them. I learned python by practicing
       | on leetcode and other sites and I'm able to recognize a lot of
       | libraries and patterns in his code. It's a bit less magical but I
       | have a much more refined appreciation for posts like this.
        
         | sergiotapia wrote:
         | Next step is realizing that most code is a liability and you
         | will begin to loathe anything "smart". I'm at this step right
         | now. I'm curious if any graybeard out there can share what the
         | next step is.
         | 
         | I don't even want smart electrical outlets.
        
           | seanw444 wrote:
           | It's the natural progression I think.
           | 
           | - 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.
        
             | beoberha wrote:
             | This is extremely accurate in my experience (besides
             | trusting only myself, I don't even trust myself). In
             | general, the engineers I work with are much less "techie"
             | than a lot of people I know outside of work.
        
         | [deleted]
        
       | sowbug wrote:
       | Re future work "It bugs me that I'm fetching this information
       | every 30 seconds even though most of the time I won't use it":
       | 
       | 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.
       | 
       | https://www.home-assistant.io/
        
         | BrandoElFollito wrote:
         | I think that the platform is more than reasonably capable.
         | 
         | 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)
        
         | [deleted]
        
       | WaitWaitWha wrote:
       | For a minute, before following the link, I was thinking 'why not
       | just look up the schedule? And, did you leave a RasPi on a bus?!
       | Those things are like $200 now! Maybe you can get it back at the
       | bus depot...'
        
         | [deleted]
        
         | nashashmi wrote:
         | What do you mean 200$
        
           | bombolo wrote:
           | They are a bit hard to find at the moment.
        
           | michaelt wrote:
           | If you want a new raspberry pi 4 8GB today, you basically
           | have to buy from a scalper at a cost of around $200 [1]
           | 
           | 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=p238005
           | 7.m...
        
         | [deleted]
        
         | fersarr wrote:
         | :) We could hide it inside a bus and make a geolocation game!
        
         | goatcode wrote:
         | In some areas, it would be necessary to somehow install
         | trackers on your busses that you use. Depending on the
         | jurisdiction, I've had to deal with busses either being
         | possibly 10 minutes early, or missing their stop time by up to
         | half an hour.
        
           | geraldwhen wrote:
           | This is a good reason to stop using busses, not add tracking.
        
             | goatcode wrote:
             | That is what I myself ended up doing :)
        
       | ageitgey wrote:
       | I made a similar thing in London as well:
       | https://twitter.com/ageitgey/status/1383381051154726920
       | 
       | The TfL API is really pretty good - no need to scape pages.
        
       | sorenjan wrote:
       | While this is a nice project, it's basically just simple web
       | scraping. I was hoping for something a bit more interesting, like
       | decoding the radio signals for the bus stop displays[0] and using
       | that data. If it's available from an API it of course makes more
       | sense to use that though.
       | 
       | [0] https://www.windytan.com/2013/11/decoding-radio-
       | controlled-b...
        
         | unnouinceput wrote:
         | Or setup a RPi camera, with OpenCV and recognize your bus while
         | it's around the corner 2 streets before coming to the stop so
         | you know you'll have a full minute until it gets there. I mean
         | a 30 meters pole on top of your house isn't something that hard
         | to do. And the programming of that is so much more fun that
         | just the web scrapping. Plus is actually more accurate than a
         | web scrapping that can have de-synchronizations between that
         | and the real bus.
        
         | [deleted]
        
       | jaimehrubiks wrote:
       | If only the Chicago CTA api was close to reliable... It's well
       | known for the ghost buses and disappearing trains. However we
       | wouldn't probably need to call Apis, just refreshing their
       | website would work as it's similar to OP's (or Google maps or any
       | other using the apis).
       | 
       | The best solution here would be to secretly implant a RPI zero
       | with gps into every bus
        
         | fersarr wrote:
         | > 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 :)
        
         | seanw444 wrote:
         | Now _that_ would be cool. Although costly, if it were
         | discovered.
        
         | alex_suzuki wrote:
         | > The best solution here would be to secretly implant a RPI
         | zero with gps into every bus
         | 
         | From the title, this was what I was actually expecting the
         | article to be about. :-)
        
       | dssagar93 wrote:
       | I feel lucky that in India we have an app to track the live
       | location of all the buses. I almost use it daily and plan my day
       | accordingly.
        
         | [deleted]
        
       | KerrickStaley wrote:
       | I built something similar recently, linking it here in case
       | people want similar projects for inspiration:
       | https://www.kerrickstaley.com/2022/02/25/transit-panel
       | 
       | 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 :)
        
       | habibur wrote:
       | > Since I already had an unopened Raspberry Pi 3B that I ordered
       | in 2016 (6 years ago!!)
       | 
       | The key line. RPi aren't any more available as like before, for
       | your new projects.
        
         | ajsnigrutin wrote:
         | Yep.. I'd have used an esp8266 for this, and kept the rpi in
         | the box, for when I "really need it".
         | 
         | And it truly is a sad time for rpi-based projects... it really
         | plugs a gap between cheap microcontrollers and power-hungry
         | servers/PCs,...
        
           | Mumps wrote:
           | I wonder if a Pi Pico W would be sufficient to run this,
           | even? waaay cheaper (and available).
        
             | ajsnigrutin wrote:
             | I just took a quick glance at the specs, and sure...
             | running an lcd and parsing some text from the web seems
             | totally doable, and in contrast to RPi (3, 4...), you can
             | actually buy picos :)
        
       | will0 wrote:
       | Looks like it's been hugged to death. Archive.org link:
       | 
       | https://web.archive.org/web/20221102223146/https://purplehoi...
        
         | fersarr wrote:
         | Wow! I wasn't expecting this at all. Thanks for the cozy hug of
         | death :) Also, thanks for posting the archive link! I'll try to
         | make it more resilient for the future.
        
       | wirthjason wrote:
       | Now if someone can build something to track ghost trains. I'm
       | looking at you CTA!
        
       | parkersweb wrote:
       | If you're interested in this you might also be interested in a
       | project I'm currently involved with.
       | 
       | 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
        
         | fersarr wrote:
         | Oh that's great to know! There seems to be an experimental API
         | already, will have a look :) thanks!
        
       | scary-size wrote:
       | Awesome! Did something similar using GTFS data. Used an e-ink
       | display though: https://github.com/Scarysize/transit-pi
        
         | gala8y wrote:
         | E-ink is much better choice.
         | 
         | Bus & Mag-Lev?
        
           | scary-size wrote:
           | Bus and ferry in Hamburg
        
             | gala8y wrote:
             | Cool.
        
       | ranger_danger wrote:
       | Now if only this could be done for public school buses that never
       | show up at the same time. Younger kids are required to be dropped
       | off/picked up in the presence of an adult, but one is often left
       | out in the cold/snow/heat/whatever for far too long wondering if
       | the bus will ever arrive, or if they were already passed by.
        
       | reckless wrote:
       | I'd definitely recommend you use homeassistant as a front-end for
       | this. You can then update a 'sensor' using an mqtt message.
        
       | chandlerswift wrote:
       | I'd been exploring a similar project a few years ago, and ended
       | up making a map that showed the location of buses along the
       | routes I tended to take. I was pretty happy with it...except for
       | the fact that it was built for the town (Duluth, MN) I went to
       | school in, and I didn't get it finished until finals week of my
       | last semester, and I left town immediately after!
       | 
       | https://chandlerswift.com/projects/bus-tracker
        
         | bitxbitxbitcoin wrote:
         | That board deserves to be on display at City Hall or something.
         | Inspiring work and I lament with you that you weren't able to
         | use it more than a few days.
        
           | chandlerswift wrote:
           | Thanks! :) I definitely thought about seeing if I made a
           | polished version, if I'd be able to sell a copy to the local
           | transit authority, or something. But it made for a great
           | conversation piece, and was tons of fun to build, so it's
           | definitely a success as far as I'm concerned.
        
       | colanderman wrote:
       | I did a similar thing as a web page an eInk tablet. What doubled
       | the value for me though was adding a weather widget to the
       | corner. It shows me:
       | 
       | * 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...
        
       | gedy wrote:
       | I know buses rotate and really not practical, but I'd try putting
       | an Apple AirTag somewhere on the bus discretely and track that
       | way.
        
       | omh wrote:
       | I love the form factor of this and the ambient data.
       | 
       | 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.
        
         | fersarr wrote:
         | Thanks for the feedback on the form :) And yea, using an API
         | would be much better! I wasn't aware of it, thanks!
        
       | et-al wrote:
       | For anyone who's looking to build something similarly, you want
       | to search for your agency's GTFS Realtime feed:
       | https://gtfs.org/resources/gtfs-realtime/
       | 
       | 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.
       | ;)
        
       | throwoutway wrote:
       | Anyone know what that screen is? I don't see a link in the
       | article
        
         | fersarr wrote:
         | Oh Sorry! I should have added that. Here's a link to it
         | https://thepihut.com/products/hdmi-4-800x480-ips-touch-scree...
        
       | fersarr wrote:
       | Finally started using my Raspberry Pi! I built a bus clock to
       | know when to leave the house and never miss the bus again. Wrote
       | this little post to share the details and some pictures.
        
         | pmontra wrote:
         | "Error establishing a database connection"
         | 
         | Probably HN killed the server.
         | 
         | BTW, where did you buy the Pi, or did you already have it at
         | home?
        
           | noodlesUK wrote:
           | It's sad because I desperately want a raspberry pi or two for
           | some projects I've been kicking the can on, but I simply
           | can't get them for anywhere close to MSRP. The shortage
           | hurts.
        
             | Grimburger wrote:
             | Perhaps try an equivalent like odroid? You usually get far
             | more compute per $ anyway.
        
               | icelancer wrote:
               | We switched to Odroid XU-4s for this reason.
        
               | dual_dingo wrote:
               | I haven't closely monitored the situation for years now,
               | but it used to be the case that OS/software support for
               | anything than a Raspi was often spotty at best.
               | 
               | 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.
        
               | icelancer wrote:
               | This is getting significantly better and fast - largely
               | due to RPis being unavailable for 2 years and growing
               | (and won't get better anytime soon). Odroid's ecosystem
               | is quite a bit better these days. I highly recommend
               | getting an XU-4 from Ameridroid or HardKernel themselves
               | (my last order arrived within 10 days from South Korea to
               | the west coast with zero customers issues) for a fraction
               | of the RPi 4 MSRP cost (much less what it actually costs
               | now) and tinker.
        
               | fragmede wrote:
               | It depends on your level of expertise and how comfortable
               | you are straying from an online guide. It's just a small
               | matter of computer engineering, for different difficulty
               | values of "just".
        
             | JonathanBuchh wrote:
             | https://rpilocator.com is great for finding Pi's closer to
             | MSRP. You just have to waif for them to be in stock.
        
               | [deleted]
        
         | JoshMcguigan wrote:
         | Thanks for sharing! In the first screenshot of CLI output, it
         | seems to show three buses all being 1 minute out? Am I
         | misreading that?
        
           | fersarr wrote:
           | Yea I was surprised with that one too. It wasn't my local
           | station but I think that sometimes happens when it's a busy
           | station at a busy time so they have more than one bus. Or it
           | might be a bug.
        
             | handelaar wrote:
             | Not very surprising to me that they'd start bunching by
             | Bethnal Green tube having all just been slogging their way
             | through Mare Street in Hackney, honestly
        
       | ge96 wrote:
       | Ha I taped one (with camera) to my window to spot when the FedEx
       | truck was coming. (no vision just periodic images uploaded to
       | local website).
        
         | fersarr wrote:
         | Was this in order receive your personal deliveries?
        
           | ge96 wrote:
           | Yeah my apt complex sucks, doesn't accept deliveries and
           | FedEx doesn't have tracking like Amazon does. Usually I try
           | to change the delivery address to some hold location but
           | sometimes not possible.
           | 
           | It was a lazy update every 5 seconds loop/webpage updates
           | image url with time query. Not great but did it's job.
        
       | l72 wrote:
       | I love these types of projects. Being able to automate or make a
       | daily chore easier is so liberating.
       | 
       | 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...
        
       | quijoteuniv wrote:
       | For a moment i though he did a solution for the <<ghost buses>> .
       | I always used the bus app and it works fine untill, from time to
       | time, you turned 2/3 minutes before to the bus stop, timer goes
       | down, then says due.... And disappears!!! And no bus pass, trust
       | me, i question myself several times. The 254 is a common offender
       | of the "ghost buses" :)
        
         | selectodude wrote:
         | It's somewhat comforting in a bad way that this isn't an issue
         | isolated to my city. We even have the same name for them.
        
         | zeristor wrote:
         | 254?
         | 
         | 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.
        
           | quijoteuniv wrote:
           | Mmm... maybe it was the 271 now that i think of it. But it
           | happen with others too
        
         | [deleted]
        
       | jpribyl wrote:
       | The problem I've faced is that the official live update arrival
       | times are often wrong.
       | 
       | 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!
        
         | nsteel wrote:
         | In London the TfL API includes access to their live CCTV
         | traffic cameras. I think you now have to register but it should
         | still be there.
        
         | acomjean wrote:
         | It's a fun problem. We hire 4 trolleys for our open studio
         | event in Somerville. One of our volunteers bought some smart
         | phones, and we pulled a together a php and MySQL back end, some
         | google maps and Trolley Tracker. We can see them bunch up over
         | the course of a day.
         | 
         | A lot of transportation services have tracking now.
        
         | l72 wrote:
         | Arrival time estimates are really difficult. I much prefer
         | being able to see where the vehicle is on a map and make my own
         | decisions, based upon my own experiences.
         | 
         | 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-...
        
         | RektBoy wrote:
         | Why is the live data wrong? Why is it called live data, then?
         | HH
         | 
         | 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.
        
         | samstave wrote:
         | Ha! me and several engineers from Lockheed built just such a
         | thin in 2007 -- but we couldnt get funding for it (we built the
         | RFID tracking system for the military) but we were too early
         | for the market at the time and people werent educated about
         | tracking so we go rejected all over....(it was for fleet
         | operations - we built the tracking systems for all weapons
         | shipments and containers for the military at the time.
        
         | mikepurvis wrote:
         | The Transit App [1] crowdsources position data for vehicles.
         | It's a gamified thing that rewards you with points or whatever
         | for leaving the app running with your GPS on while in motion.
         | This lets them have up-to-the-second knowledge similar to how
         | Google Maps running on phones gives Google live traffic data
         | around the world.
         | 
         | [1]: https://transitapp.com/
        
           | j0yb0y wrote:
           | They also recently released a developer API [1]. The free
           | access looks okay for personal use, I haven't tried it yet.
           | 
           | Oh and if your public transit service has GTFS then just
           | install home assistant and get maps and arrival times.
           | 
           | [1]: https://transitapp.com/apis
        
             | mikepurvis wrote:
             | True, but I think part of the point is that the GTFS data
             | is subject to the technical competency of your local
             | transit agency, and that seems to vary widely-- sometimes
             | they lie about where vehicles are, or pretend that
             | schedule-inferred positions are GPS positions, or they're
             | missing vehicles, or the data is delayed, or whatever.
             | 
             | 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.
        
         | srmarm wrote:
         | In London? They're usually quite accurate - used to be tracked
         | by roadside beacons so had less resolution but now it's all GPS
         | I think.
         | 
         | 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.
        
           | fersarr wrote:
           | Yea so far they are mostly accurate but there have been one
           | or two occasiones with minor delays. I didn't know they used
           | to have roadside beacons :| How did those work?
        
       | beckingz wrote:
       | Oh this is cool.
       | 
       | 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.
        
       | teeray wrote:
       | Small UX idea: what you really care about is not when the next
       | bus arrives, it's "can you make it?" Of course, you can arrive at
       | the latter from the former, referencing the current time, and
       | roughly how long it takes to get to the bus stop (with reasonable
       | buffer time).
       | 
       | 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).
        
         | qwertox wrote:
         | I have a tablet mounted on the wall which displays different
         | kinds of stuff, like weather conditions and forecasts and so
         | on.
         | 
         | 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.
        
           | sokoloff wrote:
           | > civil dawn
           | 
           | Do you mean civil dusk?
        
             | qwertox wrote:
             | Right, sorry and thanks for pointing it out.
        
         | phh wrote:
         | My dream UX for that is a single ambient led ranging from green
         | to red, but making it overall usable counting we're two, using
         | two different trains, with different WFH schedule is rather
         | complicated
        
         | Scene_Cast2 wrote:
         | Check out CityMapper. It handles your use case, as well as
         | multi-transit hops (e.g. bus to subway walking time) as well.
        
       | knodi123 wrote:
       | Small world. I did this on behalf of BlirpIt for UVM back in 2009
       | or so. We had trackers on each bus, and they would report
       | location on a certain interval, or whenever the speed changed by
       | a certain threshold from the speed at last report. We had server-
       | side geofences on each bus stop, and defined a "route" that was
       | just a chain of stops, and then we stored a moving average of
       | time between each pair of stops and that was about it. One of the
       | more fun projects I was doing back at that time!
        
         | timmaah wrote:
         | Small world indeed.
         | 
         | > 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.
        
       ___________________________________________________________________
       (page generated 2022-11-04 23:01 UTC)