My turtle is used to disappearing and hiding in different places around my yard. Since we're not always monitoring its position, I decided to create a react-native app to monitor its position on a map from anywhere in the world.
AppI first started working on the frontend of the app as it has to be pleasing for users to use and really intuitive to find the turtle. I already developed a few projects using react-native that's why I decided to go with its simplicity and scalability across multiple range of devices.
For this app I first started to design a simple UI on Adobe XD to get to work as soon as possible. I already had some design ideas in mind as making the whole app background as a map and a small dock at the bottom to display information such as the last location coordinates and the time referring to these coordinates.
Here is what the final product looks like once it was completely designed and developed.
After building the entire project I realized that it was easier to interpret the location on a satellite map. Here is the final product.
Once the frontend was working and displaying fake coordinates. I started working on the database structure. I also started to look up for free database hosting that allows a minimal response time for each request. I settled on using mongodb and hosting at clever cloud. Once all of this was correctly set up I started working on the API.
ApiMy database was correctly working and I was able to retrieve and post data from the mongodb compass GUI. I then started implementing the ability to get and post data to my database from the API.
ArduinoTo conclude this project I had to connect my GPS module to my arduino and then extract both the latitude and the longitude to then upload it to my server thanks to a wifi connection and HTTP requests.
First thing first, let's add the libraries and declare all the variable we are going to need later.
#include <ArduinoJson.h>
#include<ArduinoHttpClient.h>
#include <SPI.h>
#include <WiFiNINA.h>
#include <Bridge.h>
#include <BridgeHttpClient.h>
#include "TinyGPS++.h"
TinyGPSPlus gps;
WiFiClient client;
char server [] = "YOUR_API_SERVER_NAME";
StaticJsonDocument<200> doc;
char ssid[] = "YOUR_SSID";
char pass[] = "YOUR_PASS";
int status = WL_IDLE_STATUS ;
Next let's setup the wifi connection and both Serial ports of the arduino nano IOT 33.
void setup() {
Serial.begin(9600);
Serial1.begin(9600);
while (status != WL_CONNECTED) {
status = WiFi.begin(ssid , pass);
if (status == WL_CONNECTED) {
Serial.print("You are connected to ");
Serial.print(ssid);
Serial.println(" ");
}
delay(10000);
}
}
Finally let's see if we're getting data from the GPS using tinyGPS++. If we are receiving data let's interpret the NMEA sentence to extract a longitude and a latitude. As soon as this data is extracted let's create a new HTTP POST request and transform the longitude and latitude to JSON. That's it your Arduino GPS tracker is finally uploading data to your server. Your client (IOS & Android APP ) can interpret this data and display it on a map.
void loop() {
if(Serial1.available()){
gps.encode(Serial1.read());
}
if(gps.location.isUpdated()){
Serial.println(gps.location.lat());
double lat = gps.location.lat();
double lng = gps.location.lng();
doc["latitude"] = lat;
doc["longitude"] = lng;
String JSON;
serializeJson(doc , JSON);
Serial.println(JSON);
char JSON_ARRAY [JSON.length() + 1];
strcpy(JSON_ARRAY , JSON.c_str());
HttpClient HTTP = HttpClient(client, server , 80);
Serial.println("Sending request");
HTTP.post("/index.php" , "application/json" , JSON_ARRAY );
Serial.println(HTTP.responseStatusCode());
Serial.println(HTTP.responseBody());
Serial.println("===============================================");
delay(180000);
}
}
Comments
Please log in or sign up to comment.