Can you help me fix the issue in this code as it is just generating invalid coordinates for me and I cant figure out why?
//include <SoftwareSerial.h>
#define gpsSerial Serial1
#include <TinyGPSPlus.h>
#include "thingProperties.h"
TinyGPSPlus gps;
void setup(){
Serial.begin(115200);
gpsSerial.begin(9600);
Serial.println("Test GPS");
delay(1500);
//initProperties();
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
delay(1500);
while (gpsSerial.available()){
if (gps.encode(gpsSerial.read())) {
displayInfo();
}
}
if (millis() > 5000 && gps.charsProcessed() < 10) {
Serial.println("No GPS detected: check wiring.");
Serial.print(gps.location.isValid());
while(true);
}
}
void displayInfo() {
float longitude = 0;
float latitide = 0;
Serial.print(F("Location: "));
if (gps.location.isValid()) {
Serial.print(gps.location.lat(), 6);
Serial.print(",");
Serial.print(gps.location.lng(), 6);
latitide = gps.location.lat();
longitude = gps.location.lng();
mapString = String(latitide,6) + "," + String(longitude,6) ;
coordinates = {latitide, longitude};
Serial.println(mapString);
} else {
Serial.print("INVALID COORDINATES");
mapString = "INVALID COORDINATES" ;
}
Serial.print("Date/Time : ") ;
if (gps.date.isValid()) {
Serial.print(gps.date.month());
Serial.print("/");
Serial.print(gps.date.day());
Serial.print("/");
Serial.print(gps.date.year());
} else {
Serial.print("INVALID");
}
Serial.print("") ;
if (gps.time.isValid()){
if (gps.time.hour() < 10) Serial.print('0') ;
Serial.print(gps.time.hour());
Serial.print(":") ;
if (gps.time.minute() < 10) Serial.print('0') ;
Serial.print(gps.time.minute());
Serial.print(":") ;
if (gps.time.second() < 10) Serial.print('0');
Serial.print(gps.time.second());
Serial.print(":") ;
if (gps.time.centisecond() < 10) Serial.print('0');
Serial.print(gps.time.centisecond());
}else{
Serial.print("INVALID");
}
Serial.println();
}
void onGpsChange() {
// Add your code here to act upon Gps change
}
void onMapStringChange() {
// Add your code here to act upon MapString change
}
void onCoordinatesChange() {
// Add your code here to act upon Coordinates change
}