Find My Cat -- the GPS Tracker for Pets
by Chitlange Sahas in Circuits > Wearables
21240 Views, 242 Favorites, 0 Comments
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
Build Video
Here is a video of the whole hardware build.
As they say, a picture says a thousand words, and a video, 1001 ;)
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.
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]
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.
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.
🪚 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.
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.
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.
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!
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.
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.
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 (:
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.
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.
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:
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.
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.
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
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.
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
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"))
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:
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;
}
}
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"
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.
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.
Put It All Together!
Avengers assemble! 💥
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.
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! 🎃