21.ESP32 with GPS module

/*
 * This ESP32 code is created by esp32io.com
 *
 * This ESP32 code is released in the public domain
 *
 * For more detail (instruction and wiring diagram), visit https://esp32io.com/tutorials/esp32-gps
 */

#include <TinyGPS++.h>

#define GPS_BAUDRATE 9600  // The default baudrate of NEO-6M is 9600

TinyGPSPlus gps;  // the TinyGPS++ object

void setup() {
  Serial.begin(9600);
  Serial2.begin(GPS_BAUDRATE);

  Serial.println(F("ESP32 - GPS module"));
}

void loop() {
  if (Serial2.available() > 0) {
    if (gps.encode(Serial2.read())) {
      if (gps.location.isValid()) {
        Serial.print(F("- latitude: "));
        Serial.println(gps.location.lat());

        Serial.print(F("- longitude: "));
        Serial.println(gps.location.lng());

        Serial.print(F("- altitude: "));
        if (gps.altitude.isValid())
          Serial.println(gps.altitude.meters());
        else
          Serial.println(F("INVALID"));
      } else {
        Serial.println(F("- location: INVALID"));
      }

      Serial.print(F("- speed: "));
      if (gps.speed.isValid()) {
        Serial.print(gps.speed.kmph());
        Serial.println(F(" km/h"));
      } else {
        Serial.println(F("INVALID"));
      }

      Serial.print(F("- GPS date&time: "));
      if (gps.date.isValid() && gps.time.isValid()) {
        Serial.print(gps.date.year());
        Serial.print(F("-"));
        Serial.print(gps.date.month());
        Serial.print(F("-"));
        Serial.print(gps.date.day());
        Serial.print(F(" "));
        Serial.print(gps.time.hour());
        Serial.print(F(":"));
        Serial.print(gps.time.minute());
        Serial.print(F(":"));
        Serial.println(gps.time.second());
      } else {
        Serial.println(F("INVALID"));
      }

      Serial.println();
    }
  }

  if (millis() > 5000 && gps.charsProcessed() < 10)
    Serial.println(F("No GPS data received: check wiring"));
}
/*
 * This ESP32 code is created by esp32io.com
 *
 * This ESP32 code is released in the public domain
 *
 * For more detail (instruction and wiring diagram), visit https://esp32io.com/tutorials/esp32-gps
 */

#include <TinyGPS++.h>

#define GPS_BAUDRATE 9600  // The default baudrate of NEO-6M is 9600

TinyGPSPlus gps;  // the TinyGPS++ object

const double LONDON_LAT = 51.508131;
const double LONDON_LON = -0.128002;

void setup() {
  Serial.begin(9600);
  Serial2.begin(GPS_BAUDRATE);

  Serial.println(F("ESP32 - GPS module"));
}

void loop() {
  if (Serial2.available() > 0) {
    if (gps.encode(Serial2.read())) {
      if (gps.location.isValid()) {
        double latitude = gps.location.lat();
        double longitude = gps.location.lng();
        unsigned long distanceKm = TinyGPSPlus::distanceBetween(latitude, longitude, LONDON_LAT, LONDON_LON) / 1000;

        Serial.print(F("- latitude: "));
        Serial.println(latitude);

        Serial.print(F("- longitude: "));
        Serial.println(longitude);

        Serial.print(F("- distance to London: "));
        Serial.println(distanceKm);
      } else {
        Serial.println(F("- location: INVALID"));
      }

      Serial.println();
    }
  }

  if (millis() > 5000 && gps.charsProcessed() < 10)
    Serial.println(F("No GPS data received: check wiring"));
}

