How to create a GPS tracker with a Raspberry Pi, USB GSM Modem, and AWS

Introduction

Recently I’ve been worried about recent car thefts and thought I’d create something to give me some security over the matter. This is why I decided to create a GPS tracker. It’s not the first time I’ve installed a Raspberry Pi in my car, I created a dashcam that used the Raspberry Pi V2 camera and the inbuilt WiFi to act as an AdHoc AP. This allowed me to see what’s happening in front of the car when I wasn’t there and also transfer files as soon as I arrived back at home to my local home server as a USB WiFi dongle was also attached that connected to my home WiFi.

The Accessories

For this project I used;

  • USB mobile GSM dongle (I used a Huawei E303).
  • USB GPS Dongle (U-Blox 7).
  • Raspberry Pi 2 (I had this spare laying around + good processing power).

How it works

The raspberry pi has Debian Jessie installed that is currently the latest OS you can run from the Raspberry Pi website. I chose to have the desktop already installed as it comes in useful when I want to remotely control the pi via VNC. More on this later.

WVDial – Connecting to the GSM network

Setting up the USB GSM Modem was a bit of a pain. I used a piece of software called wvdial that you can install via apt-get. The configuration for this, since I used giffgaff is;

The config file is located at /etc/wvdial.conf

There’s no private parts retracted from this as it is all generic since the SIM card is what is registered with the network.

Once this was setup you can simply run sudo wvdial and it should dial in and connect fine. You’ll notice if you also run ifconfig -a it created a ppp0 interface that is used to access the internet.

Now, for me when testing, I also had my Ethernet cable connected so in order to test I had to change the default route. To do this, just run;

Now, if you ping google.co.uk or any other site, you should see some times that are quite high due to latency when on the mobile network.

Once I know this was working, I created a little script that launches on startup;

This could be written better, but I’m no bash expert, but it works.

This script checks to see if the interface ppp0 is available, if not, then it continues with the loop and attempts to start wvdial again. Once wvdial is running an an interface is created, it then starts the tracker application that is written in node.

GPS Dongle

Setting GPS up on the raspberry pi is a relatively simple task once I knew what I was doing. Simply plug in the USB dongle and identify which port it is using. I found that mine was on /dev/ttyACM0. I found this out because if I ran sudo cat /dev/ttyAMC0 I could see a lot of raw GPS data.

Once this port was identified, then I proceeded onto installing some utilities by doing sudo apt install gpsd gpsd-clients.

Once this has finished installing, proceed to run the following commands, assuming the port you identified was /dev/ttyAMC0 like mine was.

If you have a GPS lock, you will see all the fields populated in that window. You can close it by doing CTRL+C.

The tracker + AWS

At some point I will upload this to github. For now, I’ll explain what I did.

The tracking application is built in NodeJS and uses a node module I come across called node-gpsd. This handles the parsing of the raw GPS data that you saw earlier and returns a constant stream of GPS data in the form of a JSON object. I then setup the necessary IAM roles and policies in AWS so that only the Lambda has permission to read/write to the DynamoDB table and Cloudwatch for logging. I also setup an AWS gateway and added a POST method that is passed to the Lambda that just handles putting the data into dynamo, nothing else.

Here is how it looks in AWS Gateway:

And here’s what the DynamoDB table looks like (with the coordinates retracted):

NOTE: I should note that the tracking application determines whether to send the location by checking to see if the vehicle has moved by matching the previous sent coordinates to the current coordinates. This saves bandwidth and write units on DynamoDB.

Repositories

You can clone the repositories for both projects from Github.

Summary

I will improve this article soon and provide images for you to see what I have done visually and provide the source code for my Lambda and tracking application.

I have tested this system and it works very well, the location is highly accurate!

Please feel free to leave a comment on any questions you may have and i’ll try my best to help you.

It’s been a while

It’s been a while since I last wrote a blog post. I thought I’ll just give you all a quick update as to what is going on right now.

In September I started college studying Electrical/Electronic Engineering at Level 3. It’s been over a month since then and I’m really enjoying it. Never the less, I still continue on with my projects at home. A few days after enrolment day, I mounted a 100W solar panel on my roof. This connects to a solar charge controller which controls the voltage/current going to the battery. Right now I only have one single leisure battery and require more for my project to be completed. My aim is to completely run this room from solar. I only ever use the light, computer, and my home server which is planned to stay on 24/7. In total the wattage adds up too… 600W(pc) + 250W(home server) + 25W(light) = 875W. Currently, the system powers the room light and my phone charger.

Right now I’m seeking a job in order to complete this project.

My first post in a very long time

Well It seems I haven’t made a post in a long time. Well, what’s new? Well the other week my Raspberry Pi came which I have been waiting quite some time for. It’s such a cool little device… For you who don’t know what one is, it’s considered to be the worlds smallest computer which can fit in the palm of your hand. Here’s an image of one…

 

 

The first thing I did once I installed the linux operating system debian, was over clock it to it’s newly overclocking setting, 1GHz. The default was set to 700MHz which is obviously, as slow as some modern smartphones today. However after reading that this can cause SD card corruption (which is not a good think, eeek) I left it at it;s standard setting. I bought a 2A plug to use so I know for sure it’s getting enough power in to run everything I want it too. Right now It is hooked up to my 5v 2A mains plug, and has wireless USB card which supports b/g/n and up to 150Mb/s transfer rate.

I’m pretty proud of it. I can do almost anything on it like compiling source code (which it’s meant to do), run a web server along with a MySQL database with php5 installed, and of course something I just have to install, boinc. Why? Because… I can? So, What is boinc? Well, “BOINC is an open-source software platform for computing using volunteered resources.” Basically you attach a project which you would like to be part of, lets say the LHC@Home project. I simply login and then it automatically attaches, and the boinc client then sends a request to download the master file so then it can then request work. This work uses your CPU’s idle time, and can be set in the options to run at different times of the day. Handy for when your not using the computer, you can just crank up the CPU usage a little, OR, let your GPU do the work if your computer is in use.

Good old’ Johnny Cash – The ‘Sound’

I created a recording of my self doing some guitar licks (Intro’s & Solo’s) of some famous Johnny Cash songs. If your wondering what I mean by this, have you ever heard a twangy kind of sound in his songs? If you dont know what I mean, then take a look here…

Did you hear the the guitar at the beginning? Keep listening all the way through. Luther  Perkins was Johnny Cash’s electric guitar player from 1954-1968. Sadly he passed away (January 8, 1928 – August 5, 1968). You can read more about him here.

He created Johnny Cash’s ‘Boom-Chicka-Boom’ sound. And now, I just so happened to got my self interested in this sound and now I’m sharing with you me playing Luther’s part.

I bought a Server!

Welcome to my personal website; my space here on the web. Today is my birthday, and I’ve had enjoyed my day 🙂

With the money I got for my birthday and the money I had saved up, I went a head and bought my self a dedicated server situated in France. With this server I can accomplish my goals such as publishing my websites and hosting other services.  As a developer I did need this, as having a home server originally had a down time everyday and I could not pay for having it on 24/7. However it served a good purpose in hosting my gaming/web servers.

I’ll try and keep this website up to date and work on it every now and again.