• Personal Blog

    Posted on January 18th, 2015

    Written by Denis Finnegan


    Dublin Bus Pebble App

    Fresh after the huge success of the Irish Weather App, ok I’m exaggerating a little but where and when I could find the time between work and my other interests, I was just dying to have another go at an App for the Pebble. Specifically a Dublin Bus app that would show the nearest stops, allow you to select a stop and then see the time for all busses arriving at that stop. Perhaps some extra bells and whistles like route information, journey times and favourite or recent stops could be added at a later stage but I was eager to get something functional up and running as quickly as possible.

    Dublin BusI saw an opportunity for the Dublin Bus App because, while there was an app for the Dart Train Service, nothing for Real Time Information for Dublin bus which is actually already available from DublinBusRTPIService. Unfortunately, the limited PebbleJS AJAX examples I had available don’t show how to interact with a SOAP API and I didn’t have the expertise to derive this myself. Bummer! first road block.

    I came accross a JSON / XML API available from DublinLinked but there was a ton of red tape to go through to get access and speed was of the essence. Finally I came accross an API by Jordan Neill https://github.com/jneill/dublinbus-api which seemed to do all that I needed. For example, http://dublinbus-api.herokuapp.com/stops pulls back all of the bus stops. Unfortunately, the one real key bit of information that I needed, was the part that gets the current live information for a particular bus stop and it seems that this was the only thing no longer working. I decided that I would plough on with what I could use and I’d through AJAX and parsing the response, figure out how to get the actual bus arrival times from http://www.dublinbus.ie/rtpi/ which I was pretty confident I could do, it would just be a pain in the pants.

    Dublin Bus Pebble App by Denis FinneganIn the most bizzar turn of events, a work colleague saved the day (Daniel Fanica, a Software Developer on my Development Team at Tesco Health and Wellbeing). I had been chatting about my new pebble watch and how I had hit a bump in the road in my latest project and as it happened, he had been planning to build the same kind of app for his new Moto360 Watch. On mentioning my delima he was delighted to inform me that he had already built an API that scraped the Dublin RTI site and that I was welcome to use it. Armed with this final piece of the puzzle and full of excitement, I finished the app over the weekend, about the only real block of free time I get these days and voila, we have real time information for the nearest bus stop. There’s a nice preview of it here (http://pblweb.com/pas/54b2a8296357cebb9a000081) where someone is loading the Pebble Store Apss onto their own service but below are the features that I’ve produced thus far.

    Simple Dublin Bus app to show Irish Bus times. App tells you the distance to the nearest bus stop and when the next bus is due.

    • Loads list of Bus Stops with in 2km Radius.

    • Name and Distance to Bus Stop.

    • List of Services & Due time for Buses.

    • Detailed Information of Bus including Stop Location, Destination and Route.

    I still have a lot more to do with this app as I type this, I first need to add a refresh shake or something similar or maybe just even pressing the “up button” to update say. I want to add some favourites and or recent bus stops accessed plus all the other things I mentioned at the top of the post so hopefully, I’ll have a free weekend soon.

    The Code

    Dublin Bus StopsThere’s about 400 lines of code in this one and it definately was trickier to build and structure and again,t here is a separate file for loading in the real time information for the busses, again all available from my GitHub Account. You’ll also find I’ve left in a lot of commented code, this time I left it in just to show where I was getting stuck and ideas I was exploring but of course you can delete it all.

    As usual I loaded up a splash page while the API connected. Then we have several different functions which I will go through. Firstly we call the  getLocation() fucntion which uses the geoLocation from the phone using a listner function. This in turn will then triger either the geoFail or the showPosition function and the showPosition function is really where the fun begins.

    IDublin Bus Inbound Bussesn the showPosition function, the AJAX is triggered and this where several functions are nested and called from. Once we know how many bus stops there are in the returned date by counting the keys, we know how many to list.  We then call parseNearbyStops() and pull out the name and stop number and we figure out the distance to these stops by calling the getDistanceFromLatLonInKm() function.

    The getDistanceFromLatLonInKm() function just uses a standard as the crow flies as calculating using street directions from google or some other source, would have taken a lot more effort for very little gain.

    Dublin Bus Route InformationOnce the customer has selected a bus stop, well then I switch to Daniels API and I request the real time information for that stop, for example, http://sapi.danielfanica.com/dublinbus/stop/4563

    This calls the realTimeInfo.js file which does a little error handling depending on what Daniels API returns and then handles populting the bus information into a standard menu using the UI.Menu selection. Finally, as a little extra, I just added the ability to see the full read out for the bus route and to see the to and from locations for the bus, just in case the traveller was not sure they were getting on the right one. Then back to the main app for a bit of tidy up but that its.

    Dublin Bus by Denis FinneganStill have a lot of work to do on this and perhaps I released it on to the pebble app store a bit too hastely but it’s already had a few hearts and downloads although doesn’t seem to be as popular as the Irish Weather Pebble App I made previously. After I get the remaing bits I want done here, time allowing of course, I’d like to build a sort of Ireland App, that would have bus, rail, weather, the alerts you see on the M50 signs and more on it as the problem is you can only have 8 apps on your phone so I don’t always have space for my own apps.
    Anyway, signing off for now, thanks for reading. Stay tuned for more adventures of an IT Manager.

    This entry is filed under Personal Blog. You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pinging is currently not allowed.

    Take a look at some of the responses we have had to this article.

    1. Jacob
      Feb 23rd

      WEll done, app is great. Small suggestion, for frequent commuters it would be handy to have 2 modes: “discover” all stops around, like now, and also check status of favorite stops. I normally use only few stops, and it would be perfect for such scenario. My 5 cents…

      • Wow, thanks Jacob, that 5 cents you offer is the best payment I’ve ever received as I didn’t think anyone was even using the app so I never went ahead with any updates 🙂

        Absolutely take on board what you say and will add a feature to maybe have recent or saved stops for easy access as well as a shake or button press to update feature.

        Thanks again for the message, I’m stuck in some other bits at the moment but will see if I can get to a few updates next weekend for you.

        Cheers, Denis.

        • Jacob
          Feb 26th

          🙂 I’m using your app every single day, most of the time from same bus stops. It’s so much easier and faster to check bus status without phone! I’m using also luas, but there is no app for that (yet). But there is even Dublin Bike app, also very nice! 😉

          • Apologies for not getting to this at the weekend Jacob, I’ve not had a lot of time to work on this at the moment but I’ve put in a quick feature to save the 20 most recent stops which will hopefully suffice for what you need.

            I have added a “recently accessed stop” function at the top of the list of nearby stops, each time you now open a bus stop, it will be added to your ‘Recent Bus Stops’ list (and there shouldn’t be any duplicates). The list is currently limited to 20 recent items but this is arbitrary and can be increased. As I say, when I get time I might at favourites and a few other options to clear recent and force refresh etc.

            Let me know if the new feature is in line with what you were looking for.

  • Leave a Reply

    Let us know what you thought.

  • Name(required):




    CAPTCHA Image
    Play CAPTCHA Audio
    Reload Image