clairiereriom
Published © CC BY

Project Turtle

The goal is to create an app to track my turtle's location whether I'm home or not.

AdvancedWork in progress1,466
Project Turtle

Things used in this project

Hardware components

Arduino Nano 33 IoT
Arduino Nano 33 IoT
×1
GPS Module (Generic)
×1

Story

Read more

Schematics

Schematics

Code

Emitter Software

Arduino
#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_HERE";


StaticJsonDocument<200> doc;
char ssid[] = "YOUR_SSID";
char pass[] = "YOUR_PASS";
int status = WL_IDLE_STATUS ;

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);
  }



}

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("/api" , "application/json" , JSON_ARRAY );
  Serial.println(HTTP.responseStatusCode());
  Serial.println(HTTP.responseBody());
  Serial.println("===============================================");
 



  delay(180000);
}

}

Credits

clairiereriom
0 projects • 2 followers
Contact

Comments

Please log in or sign up to comment.