Inspiration

This is a hackneyed hack, but this had to be done for my own sake. I am an International student in a University town so I depend on the town's bus service a lot. There's a bus every ten minutes during the weekdays and gets more infrequent during weekends. If I miss any bus that I was supposed to take, it is guaranteed that I'm going to be late to class. And even if I am on time to the bus stop it's not guaranteed that I'll get a bus soon enough. I don't like waiting for the bus at the bus stop and as a result I end up just missing the bus a lot, so I thought of taking advantage of this hackathon to create a python script to help myself through visual and sound cues to not miss another bus.

What it does

  1. When I'm ready to get movin', I send a message to my app using Twilio messaging services to start monitoring buses. In the message I specify two arguments: the route number I intend to catch and a time threshold. I can send 'all' as route number if the route number doesn't matter. This time threshold is set as the time it takes for me to reach the bus stop + a cushion in case the bus arrives earlier than expected (I can wait for 1-2 minutes)
  2. Using Transloc's OpenAPI, the app receives arrival estimates every 30 seconds. If it sees that there is a bus arriving at around the threshold time, it sets up the Circuit Playground to light up and beep. It also sends back a text saying that the bus is approaching (originally for debugging purposes but it could be a feature)
  3. The Circuit Playground board (which is going to be hung up in my room in clear view) lights up in the color of the bus route that is arriving. Transloc has color codes for each route, for example the bus that I use frequently is a brown route and the other bus that I can take is purple. The board also beeps as a sequence of musical notes. The board will keep doing this for around 20 seconds or till a button on the board is pressed.
    ## How I built it I used python with flask to act as a server to handle request sent via text using Twilio services. I used ngrok to tunnel my local server to the internet. To get arrival estimates transloc openAPI was used. I used circuitplayground firmata and libraries for the hardware part of the code. I heavily relied on online sources and sample codes. ## Challenges I ran into The first mistake was that I thoroughly underestimated the time it was going to take for me to finish the script. Since the idea was very simple, I assumed it wouldn't take so long. Alas, I was mistaken. Since I was using a lot of new technologies at once I think I got a little too overwhelmed. I had thought of using Bandwidth APIs first, but the documentation was hard to navigate and the tutorials seemed lacking, so I switched to Twilio (which I had fiddled around with once before but was still very new to). There was also an issue with flask and the public server. I was new to flask and ngrok too, and there were little mistakes that were hard to find and troubleshoot. I wanted to use multi-threading, but that didn't work out either after a lot of trying. Since I'm also starting to get interested in hardware I thought it would be fun to integrate a bit of hardware code into the script to provide visual cues in the form of LED lights and auditory cues in the form of tones. The hardware code caused a bit of a problem in the server code. I originally wanted blinking LEDs with two notes playing, but the code was causing a huge lag in the server. It was also hard to figure out how to integrate and code the button events to get the lights and sound to stop. Testing the app was also a pain since there are no bus services in the evening in the weekends, so the API requests wouldn't receive anything, so I had to rely on a lot of hardcoding to test the script. ## Accomplishments that I'm proud of I'm proud that I overcame most of the challenges that I just described and even if I couldn't, I figured out a successful work-around. I'm glad that I could successfully put together so many new technologies into a script and made it work. ## What I learned Apart from the new technologies like flask ngrok twilio, I learnt to get out of my comfort zone. I have always had a distaste for client-server programming and I haven't done a lot of hardware work. Even if the code was minimal, I did learn a lot about solving problems to make things work. I also learnt a thing or two about time-management. Another lesson learnt the hard way and for the millionth time is that things necessarily won't go my way, and I just need to stay positive and never give up. ## What's next for Bus Lights The first thing is to try to get multi-threading to work since multi-threading would make the server more efficient and let it accommodate more than one clients (via text). I might also try blinking LEDs since blinking lights are better visual cues. I want to make the script more modular so I might have to break my code up. I am also planning on a snooze feature.

Built With

Share this project:

Updates