gps now only sends when locationis valid

This commit is contained in:
unknown
2023-08-01 23:23:57 -04:00
parent 1e80ab8e89
commit e3659147b1
2 changed files with 197 additions and 11 deletions
+30 -11
View File
@@ -46,6 +46,8 @@ const unsigned char host[4] = { 192, 168, 1, 120 };
//const char* host = "xyz.xyz.xyz.xyz";
const uint16_t port = 1202;
int count = 0;
// Create an Instance of the TinyGPS++ object called gps
TinyGPSPlus gps;
// The serial connection to the GPS device
@@ -113,20 +115,37 @@ void loop() {
// This will send gps info
Serial.println("sending gps data");
if (client.connected()) {
// send data to server
client.print(gps.location.lat(), 5); // 5 decimals of precision
client.print(",");
client.println(gps.location.lng(), 5);
// print data to serial monitor
Serial.print(gps.location.lat(), 5); // 5 decimals of precision
Serial.print(",");
Serial.println(gps.location.lng(), 5);
switch( count ) {
case -1:
break;
case 0:
client.println("start");
Serial.println("start");
count++;
break;
case 15:
client.println("fin");
Serial.println("fin");
count = -1;
break;
default:
// send data to server
client.print(gps.location.lat(), 5); // 5 decimals of precision
client.print(",");
client.println(gps.location.lng(), 5);
// print data to serial monitor
Serial.print(gps.location.lat(), 5); // 5 decimals of precision
Serial.print(",");
Serial.println(gps.location.lng(), 5);
count++;
break;
}
}
// Close the connection
Serial.println();
Serial.println("closing connection");
client.stop();
//Serial.println();
//Serial.println("closing connection");
//client.stop();
// don't get data continuously, wait one second
delay(1000);