Hello wonderful spark community
I am making a visual beacon for transit bus arrival at my stop. Often times in lab, my hands are full of goo and I want to check if my bus is coming. I cannot launch the app or don’t have my phone. I need a way to just glance over and see if my bus is coming and whether I will be able to make it to it or not.
The way I am implementing this is very specific to my application. I am using the OneBusAway REST API for Puget Sound. Spark core checks their API between the hours I usually travel. The method OneBusAway provides give bus arrival information for all the buses coming at a particular stop between X and Y minutes in future. To keep the response length minimum, I check for buses arriving within a minute, for example show me the buses coming between 14 and 15mins from Now. And I do this every minute, so in theory I shouldn’t be missing any buses. I am using the Rest client library to invoke the GET requests.
Then, I parse the response using the wonderful JSMN library by @peekay123. In the parsed response, I look for relevant information and start an animation on neopixels which lasts until the time I could catch the bus. The idea is inspired by the reddit mail notifier and the program structure is motivated from @BDub’s Bitcoin example.
The beacon consists of engraved acrylic sheet edge lit with a neopixel strip. The base is 3D printed. This is how it looks when it’s time to go home: https://www.dropbox.com/s/qfherttbwgnjqyp/VID_20150113_112328.mp4?dl=0 [12 secs]
But I am far from a reliable solution. My core crashes randomly after issuing a few API calls. Almost always it’s a memory manager hard fault (3 red flashes). As you can see the code pasted below, I am rebooting after every ten unyielding calls (bus in not coming) or one successful call to clear the memory but that doesn’t seem to help.
I am an alright coder but can put things together. I am hoping if someone can review my code and provide pointers to make it more reliable. Mostly, I am looking for inputs on optimizing the core memory and better procedures to do what I am doing.
You can find the code at:
A sample XML response is here:
A sample JSON response is here
And this is the program structure:
Any other feedback, feature ideas, questions or comments are always welcome. Thanks!