Saturday, August 10, 2013

My Arduino distance-from-home project, before and after Latitude

In my previous post, "Heroku notes" I mentioned an app I had deployed on Heroku that got my Google Latitude coordinates, calculated the distance to my home and posted this distance to ThingSpeak and to my Arduino (using Teleduino). This app is a node.js app derived from a NinjaBlocks device, using code originally written by ChrisN (thanks a lot to ChrisN for code and all his help). My app uses all of the original ChrisN's code to get the Latitude position and calculate the distance but instead of pushing these values to a NinjaBlocks device, it sends them to a ThingSpeak channel. In addition, it calculates PWM values to be sent to an RGB LED connected to my Arduino (in fact, there are 2 LEDs on both sides of a board, to make it light better), that will show red when I am far from home, blue when closer, green when home.

As a side note, if you are interested in more info about deploying NinjaBlocks app to Heroku, see this How-to.

On August 9th Google discontinued Latitude, which was very unfortunate and upset a lot of people that used it for real stuff; so I had to find another way to do all this. The easiest thing was to find or write some simple Android app that gets the coordinates and post them to some custom URL. After quite a lot of searches, I was able to find such an app in the Play store: EasyGPSTracker written by Christian Brosch. This app allows setting a custom URL to which it will post some data containing latitude, longitude and a few other optional fields (docs are here). Big thanks to Christian for writing this app, it saved me a lot of time since I am only a beginner with Android coding.

And since my first Heroku app was a node.js one, I decided this time to try a Java app; I was worried it will take me a very long time to do this since I am not familiar with maven (which is what Heroku uses for Java apps deployment) but Heroku awesome as it is (I know, I am repeating myself) has quite a few templates to start with which made writing the app a breeze. This app does basically the same thing as the old one except this time it gets the POST-ed data from Christian's app, calculates the distance which is sent to ThingSpeak and then the PWM values to be sent to my Arduino.

I kept the original app's name as generated by Heroku, pretty long but I liked it: hidden-hollows-5561 and named my servlet geo so this is the link. Anyone can try the link however it won't do anything unless you POST the data in the right format and even then it will only send back an arbitrary distance. I started working on a GET method that can take 2 latitude/longitude pairs and return the distance between them but never finished: if I do and anyone will be interested, I will post all the details of the GET call.

The next step is to find a way to get rid of the wires; right now, the Arduino uses an Ethernet shield so I need a wire going to it; I'm using a wall wart to power it so... another wire. If I find a way to make it more portable without spending a lot of money on a WiFi shield, I'll update this post.

There is nothing special in the Arduino code since I'm using Teleduino so there is nothing to post here. The Java code for the Heroku app is also pretty simple so again, nothing special to post. To calculate the distance I am using a library I found in google code: simplelatlng, very easy to use and well documented - thanks to the author!

No comments:

Post a Comment