GPS module with Appscript (https://github.com/ahmadlogs/esp32/tree/main/google-sheet-gps)

var ss = SpreadsheetApp.openById('ENTER_SHEET_ID');
var sheet = ss.getSheetByName('Sheet1');


function doGet(e){

  if (e.parameter == 'undefined') {
    return ContentService.createTextOutput("Received data is undefined");
  }

  var dateTime = new Date();
  latitude    = e.parameters.latitude;
  longitude   = e.parameters.longitude;
  speed       = e.parameters.speed;
  satellites  = e.parameters.satellites;
  altitude    = e.parameters.altitude;
  gps_time    = e.parameters.gps_time;
  gps_date    = e.parameters.gps_date;
  //Logger.log('latitude=' + latitude);

  var nextRow = sheet.getLastRow() + 1;
  sheet.getRange("A" + nextRow).setValue(dateTime);
  sheet.getRange("B" + nextRow).setValue(latitude);
  sheet.getRange("C" + nextRow).setValue(longitude);
  sheet.getRange("D" + nextRow).setValue(speed);
  sheet.getRange("E" + nextRow).setValue(satellites);
  sheet.getRange("F" + nextRow).setValue(altitude);
  sheet.getRange("G" + nextRow).setValue(gps_time);
  sheet.getRange("H" + nextRow).setValue(gps_date);

  //returns response back to ESP32
  return ContentService.createTextOutput("Status Updated in Google Sheet");

}


function doPost(e) {
  var val = e.parameter.value;
  
  if (e.parameter.value !== undefined){
    var range = sheet.getRange('A2');
    range.setValue(val);
  }
}
#include <WiFi.h>
#include <HTTPClient.h>

#include <TinyGPS++.h>
TinyGPSPlus gps;

#define RXD2 16
#define TXD2 17
HardwareSerial neogps(1);

const char * ssid = "ENTER_YOUR_WIFI_SSID";
const char * password = "ENTER_YOUR_WIFI_PASSWORD";
String GOOGLE_SCRIPT_ID = "ENTER_GOOGLE_DEPLOYMENT_ID";

const int sendInterval = 2000;


 void setup() {
    Serial.begin(115200);

  neogps.begin(9600, SERIAL_8N1, RXD2, TXD2);
  delay(10);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);

  Serial.print("Connecting to Wi-Fi");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("OK");
}

void loop() {
    
  boolean newData = false;
  for (unsigned long start = millis(); millis() - start < 1000;)
  {
    while (neogps.available())
    {
      if (gps.encode(neogps.read()))
        {newData = true;}
    }
  }

  if(newData == true)
  {
    newData = false;
    Serial.println(gps.satellites.value());
    print_speed();
  }
  else
  {
    Serial.println("No new data is received.");
  }  

}

void print_speed()
{
  if (gps.location.isValid() == 1)
  {
    //String gps_speed = String(gps.speed.kmph());
    Serial.println(gps.location.lat(),7);
    Serial.println(gps.location.lng(),7);
    Serial.println(gps.speed.kmph());
    Serial.println(gps.satellites.value());
    Serial.println(gps.altitude.meters(), 0);

    String param;
    param  = "latitude="+String(gps.location.lat(), 7);
    param += "&longitude="+String(gps.location.lng(), 7);
    param += "&speed="+String(gps.speed.kmph());
    param += "&satellites="+String(gps.satellites.value());
    param += "&altitude="+String(gps.altitude.meters());
    param += "&gps_time="+String(gps.time.value());
    param += "&gps_date="+String(gps.date.value());

    Serial.println(param);
    write_to_google_sheet(param);
  }
  else
  {
    Serial.println("No any valid GPS data.");
  }  

}

void write_to_google_sheet(String params) {
   HTTPClient http;
   String url="https://script.google.com/macros/s/"+GOOGLE_SCRIPT_ID+"/exec?"+params;
   //Serial.print(url);
    Serial.println("Postring GPS data to Google Sheet");
    http.begin(url.c_str());
    http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
    int httpCode = http.GET();  
    Serial.print("HTTP Status Code: ");
    Serial.println(httpCode);
    String payload;
    if (httpCode > 0) {
        payload = http.getString();
        Serial.println("Payload: "+payload);     
    }
    http.end();
}