Differences

This shows you the differences between two versions of the page.

Link to this comparison view

iothings:proiecte:2022:pettracker [2023/01/19 23:47]
andrei.ursulean
iothings:proiecte:2022:pettracker [2023/01/20 11:26] (current)
andrei.ursulean [Pet Tracker Application]
Line 1: Line 1:
 ====== Pet Tracker Application ====== ====== Pet Tracker Application ======
 Student: Andrei Ursulean (ACES) Student: Andrei Ursulean (ACES)
 +
 +Code: https://​github.com/​andreiursulean/​pet_tracker
 ===== Project Description ===== ===== 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. 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.
 +
 +{{:​iothings:​proiecte:​2022:​pt_sys.jpeg?​700|}}
 +
 +Fig. 1 Pet tracker demonstrator (using the antenna from another SIM module because I broke the original antenna)
 ===== System Architecture ===== ===== 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. 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.
Line 15: Line 21:
  
 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. 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.
 +
 +{{:​iothings:​proiecte:​2022:​pt_config_web.png|}}
  
 Fig. 3 Configuration page Fig. 3 Configuration page
Line 29: Line 37:
  
 Fig. 5 Web Application Map Fig. 5 Web Application Map
 +
 +If the tracked target leaves the given geofence, an SMS alert is triggered.
 +
 +{{:​iothings:​proiecte:​2022:​pt_sms_alert.jpeg?​300|}}
  
 ===== Software development ===== ===== Software development =====
Line 40: Line 52:
   const char gprsUser[] = "";​   const char gprsUser[] = "";​
   const char gprsPass[] = "";​   const char gprsPass[] = "";​
 +The GPS receiver is included in the SIM7000G chip, therefore we use TinyGSM to get the location.
 +  modem.enableGPS();​
 +  delay(5000);​
 +  while (!modem.getGPS(lat,​ lon)) {
 +    Serial.println("​Couldn'​t get GPS location. Retrying in 2s");
 +    delay(2000);​
 +    ​
 +  }
 +  modem.disableGPS();​
 +  ​
 +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);​
  
 ===== Challenges ===== ===== Challenges =====
iothings/proiecte/2022/pettracker.1674164870.txt.gz · Last modified: 2023/01/19 23:47 by andrei.ursulean
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0