The VanDea

GPS tracking for you vehicle.

maybe someday I'll leave West Seattle

Plot maps of places you already know you’ve been too, but now you have proof!

The Build

Materials

  • A GPS device like this. I have setup a part of the code to just use IP address, but from my experience this will only track specific cities you have been in so it’s not as fun.
  • A Pi. See this guide for mounting
  • Internet access. There are GPS modules that will connect itself, but they are more expensive and need it’s own SIM card. The process should work the same for those though.
  • some beer

The Process

Most GPS modules including the one I use will have a magnet on it. Stick it to the roof or wherever inside the vehicle and connect the USB to your computer. Bada bing, bada boom you’ve got the GPS connected.

Testing before we setup further

Now for testing it works before we setup my repository. Run the following to install the dependencies.

1
2
3
4
5
6
7
# The GPS libraries and programs
sudo apt install gpsd gpsd-clients

# Quite frankly I don't know why it doesn't work out of box
# But the following will fix that
sudo systemctl stop gpsd.socket
sudo systemctl disable gpsd.socket

Make sure you see /dev/ttyACM0 in the filesystem (the gps module). Write the following to /etc/default/gpsd

1
2
3
4
5
6
7
8
9
10
11
12
13
# Start the gpsd daemon automatically at boot time
START_DAEMON="false"

# Use USB hotplugging to add new USB devices automatically to the daemon
USBAUTO="true"

# Devices gpsd should collect to at boot time.
# They need to be read/writeable, either by user gpsd or the group dialout.
DEVICES="/dev/ttyACM0"

# Other options you want to pass to gpsd
GPSD_SOCKET="/var/run/gpsd.sock"
GPSD_OPTIONS="-n"

Then run the following.

1
2
sudo killall gpsd
sudo gpsd /dev/ttyACM0 -F /var/run/gpsd.sock

Now to make sure you are getting data (you will need internet depending on the device). Run

1
gpsmon

And you should see some data similar to this output.

gpsmon Output

If you can get data to show up from gpsmon you will be able to use my gps tracking project later.

GPS tracking

There are several other projects that will make use of the GPS displaying graphs maps and what not. I’ll post a list below, but for my purposes I wanted to view this in my Grafana instance.

The rest of this portion will be around my Grafana setup.

Grafana setup

I’ll assume you have a Grafana instance setup either on the pi or an external server.

First we will install this TrackMap plugin for Grafana. Run the following command wherever you have Grafana installed.

1
grafana-cli plugins install pr0ps-trackmap-panel

This Grafana plugin makes use of an Influx DB, so you will need to install that and setup some credentials for connecting to it. If you don’t care for my code, all you need is a latitude and longitude field in your influx Database (or MySQL if you view the plugin page) to be able to use the TrackMap plugin.

My GPS Repository

We will clone what I have setup to send this data to Influx and Grafana. And then setup a config that will use your Influx DB credentials. You will Nodejs installed.

1
2
3
git clone https://git.chuckfairy.com/chuckfairy/gps-tracking
cd gps-tracking
npm i #installs node modules

Setup a config in config/config.js. Copy the config/config.example.js file from the repo to the location config.js will give you a head start.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
module.exports = {
//If you intend on just using your internet IP, grab a license key from MaxMind for GeoIPLite
//You will also set the key "method": "internet"
//"license_key": "YOUR_KEY_HERE",

//Influx credentials
influx: {
host: 'yourdomainorlocalhost.com',
database: 'location',
username: "chuckfairyrules",
password: "hispasswordrulestoo",
},

//either "device" or "internet"
method: "device",
}

Test it out by running ./app.js. If all goes well you shouldn’t see an error. Make sure you know the full path for the next step.

For running periodically I use crontab. Run crontab -e and you should enter an editor where we will add the following.

1
2
3
4
5
# Where "10" is is how many minutes you run.
# So I'm running this every 10 minutes, but you might want more or less or only once a day.
# checkout https://crontab.guru
# After ">>" will be your log file
*/10 * * * * /home/pi/Sources/gps-tracker/app.js >> /home/pi/Logs/gps.log

Now to checkout in Grafana. Create a datasource for the influx DB if you haven’t already. I create a measurement called location that you’ll see later. Here is the panel config and what you’ll be doing to setup.

Setting up the panel in Grafana

Go out for a drive to check it out with some data. Eventually you’ll see something like the map on the left of my dashboard. Make sure to save the dashboard, I’ve lost plenty of panels to exiting early.

maybe someday I'll leave West Seattle

Well

It’s a fun idea to track your travels. I wish I set it up earlier so I could see my trip from Illinois to Washington state. It’s a bit of a setup when you factor in Grafana, Influx, and especially as the USB GPS device is not so plug in play. So I give it an 8/10. In the chance the vehicle is stolen, you’ll be rest assured as you’ll know the location of the chop shop!