How to setup a simple and easy self-hosted vehicle tracking system

Nick Rodriguez By Nick Rodriguez - Updated: August 07th, 2018
Posts 23    Views 275    Like 2
Learn about simple fleet tracking without vendor lockin or recurring costs, and keeping your data private and under your control.

I recently had the need to setup a vehicle tracking system for a client. What I thought would be a simple task turned out to be more complicated and involved than I imagined, so I'll share my experience and go through the steps I took to get it up and running as quickly and painlessly as possible.

Requirements

The first step was to figure out the requirements and start researching products and services that would match the needs of my client. In my case the system would be for a small fleet of vehicles (about 20 vehicles). The gps data itself had to be self-hosted and not dependent on any subscription services, and there needed to be a simple and cheap device that could be easily installed and maintained. And finally, there had to be a way to access the data online either via a website dashboard or app to view the vehicles on a map and download reports.

With those requirements in place it was now time to start researching the available products.

Researching products and services

The first thing I discovered was the wide spectrum of tracking devices and services available, which were mostly subscription services and using proprietary tracking devices. This can make it confusing because there are so many use cases for gps tracking. And to make matters worse, nothing I encountered would allow me to self-host the data. When I'm in a situation like this sometimes it helps to search Amazon and Ebay and search for the most popular type of product you want, this will bring up products that have already been vetted and tested by the community, narrowing down my search. I ended up settling on a device I found on ebay that connects to the obd diagnostics port of the vehicle. I liked this because it was easy to connect and configure and would already be powered via an existing port so I didn't need to add extra wiring. All I needed to do was add a SIM card to the device and plug it in, and I could login to an existing, easy to use dashboard to track the vehicles.

Problems with cheap tracking devices

Things went great for awhile until I started seeing problems with certain vehicles not accepting the device and the battery going dead. While not a big problem, it was still happening to enough of the vehicles and so I had to begin looking for a new solution despite having already purchased four of the units. This is the problem with buying cheap hardware devices, you're tied to a single device that is cheaply made and will likely be obsolete in a year. Support is non-existent, documentation is terrible, and you're dependent on the device and a 3rd party platform for the foreeable future.

Looking for a robust open-source solution

Now that my experiment with a quick turnkey solution was over, it was time to look for something more future proof and flexible, so I knew it would most likely have to be an open source project. I found several projects mostly dealing with personal tracking, but I needed something focused on fleet tracking and preferably with a built-in dashboard to handle the data. I narrowed my choices down to two, opengts and traccar. I ended up going with traccar because it seemed more polished and had great documentation along with optional android and ios apps.

Wiring the vehicle for a phone

Because I'm using a software solution, it means I'll need to have a phone permanently attached to the vehicle. So after some quick research on Amazon, I had a power adapter and fuse box connector ordered and in the mail. I'll be putting the phone under the dash board so the driver can't see it, and running the traccar client directly on the phone. You can also wire it to the ignition switch so it only charges when the car is running, so it won't over charge the battery at night. Another advantage of using software is that there are many used phones available that can easily handle the task of sending location data, so you can control the hardware costs.

Setting up and configuring traccar

Installation and setup was straight forward thanks to the simple documentation and installation scripts.

Depending on your server download the appropriate zip file here, https://www.traccar.org/download/

In my case I'm using a Linux server.

Unpack the zip file, and run:

sudo ./traccar.run

You're also going to need to setup the database and modify the config file at /opt/traccar/conf/traccar.xml, here is what mine looks like:

com.mysql.jdbc.Driver
jdbc:mysql://localhost:3306/traccar
traccar
traccar

For more configuration options check here, https://www.traccar.org/configuration-file/

Then start the daemon with:

sudo /opt/traccar/bin/startDaemon.sh

At the first start it will build the database and set everything up automatically, so give it a minute to complete and run.

Next I needed to open a couple of ports so it could be reached through the firewall, these were ports 5055 (android client) and 8082 (admin dashboard).

Once that is finished you can test to see if the dashboard is reachable by going to yourdomain.com:8082 and seeing if the dashboard comes up.

And to connect the phone with an android client, set the url of your server and the port (5055).

Conclusion

After a few weeks everything seems to be working fine, there are some issues that need to be dealt with such as what happens when the phone crashes or turns off, but I already knew I'd have to deal with recurring maintenance issues. I'm also confident that this will be a future proof solution that can scale up if needed. And with the peace of mind of keeping the data self-hosted and under my control, it should help to keep the client happy.