Introduction: Find My Cat -- the GPS Tracker for Pets
I love my cat, Pumpkin, a lot. There were a couple times over the last two years of having him that he went out of my sights (outdoors) and I was really frightened that he had gone missing. If you own a pet, I'm sure you relate.
I wanted to do something about it, I looked for cat tracker options but none really fit what I was looking for. They either lack precision / refresh times (number of times the live location updates), have low battery life or are just unreliable for the most part.
I thought i'd just build it myself. So, for the last 4 months I embarked on this journey, to build the best possible Pet tracker system I can attempt to build.
My design goals were the following:
- Needs to fit on a Cat.
- Needs to have long battery life.
- Needs to be extremely reliable with a near to real time tracking capability.
- Should use GPS for positioning, (cellular / bluetooth only based options don't make the cut)
I was able to cross off most of my goals. And this is just Version 1. I am already working on a Version 2 with the lessons I learned on this build.
Introducing to you my friends, Find my Cat. The Open Source Pet tracker.
- Lasts about 12 days on battery (will get a LOT better in V2 with more optimizations)
- Comes with a Web App to which you can add multiple furry fwends (friends)
- Is fully open-source and self-hostable.
A lot of work went into the software part, from integrating the web-services to optimizing every mA draw from the chip. I can't really demonstrate it 'step-by-step' but I tried documenting my thought process in the steps with hand drawn illustrations. I hope you enjoy that part of the Instructable, if you have feedback I'd appreciate it!
I want to give a shout out to HeatSync Labs, they are a non-profit Makerspace located in Mesa AZ and have been an essential place for me to go build my projects at. If you are in Tempe Arizona, you should check them out!
Finally, here is a demo video that shows off the highlights, I have a detailed build video later in the steps.
Supplies
Following are the materials we need for this project.
Electronics:
- A9G - GPS / GSM board 12 USD
- USB-TTL converter (5V worked for me). 9 USD
- Lithium Ion Battery 10 USD
- SIM Card Free*
- Raspberry Pi or any Linux SBC 40 USD
- TP-4056 Battery Charger
I realize the Pi supply is a bit shaky at the moment, I had to use my old Raspi 3 and it worked fine. You may opt for that or a similar one. This is to build our own server, if you are okay with paying a small fee ($6/mo), you can also choose to use a VPS (Virtual Private Server) like DigitalOcean.
Hardware:
- Brass sheets
- Solder equipment (A hot plate or hot air reflow gun works the best)
- Walnut wood sheet
- Basic wood tools
Step 1: Build Video
Here is a video of the whole hardware build.
As they say, a picture says a thousand words, and a video, 1001 ;)
Step 2: Early Drawings
I would like to share the early drawings of my thought process. Hopefully these give you some context.
Some design notes:
- I chose the overall form to be rectangular because it is the most efficient way to use the space since all other components are rectangular.
- I was really wrong about the GPS antenna being a patch on the top, and I will describe what happened / what I misunderstood about antennas in a future step (The Antenna Experiment)
- Since I am a Maker with limited resources (assuming you as well, dear reader) I notice that my designs are driven by what components are available, however that being said, I try to put that aside when sketching / drawing concept ideas.
Step 3: Overall CAD Design
After sketching some ideas out I designed the wearable in Shapr3d CAD design software. I like starting there so I can get a feel of the dimensions and other physical properties like placement of the hardware and PCB boards.
The iPad is a super clutch tool to use while designing, I was able to use the AR mode in Shapr3D to view how the device would fit on my cat, Pumpkin :)
Attachments to the step:
- CAD file (.shapr)
- 2D Drawings (1:1 scale) [Top + Bottom.pdf, Middle Chassis.pdf]
Step 4: The Find My Cat Algorithm
A little bit about my Python code and how it communicates to the servers. I implemented a two threaded program. Each thread handle part of the responsibility.
The first thread is an infinite loop that checks for any messages from the MQTT server, with an appropriate message you can switch the device from "IDLE" mode to "ACTIVELY_TRACKING"
In the IDLE mode, the device stays in low power mode by switching off all peripherals and slowing the CPU clock speed. When the ACTIVELY_TRACKING mode is enabled, the device reports it's location to the Traccar GPS Server every 10 seconds.
Any interruption in network is handled by catching the exception and restarting the process. We also have a watchdog timer set for 30 seconds, it means if the device freezes / becomes unresponsive, it will reset itself to restart the threads. This ensures that the device keeps trying to report it's location until it's instructed to do otherwise.
Step 5: Prepare the Bottom Brass (Chassis: 1)
We start off by cutting off the top and bottom cover of the box using the PDF template attached in the previous step (Overall CAD design)
1) Print the template in 1:1 scale setting, this is important so you keep the dimensions correct.
2) Glue the template onto the brass sheet. I used some cheap envelope glue to stick the template onto the brass. This let the template stay onto the brass pretty secure while I need to cut it, but also could peel off the glue when I was done, with little residue.
💡 Tip: If you use the existing edges of the brass, you only end up needing to cut around 2 edges. Makes it simpler.
Step 6: 🪚 Cut the Bottom (Chassis: 2)
We gently just saw away at the brass. I used a jewelry saw to get precision cuts, I find it to be much precise. The edges might be a little rough but we will smooth them out in the next step.
You do have to spend a bunch of time and the blade breaks a lot given how fragile it is. I broke about 7 blades 😂 I think it's worth since it's only one piece that you have to cut.
Step 7: Smooth Edges and Round Corners
Time to de-burr the edges to get it all nice and smooth. I use the bench sander to get a nice edge. This compensates for any irregular edges from the jewelry saw.
💡 To give it a final smooth touch I used a sand paper and just ran the edge over it, just gets it to the finish line.
Step 8: Make the Sides of the Chassis
For the sides of the chassis, I am using 12.5 mm wide (0.5 inch) brass strip. The plan is to fold the strip into what becomes the walls of the body.
First I found a rod that matches the diameter of the fillet curvature and used it to bend the corners at 90 deg. Pictures will probably describe it best.
Step 9: Prepare the Side + Bottom
This was the tricky part, I didn't realize how hard it is to bend corners and still have it match the bottom edges, in my case I kept having extra length, thus making the edges not line up with the walls.
I tried a bunch but the best solution was to cut the sides into 4 "Corners" (see illustrations above) and then sand off the extra material length until they line up. I was able to get this method working and looking seamless.
If you are able to bend the strip to match the exact dimensions, please leave your trick in the comments and you can skip this step!
Step 10: Solder the 4 Sides to the Bottom
Using a heat plate I warmed up the brass pieces to the appropriate temperature and soldering the rest was relatively easy.
💡 Some tips for this step:
- Use a sandpaper to remove any oxidation layer from the brass and then wipe it with alcohol to remove any oils
- Apply solder flux to the area where you are soldering. This will make it really to solder. Else it gets really sticky and weird.
- You will need steady hands, try not to topple the side, it's sitting on the edge, literally.
✨ What I wish I did different:
I wish I used a different method to solder this, a local heat source instead of heating up the whole plate. This way i wouldn't need to worry about knocking off the other sides while soldering.
Step 11: Solder the Nuts to the Chassis
Oh the tricky part!
We need to solder the nuts to the brass casing we're building. This will let us screw on the top cover later when we build it. I used a brass template I cut out earlier to help align the nuts with the holes. I used a hot air gun to get the precise concentrated heat.
💡 just like previous steps, make sure to get the oxidation and oil residue off before applying the solder flux.
Step 12: Clean Up the Case
Using a wire brush attachment on the dremel, clean up the solder paste residue and the oxidation caused by heat on the brass.
💡 I'd recommend that you stick to the higher grit sand paper for the sanding, I made the mistake of using too coarse of a grit and ended up creating a lot of "scratches" that I had to buff off with more fine sandpaper (:
Step 13: Build the Top Out of Walnut
I use the CAD file pdf (see step 2: Overall CAD design) to cut the Top out of walnut.
Step 14: Make the Inlay for GPS Antenna
To make the GPS antenna, I chose to build a dipole antenna out of the brass sheet. I found a metal chopper to cut a small 3mm wide rectangular piece of brass "wire".
Using a chisel and a sharp knife works pretty well for making the groove for the inlay, just score the walnut about 1 mm deep and use the chisel to break the material free.
Then once you do that, just lay the wire inside the groove and glue it.
Finally, trim the ends to make the antenna flush with the top case.
Step 15: The Antenna Experiment
The design goals for this project are the follows, they are pretty non-negotiable:
- Small form factor
- Long battery life
- Reliable GPS / GNSS transmission / reception.
I couldn't use the commercial antenna that shipped with the module (ceramic patch antenna) for the following reasons:
- The size of the antenna is too big for my wearable build. (design goal #1)
- The antennas are active antennas and hence consume power, I was trying to optimize every mA drawn. (design goal #2)
I decided to make my own GPS antenna, i've done this before in my With U shoe GPS project so I didn't think it would be that hard, but I was wrong, slightly :)
The first design I tried building was a patch antenna. I figured it'd be enough to make it work. But upon plugging it all in I got really poor reception, I could not understand why. After doing a lot of research on RF / Antennas I learned the following lesson. It's probably RF-Enginnering 101 Lecture 0, but, here we are.
Metals do not allow RF (radio frequency) signals to pass.
My first design was like this:
The patch was basically trapped inside a Faraday cage, hence no reception.
After learning that, I thought I could put the patch outside the metal box. But there is a little problem with this strategy: if I wanted to use any commonly available dielectrics for the patch antenna, i'd need the patch to be around 60 mm x 60 mm ~
This would not work for my small form factor design goal.
Doing some research on different types of antennas I found out that there are two other options that could work for my small factor:
- The Dipole Antenna
- InF (Inverted F antenna)
I chose the Dipole antenna, it was simple to build and surprisingly fast fix + accuracy.
The end result looked like this:
Step 16: Let's Understand the Software Upload Part
There are couple components to the software portion of the Find My Cat,
- Setup Coolwatcher tool (this is what will help burn SDK onto Micropython in step 2)
- Burn MicroPython SDK onto A9G chip
- Build the Traccar GPS server onto Raspberry Pi (or host of your choice)
- Upload the Find My Cat python code (written by me) onto the A9G chip
In the upcoming steps I will go into details of what each of the above steps entail.
Step 17: Why Micropython?
A9G module runs C/C++ on their SDK by default. I first started trying to implement this project in C/C++ in their choice of SDK. They have a couple examples on their github but nothing really resulted into much progress.
I ran into the following issues:
- Extreme lack of documentation of the A9G API's, nothing was really clear to me. This could be due to my lack of trying hard enough, but regardless I was demotivated really fast.
- C/C++ was way to verbose and needed too much thought about the implementation specifics, I want to be able to spend time on optimizing and developing features not debug pointer issues.
- The firmware documentation for the burner tool that A9G manufacturers recommend, is non-existent. It was a hit or miss with them, I am quite lucky I was able to finally figure it all out.
And so for the above reasons, I chose to burn the MicroPython SDK onto the A9G. This made it very (i mean very) easy to write and upload code to it after burning the firmware. The trickiest part was to burn the micropython firmware in to the chip.
In the next step, I will describe the steps that worked for me, re: burning the micro python SDK.
Step 18: Setup Coolwatcher
This was a bit of a challenge on it's own. The issue is that the software is old and unmaintained, this makes it have conflicts with new packages and in some cases it uses old packages that do not support the new OS.
Through a lot of trial and error I have found that the following steps worked for me:
- Setup Ubuntu 18.04 onto a separate computer. I recommend use a completely different machine because you may need to wipe the system and try again, better to do it on a low risk machine. I used a UP board to run my Ubuntu.
- Follow these setup instructions to install the dependencies that the Burn Tool (Coolwatcher) will need.
- Follow the Burn instructions to setup the connection from A9G hardware to the Coolwatcher.
- Do a test connection, run the tracer and just make sure that the device is in communication with the host computer.
💡 unfortunately, this step was the most complicated one for me, not because of the inherent difficulty but because of the poor documentation and outdated code. The manufacturer company seems to have abandoned this project, I think it's unfortunate because this chip has a lot of potential and that's what kept me going regardless.
🖊️ Please note, the download links for the CSDTK4.2 Linux is broken in the official A9G project, here is the github release that has a working download link:
Link: https://github.com/ZakKemble/GPRS_C_SDK/releases/tag/v2.129
Step 19: Connect A9G to the Coolwatcher
Using the USB-TTL connector, wire it up as shown in the picture above.
Note: the RX and TX go to HST_TX and HST_RX on the A9G, this is only during programming the firmware. Rest of the tutorial will use the RX/TX on A9G.
Step 20: Burn Micropython SDK Onto A9G
Hopefully the previous step we set up coolwatcher wasn't too bad for you and that you have A9G connected and talking to your host computer. The next step is really simple.
- Get the Micropython firmware file for A9G (it's a .lod extension)
- Correctly load the firmware into the burn tool
- Burn! 🔥
The link to the official MicroPython/A9G port is here: https://github.com/pulkin/micropython/tree/master/ports/gprs_a9
Get your (.lod) firmware file here: https://github.com/pulkin/micropython/releases/tag/latest-build
Step 21: Test the MicroPython on A9G
Let's do a quick test of the firmware we just installed!
You can connect to the A9G board via your normal computer by following these commands.
- Using pyserial do the following: miniterm.py /dev/ttyUSB1 115200 --raw
- This should open up a python shell that is running on the A9G!
You should be able to use the Python shell (REPL), try printing "hello world"! (print("hello world"))
Step 22: Setup Traccar Server Onto Raspberry Pi
I wanted to minimize the recurring costs for this project so I chose to host a server of my own using Raspberry Pi.
The idea is simple:
- Install Ubuntu Server 20.04 on Raspberry Pi. We choose the server image because we don't want the overhead of the GUI consuming resources on the Pi.
- Using your Personal computer, SSH into the Raspberry Pi.
- Install Traccar GPS Server on the Pi.
- Download the Linux ARM binary here: https://www.traccar.org/download/
- Follow the installation instructions here: https://www.traccar.org/linux/
- IF you run into a Java issue, this helped me: https://www.traccar.org/forums/topic/installing-traccar-server-on-raspberry-pi-rasperian/
- Install ngrok on the Raspberry Pi, we use this to expose the ports of the Traccar Server over the internet.
- Add the following contents to your ngrok config file (~/.config/ngrok/ngrok.yml). The NGROK_ACCESS_TOKEN is obtained from your ngrok dashboard.
- Launch a tmux session by typing tmux in the cmd line. Install it if you don't have it installed.
- From the session, do ngork start --all. This will start forwarding both the tunnels. (https and tcp as defined in the config file)
- Copy the two URLs that the ngrok session displays, we'll use this in our Python code next. (see images for better clarification). They look like these:
- https://0000-00-0-000-000.ngrok.io/
- 0.tcp.ngrok.io:PORT
---
ngrok config file contents:
version: "2"
authtoken: <NGROK_ACCESS_TOKEN>
tunnels:
ui:
proto: http
addr: 8082
schemes: [http]
database:
proto: tcp
addr: 5055
image pointing out the URLs:
Step 23: Install the Custom Find My Cat Web UI Server on Raspberry Pi
I built the UI based off of Traccar Server modern UI, making it more personalized to the Find My Cat project, I downloaded the source and made some changes. They can be summarized as follows
- Added MQTT communication protocol for talking to the A9G (This auto-connects upon web app load and disconnects when you exit)
- Changed the UI layout / styling to match my taste. (minimal and purpose focused)
Install it onto the Raspberry Pi server by doing the following:
- Download this build folder from the github repository.
- Copy the contents to "~" (home) directory of Raspberry Pi. (you can do this over ssh using the scp command)
- scp -r path/to/build/ ubuntu@<your_pi_IP_address>:~
- Point the nginx server to serve this build folder. This is done by modifying the nginx config file. You can just use my config file since it also has the API path settings.
- Copy these contents into /etc/nginx/sides-available/default
- Start the nginx server by doing: systemctl reload nginx
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##
# Find My Cat Nginx server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server;
root /home/ubuntu/build;
location /api/socket {
proxy_pass "http://127.0.0.1:8082";
proxy_set_header Host $host;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /api {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_pass "http://127.0.0.1:8082";
}
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
}
Step 24: Upload the Find My Cat Algorithm Onto the A9G
Time to bake in the Find my Cat algorithm onto the A9G chip!
There are 3 files:
- run.py
- A9G.py
- blink.py
1) upload the run.py as follows:
ampy --port /dev/tty.usbserial-0001 put run.py main.py
2) upload the rest of the files as follows:
>>> ampy --port /dev/tty.usbserial-0001 put A9G.py
>>> ampy --port /dev/tty.usbserial-0001 put blink.py
💡 Please make sure that you update the network ports to use correct ones for your server. They are the following variables in the run.py:
# TCP config
port = xxxxx
tcp_host = 'x.tcp.ngrok.io'
Also update the MQTT config: (can be any topic of your choice on the free hive mqtt server)
# MQTT configuration
device_name = "A9G"
mqtt_server_domain = "broker.hivemq.com"
mqtt_topic = "your-topic-name"
If you end up using a different SIM card provider than hologram, remember to replace this to your correct APN.
APN = "hologram"
Step 25: Add the Power Switch
Drill a hole that is appropriate for the size of the tactile switch you're using, and then either glue / solder the switch on the case.
Step 26: Make Space for the Charger Port
Some more metal-working here, using the drill press I drilled out the material to make space for the charger port.
Once the holes were drilled, I used a small metal file to get the port to get it precisely close to fit the charger port.
Step 27: Put It All Together!
Avengers assemble! 💥
Step 28: Open Up Your Web-App
Register your account and add the device to the UI, you should be able to see the live location of your device ! 👏
💡 When registering multiple devices (if you decide to make more than one of these) make sure you use a unique device identifier.
Step 29: Find Your Cat :)
That is it my friends. I hope you find this useful, there were a lot of learnings in the project that I hope documenting here would be of use to someone trying to make it themselves or even for people who are building similar things.
I try to generalize my steps so I communicate the thought process instead of a recipe only document. I'd like to encourage more of a problem solving mindset :)
Happy building!
PS: Enjoy some pictures of my cat, Pumpkin! 🎃
Grand Prize in the
Anything Goes Contest
37 Comments
Question 7 months ago on Introduction
Are you going to go public with this, or was it just for your own needs? ..You're right about what's out there in pet tracking... Sadly, too late for me and Maxi... I wish I could have had your tracker last year...
Answer 6 weeks ago
if Maxi died, i would never talk again. i love all cats
6 weeks ago
JUST WHAT I NEED!!!
my siamese lily goes out for days if she gets out the door!
and ever since i got her, i've been dreaming about something
like this
7 weeks ago
Since the A9G must send it's data over SOME cellular network, I assume there is
some kind of monthly fee to have a SIM card and an account.
What is the Monthy Fee you have to pay to activate/operate the A9G" GSM/GPS module?
Question 2 months ago
I really love the project!
Any updates on Version 2?
Is there still a plan to make one or are you already working on it?
7 months ago
I wish there was a way to communicate with your kitty while he/she is wearing a tracker.. In real time, you could see a dangerous enemy, like a raccoon or coyote, and yell or scream at that danger through an audio select button in the app that would come with the tracker. .. in a perfect world
7 months ago on Step 9
In steps 8/9 maybe you could cut a piece of wood the size/shape of your back with a width matching your brass (1/2") and bend the brass strip around that. There'd be some spring back but I think It would get you close and you could keep the edge flat on a table.
8 months ago
This is an awesome build, can be used to track anything. Car, boat, bicycle or even kids :)
Reply 8 months ago
Right on :)
8 months ago
Awesome job putting it all together!! I'd like to buy you a drink and pick your brain sometime on some other projects along this same line. I live in Mesa and frequent Heatsync once in awhile.
Reply 8 months ago
Thank you @KelHelmick! I just sent you a message :)
8 months ago
Nice writeup. I'll be looking forward to an update that uses 4G LTE as 2G and 3G are no longer available in the US.
Reply 8 months ago
Yup, stay tuned ;)
8 months ago
Congrats for completing this challenge! A few years ago I was working on this as well but I gave up. To my defense I must say that my requirements were a lot stricter: much smaller device, battery life time at least 9months. I wanted to use LoRaWAN as communication channel.
In the meantime we saw interesting developments in key technology areas.
A guy from Berlin apparently now has a working prototype of the device I had wanted to build and 8k preorders: https://katzentracker.com/.
Reply 8 months ago
That is a very cool product!
8 months ago
I had a similar problem when my roamer cat turned up missing. He died from eating a poisoned mouse. I bought an expensive pet Locator but it required hard to find batteries every month. I was planning on building a GPS locator but my wife suggested putting an Air Tag on the collar of our current roamer.
Reply 8 months ago
Sorry to hear that :(
I am building a V2 that would be way better at battery life.
Airtags are great when there are iPhones around, else they are a bit tough to get location from frequently.
Reply 8 months ago
Too true, it was a quick fix because my wife was desperate and worried. The cat in question had been missing for 3 days (locked in the neighbors garage eating all the mice). She just stuck an air tag on the cats collar. I wanted to build a real GPS tracker. I helped develop the original GPS satellites as a targeting system for nuclear ballistic weapons (submarine launched). It was called Fleet Satellite Communications (Fle-Sat-Com in military jargon).
Reply 8 months ago
Your background in GPS systems is really cool @Atilla De Hunn! I'll reach out to you for V2 if you wouldn't mind :)
8 months ago
This is awesome, thank you so much!