/************************************************************************************
* Created By: Tauseef Ahmad
* Created On: 10 November, 2021
*
* YouTube Video:
* My Channel: https://www.youtube.com/channel/UCOXYfOHgu-C-UfGyDcu5sYw/
*
* *********************************************************************************
* Preferences--> Aditional boards Manager URLs :
* For ESP32:
* https://dl.espressif.com/dl/package_esp32_index.json
*
* *********************************************************************************
* Download Blynk Library (Version 1.0.1):
* https://github.com/blynkkk/blynk-library
* *********************************************************************************
* Download TinyGPS++ Library (Version 1.0.2b):
* https://github.com/mikalhart/TinyGPSPlus
**********************************************************************************/
//------------------------------------------------------------------------------
// Template ID, Device Name and Auth Token are provided by the Blynk.Cloud
// See the Device Info tab, or Template settings
#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPL6FKlP6QUm"
#define BLYNK_TEMPLATE_NAME "GPS System"
#define BLYNK_AUTH_TOKEN "BFQJDYy-ByTAsQHuNdAtizYXKa0K-Rih"
//------------------------------------------------------------------------------
char auth[] = "BFQJDYy-ByTAsQHuNdAtizYXKa0K-Rih";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "HONOR 20 Lite";
char pass[] = "1234567890";
//------------------------------------------------------------------------------
// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial
//------------------------------------------------------------------------------
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
//------------------------------------------------------------------------------
#include <SoftwareSerial.h>
#define BLYNK_PRINT Serial
//Install the following Libraries
#include <TinyGPS++.h>
//GPS RX to D1 & GPS TX to D2 and Serial Connection
const int RXPin = 17, TXPin = 16;
const uint32_t GPSBaud = 9600;
SoftwareSerial gps_module(RXPin, TXPin);
TinyGPSPlus gps;
WidgetMap myMap(V0); //V0 - virtual pin for Map
BlynkTimer timer;
//Variable to store the speed, no. of satellites, direction
float gps_speed;
float no_of_satellites;
String satellite_orientation;
//unsigned int move_index;
unsigned int move_index = 1;
void setup()
{
Serial.begin(115200);
Serial.println();
gps_module.begin(GPSBaud);
Blynk.begin(auth, ssid, pass);
timer.setInterval(5000L, checkGPS);
}
void checkGPS(){
if (gps.charsProcessed() < 10)
{
Serial.println(F("No GPS detected: check wiring."));
Blynk.virtualWrite(V0, "GPS ERROR");
}
}
void loop()
{
while (gps_module.available() > 0)
{
//displays information every time a new sentence is correctly encoded.
if (gps.encode(gps_module.read()))
displayInfo();
}
Blynk.run();
timer.run();
}
void displayInfo()
{
if (gps.location.isValid())
{
//Storing the Latitude. and Longitude
float latitude = (gps.location.lat());
float longitude = (gps.location.lng());
//Send to Serial Monitor for Debugging
Serial.print("LAT: ");
Serial.println(latitude, 6); // float to x decimal places
Serial.print("LONG: ");
Serial.println(longitude, 6);
Blynk.virtualWrite(V1, String(latitude, 6));
Blynk.virtualWrite(V2, String(longitude, 6));
Blynk.virtualWrite(V4, longitude, latitude);
//get speed
gps_speed = gps.speed.kmph();
Blynk.virtualWrite(V3, gps_speed);
}
Serial.println();
}