Introduction: Tracking My Car Trips Without GPS

About: I am a techie DIYer who loves tinkering with electronics. Twitter @MrDIYca. For more info and my full contacts, please visit www.MrDIY.ca

In this project, I will show you how I track my car's trips using an ESP8266 board and serve them on a HTTP webserver with the help of Google's Geolocation and Maps API services.

Step 1: Watch the Video

Step 2: Order the Components

-- LINKS -- (When available, I use affiliate links and may earn a commission)

Amazon.com:
- Wemos d1 mini (4M version) - https://amzn.to/3jLR1Qd
- Shield - https://amzn.to/3tZTk7C

AliExpress:
- Wemos d1 mini (4M version) - https://s.click.aliexpress.com/e/_dXcNTYU
- Shield - https://s.click.aliexpress.com/e/_AZer1e

Amazon.ca:
- Wemos d1 mini (4M version) - https://amzn.to/3fx28Lq
- Shield- https://amzn.to/3rpSe3i

Step 3: Background

A few months ago, I made a video about monitoring my car battery level and that got me thinking: why just the battery? Why not monitor my car trips as well? So, let's build a car trip tracker ...without GPS!

If you would ask someone to build a trip tracker, they will most likely think of some kind of a microcontroller paired with a GPS receiver, record checkpoints, and plot the path.

But there is a less common known way using Wifi Geolocation and Google provides such a service.

Step 4: Wifi Geolocation

You can send a list of wifi access points from a location to Google's API and it will return the GPS coordinates for that point. This is really exciting, because using this basic concept, I was able to build this project.

The picture above shows my car trip tracker. It sits in my car and it records all my trips. The trips are saved and hosted on this tiny device which cost just a few bucks ... and you guessed it. It's an ESP8266 device.

These pages are hosted on an HTTP server running on the D1 mini. The homepage, I see a summary of my trips. I can click on any given trip to view and interact with it. From there I can see the raw GPS coordinates or view the list of access points' mac addresses. I also have a delete option for both.

To explain how wifi geolocation works, I created this sample code (esp8266_geolocation.ino + cert.h) . When the D1 mini boots, it runs the get_my_location() function. In that function, it scans for the surrounding wifi networks and prints them. Then it prepares the data for the epIcall. With that payload, it connects to the Internet, sets up the SSL connection with google, and makes the API call. When it gets a response, it prints it. And if everything goes well, it responds with the GPS coordinates.

The only thing that happens behind the scene here is the API key setup. You need to get an API key from Google and have the geolocation service enabled on it. If you are not careful you might get charged. So make sure you stay within the free tier.

So this is how you can get the GPS location by knowing the surrounding access points.

Step 5: Device

Above is my schematic. It has a Wemos D1 mini connected to two modules - an SD card and a real time clock. The sd card is used to save the trip files and the RTC is used to timestamp the trips. As you might already know, the ESP8266 doesn't have an internal clock so an RTC is needed.

When I put everything together. I get the prototype shown above: the d1 mini is in the middle and the modules are on the sides. But later, I came across the shield shown in the "Order the Components" section. It has the RTC on one side and the sd card on the other. This made my setup simpler and much smaller! I highly recommend this shield. Then, I attached a usb cable and 3D printed a case for it.

The device is plugged into one of the usb outlets in the car. It is only powered when the car is running.

When the device boots, it starts looking for my home wifi. If it finds it, it connects and serves this portal. This allows me to access my trips history.

And when it starts and doesn't find my home wifi, it assumes I am on the road and starts recording a new trip. It does this by creating a new .log file. It uses the current timestamp as the file name. Then it starts saving the list of the access points it finds every 5 seconds. These "files" I call them "Trips" on the portal. To convert these trips - using the geolocation API call- all I have to do is press one button and it generates a new file with the same timestamp but with a .gps extension. The file contains the results returned from the API calls containing the GPS coordinates.

I then use Gogle maps to plot GPS coordinates on an interactive map.

Dealing with big files on the web server was a bit challenging though. The ESP8266 only has 40k of memory. When I tried to load big files from the sd card to memory, it crashed the device. So I used a buffer to send chunks of the file at a time until the entire file is transferred. I then used AJAX to handle the manipulations on the frontend to display big files, long lists, or plot maps. That seem to have solved the limited memory issue and it worked great.

Step 6: Done

I had so much fun creating this project and I am very happy with the results .. and to be honest I was surprised on how accurate Geolocation is. I didn't expect that! If you want to give this project a try, buy the shield ( see the "Order the Components" section above for links), grab the bin file and flash it to the D1 mini.

I built a setup wizard in the device itself so simply type 'setup' over Serial and follow the instructions.

If you found this useful, please consider subscribing to my YouTube channel and give me a LIKE - It helps a lot.

* Much of the information contained is based on personal knowledge and experience. It is the responsibility of the viewer to independently verify all information.