Pet Tracker Application

Student: Andrei Ursulean (ACES)


Project Description

The project aims to offer pet owners a way to track their small pet (about the size of a cat or a dog) in real time from anywhere. Using this product, they are aware of the current location of the pet, they can see a history and they can receive SMS alerts when the pet leaves a designated area. The system uses mobile data via LTE and GPRS so it is not dependent on WiFi which is useful for owners that own a house and leave their pet to roam free, but it is also useful for owners that keep their pets only indoor for the cases when the pet can escape. The application requires a mobile data plan which can be bought for ~2 Euro or a data + SMS (~6 Euro) if users want SMS alerts.

Fig. 1 Pet tracker demonstrator (using the antenna from another SIM module because I broke the original antenna)

System Architecture

The hardware is based on a LilyGO-T-SIM7000G module which is composed of an ESP32-WROVER low power SoC with WiFi and Bluetooth, a SIM7000G chip which adds LTE, GPRS and GPS and a MicroSD card. The module also comes with a 18650 battery holder. The MCU communicates to the SIM/GPS module via asynchronous serial interface and with the SD card via SPI. With this board we can send SMS, get location and time using GPS, and connect it to the internet using a SIM card data plan. This board doesn’t support phone calls.

Fig. 1 LilyGO-T-SIM7000G pinout

Fig. 2 System Architecture

When the user first starts the application, the module creates a WiFi access point and the user must access the address of the tracker where it is presented with a web page. This is a configuration page where the user must input username and password, pet name, geofence definition and phone number for sms alerts. After that, the application runs as normal.

Fig. 3 Configuration page

Once the main application loop begins, the microcontroller calculates the GPS position, gets the current time, connects to the firebase database in order to publish data and logs to SD card. In case the user is not authenticated, it retrieves the authentication token from the server and then it writes the position and the timestamp information in the database.

Fig. 4 Software flowgraph

When a position update is received, it is displayed live on a map in the web application interface. In order to access the web application, a user account is required and each user can only see information from his pets.

Fig. 5 Web Application Map

If the tracked target leaves the given geofence, an SMS alert is triggered.

Software development

As previously mentioned, the application communicates with the SIM module using a UART interface on pins 26(TX) and 27(RX). Like most GSM modems, AT commands are used for controlling it. We can manually connect via serial to the modem and send AT commands, however, it is often considered practical to use a library and indeed, we have used the TinyGSM library which knows how to send AT commands and handle responses. First we must define a few constants for the library. We must use the SSL variant of the SIM7000G definition since Firebase only supports HTTPS requests.

#define TINY_GSM_RX_BUFFER 1024 // Set RX buffer to 1Kb

Also, we must configure the APN in order to access the mobile data plan. For our operator (Orange Romania) we use the following values:

const char apn[]  = "net";
const char gprsUser[] = "";
const char gprsPass[] = "";

The GPS receiver is included in the SIM7000G chip, therefore we use TinyGSM to get the location.

while (!modem.getGPS(lat, lon)) {
  Serial.println("Couldn't get GPS location. Retrying in 2s");

For internet requests we use the Arduino HttpClient over the TinyGsmClientSecure class.

TinyGsm modem(SerialAT);
TinyGsmClientSecure client(modem, 0);
HttpClient http_client(client, DATABASE_URL, SSL_PORT);

SMS messages are sent using TinyGsm library

bool res = modem.sendSMS(smsTarget, petName + String(" has left the geofence"));

For timing we could've used both GPS and GSM networks. Each GPS satellite contains multiple atomic clock so this offers us one of the most precise timing systems available. However, we opted for using the GSM timing since our application does not require very precise timing. It doesn't really matter if the pet was last seen 5 seconds ago or 0.0001 seconds ago and also, connecting to the GSM network is much faster compared to acquisition of GNSS signal (especially indoors where we had problems with getting a location fix.

modem.getNetworkTime(&year3, &month3, &day3, &hour3, &min3, &sec3, &timezone)

We use a struct tm and the mktime function to convert from date to Unix epoch time.

tm t = { 
  .tm_sec = sec3,
  .tm_min = min3,
  .tm_hour = hour3 - timezone,
  .tm_mday = day3,
  .tm_mon = month3 - 1,
  .tm_year = (year3 - 1900)      
time_t timestamp = mktime(&t);


The main challenge in this project was that the Firebase ESP 32 library was made to work only on WiFi while in this project we are using mobile data (WiFi is not feasible for pet tracking purposes). In order to overcome this problem, we have used the REST API exposed by Firebase in order to retrieve the authentication token and then to publish data to the database using the token. The requests must be performed over HTTPS since unsecured HTTP is not accepted by Firebase.


This project presents a demonstrator for a smart pet tracker. It has all the functionality, but it order to be used for a real pet the same components must be placed on a smaller PCB in order to avoid discomfort for the pet. Also, the GPS receiver is very weak for indoors positioning. This is not an issue for animals that can get lost outdoors, but it makes testing the prototype difficult.

Special thanks to Paul for giving me a GPS antenna. The demonstration would've been really compromised without the new antenna.


iothings/proiecte/2022/pettracker.txt · Last modified: 2023/01/20 11:26 by andrei.ursulean
CC Attribution-Share Alike 3.0 Unported Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0