I made a code for GPS that provides coordinates, but the problem is when I disconnect antenna from GPS shield it still provides location instead the output "No GPS Data".
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
SoftwareSerial gpsSerial(2, 3);
TinyGPSPlus gps;
char lon[12]; // create variable for latitude and longitude object
char lati[12];
char text[160];
void setup() {
Serial.begin(9600);
gpsSerial.begin(9600);
}
void loop()
{
while(gpsSerial.available()>0)
{
char c = gpsSerial.read();
if (gps.encode(c))
{
if (gps.location.isValid())
{
dtostrf(gps.location.lat(), 1, 6, lati);
dtostrf(gps.location.lng(), 1, 6, lon);
strcat(text,lati);
strcat(text,",");
strcat(text,lon);
Serial.println(text);
delay (1000);
memset(text, 0, 160);
}
else
{
strcat(text,"No GPS Data");
Serial.println(text);
delay (1000);
memset(text, 0, 160);
}
}
}
}