gps now only sends when locationis valid
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user