4 min read

In this article by Marco Schwartz author of the book Arduino for Secret Agents, we will build a GPS location tracker and use a spy camera for live streaming.

Building a GPS location tracker

It’s now time to build a real GPS location tracker. For this project, we’ll get the location just as before, using the GPS if available, and the GPRS location otherwise.

However here, we are going to use the GPRS capabilities of the shield to send the latitude and longitude data to Dweet.io, which is a service we already used before. Then, we’ll plot this data in Google Maps, allowing you to follow your device in real-time from anywhere in the world.

(For more resources related to this topic, see here.)

You need to define a name for the Thing that will contain the GPS location data:

String dweetThing = "mysecretgpstracker";

Then, after getting the current location, we prepare the data to be sent to Dweet.io:

uint16_t statuscode;
int16_t length;
char url[80];
String request = "www.dweet.io/dweet/for/" + dweetThing + "?latitude=" + latitude + "andlongitude=" + longitude;
request.toCharArray(url, request.length());

After that, we actually send the data to Dweet.io:

if (!fona.HTTP_GET_start(url, andstatuscode, (uint16_t *)andlength)) {
   Serial.println("Failed!");
}
while (length > 0) {
   while (fona.available()) {
     char c = fona.read();       
     // Serial.write is too slow, we'll write directly to Serial register!
     #if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__)
       loop_until_bit_is_set(UCSR0A, UDRE0); /* Wait until data register empty. */
       UDR0 = c;
     #else
       Serial.write(c);
     #endif
     length--;
   }
}
fona.HTTP_GET_end();

Now, before testing the project, we are going to prepare our dashboard that will host the Google Maps widget. We are going to use Freeboard.io for this purpose. If you don’t have an account yet, go to http://freeboard.io/.

Create a new dashboard, and also a new datasource. Insert the name of your Thing inside the THING NAME field:

Then, create a new Pane with a Google Maps widget. Link this widget to the latitude and longitude of your Location datasource:

It’s now time to test the project. Make sure to grab all the code, for example from the GitHub repository of the book. Also don’t forget to modify the Thing name, as well as your GPRS settings.

Then, upload the sketch to the board, and open the Serial monitor. This is what you should see:

The most important line is the last one, which confirms that data has been sent to Dweet.io and has been stored there.

Now, simply go back to the dashboard you just created: you can now see that the location on the map has been updated:

Note that this map is also updated in real-time, as new measurements arrive from the board. You can also modify the delay between two updates of the position of the tracker, by changing the delay() function in the sketch. Congratulations, you just built your own GPS tracking device!

Live streaming from the spy camera

We are now going to use the camera to stream live video in a web browser. This stream will be accessible from any device connected to the same WiFi network as the Yun.

To start with this project, log into your Yun using the following command (by changing the name of the board with the name of your Yun):

ssh [email protected]

Then, type:

mjpg_streamer -i "input_uvc.so -d /dev/video0 -r 640x480 -f 25" -o "output_http.so -p 8080 -w /www/webcam" &

This will start the streaming from your Yun. You can now simply go the URL of your Yun, and add ‘:8080‘ at the end. For example, http://arduinoyun.local:8080.

You should arrive on the streaming interface:

You can now stream this video live to your mobile phone or any other device within the same network. It’s the perfect project to spy in a room while you are sitting outside for example.

Summary

In this article, we built a device that allows us to track the GPS location of any object it is attached to and we built a spy camera project that can send pictures in the cloud whenever motion is detected

Resources for Article:


Further resources on this subject:


LEAVE A REPLY

Please enter your comment!
Please enter your name here