I’ve got around a ten minute walk to my closest train station every morning. Depending on how late I’m running and if I’m hustling or not, that time can swing from eight to twelve minutes. It seems like every time I try to do the eight-minute run, I always end up getting to the station right as my train is pulling away. To help better predict how much time I have to catch a train, I made a button that can figure out when the next train arrives. Once it gets the time, it sends me a text to my phone - that way I can hit the button on my way out the door and not worry about it until I make it to the bottom of my stairs.
Set Up Your Edison
Full disclosure—I’m working on a Mac, so these instructions will skew that way. To get started, you should have a freshly-flashed Edison. After you board is flashed, you can try to find the IP address and enter all the additional commands, or you can just “npm install bloop” on the machine that you’re trying to SSH in from. Bloop is a tool from Rex St. John, and it’s an absolute lifesaver when you’re working with the Edison. Instead of running “screen /dev/cu.usbserial-XXXXX 115200 -L”, all you have to do is run “bloop c” it will connect to the Edison it finds on your network. Once you’re in, run “configure_edison –setup” to get your wi-fi and user creds defined.
While all this is happening, you can start downloading the Edison Yocto Image from this site. You want the link that says, “Edison Yocto Complete Image.” Once downloaded, you’ll need to load the files onto a micro SD card - you can read up on Yocto and how to get those files onto the SD card here. After you load the files, power down your Edison, insert the SD card, and the power it back up. To test your install is working, bloop in to your Edison and type “node -v”. If that returns the version of Node that you have installed you’re good to go. If it says “Command not found,” you’re going to need to try loading Yocto onto the SD card again, because something went wrong.
Hook Up Your Button
If you read any of my other Edison posts, you know that I've been working with a Grove Starter Kit that I got from Intel and Instructables. I used the small pushbutton from the starter kit for this project, but you can use any button - the bigger, the better.
If you need help figuring out how to hook up the button, the Arduino website has a really great tutorial to get you pointed in the right direction. Whatever button you end up using, all you need to do is hook it up so that it's outputting to a digital pin on the Edison. I used D2 for my program. Once that is connect, you can go ahead and power on your Edison.
Bells & Whistles - a 3D Printed Case
I 3D printed a case for my Edison using a design from Thingiverse. The case uses the screws for the struts to secure the lid, and has two slots for the shield pins to go through. I did have to drill an extra hole in the lid for the ISP pins, but other than that everything fits great.
Chicago has been making a huge effort to make a lot of resources available to developers over the past few years. We’ve got the Data Portal at our fingertips, the Array of Things on the horizon, and fairly comprehensive access to the CTA’s API. We’ll be using the CTA API to ask for arrival times for a specific station.
In order to use the CTA’s API, you’re going to need to apply for an API key. I’ve never heard of them turning someone down for a key, but it does take around a day to turn around. You can apply for an API key here.
Once you have your API Key, you’re going to want to find out the station ID for your home station. You can find the station listings here. It’s worth mentioning that this whole thing would also work for the CTA’s Bus Tracker API, as well as a slew of other transit APIs from other cities.
In addition to the CTA API key, you’ll also need a Twilio key. If you aren’t already familiar with it, Twilio is a service that lets you send calls or texts programmatically. To get your Twilio API Keys, you’ll need to sign up for their free trial here. The trial lets you send thousands of texts before you have to decide if you want to pay for your use, so you should be in the clear for this and many other projects.
Write the Code
Now that you’ve got your API stuff all sorted out, we can actually write the code that’s going to be running this stuff. Code be found on GitHub, but come on, write it out yourself and get a good understanding of it.
Run Your Code
In the terminal window that has your Bloop session open, type ‘node traintracker.js’ in the root of your project folder. This should start the JS running. Check your terminal to see if the Edison gave back the MRAA version - if it did, you’re all good to go. Go ahead and press the button, and then wait for your text.
If you don’t receive a text, take a look at the output in the terminal. The code will return an error telling you what you’re missing. Make sure that you replaced all the CTA and Twilio API keys, as well as the Twilio numbers.
If your button is working, now you can hit it on the way out your door and have you marching orders texted to you right away. Yay, Internet!