Hello, i am working on a project where i use module GSM and module GPS. I have a problem, i dont know why but when i try to use the location from the GSM, the GPS never works, it has to be a problem from the code i believe. If i only put the if(gps.location.isValid()) {..rest of the code..}, the code works fine but when i implement the if(!gps.location.isValid() && millis() > 5000){...rest of the code...} the GPS isnt working anymore, i printed gps.location.isValid() to see what value it has and everytime it had 0. I dont understand why isnt working. Maybe you can help me.
void loop()
{
while (Serial2.available() > 0)
{
gps.encode(Serial2.read());
if(gps.location.isValid())
{
// Latitude in degrees (double)
Serial.print("Latitude= ");
Serial.print(gps.location.lat(), 6);
lat_gps = gps.location.lat();
dtostrf(lat_gps,9,6,Latitude_GPS_char);
Latitude_GPS = String(Latitude_GPS_char);
// Longitude in degrees (double)
Serial.print(" Longitude= ");
Serial.println(gps.location.lng(), 6);
lon_gps = gps.location.lng();
dtostrf(lon_gps,9,6,Longitude_GPS_char);
Longitude_GPS = String(Longitude_GPS_char);
if ( (Latitude_GPS!="") && (Longitude_GPS!="") )
{
//Serial.println("Latitude: " + String(Latitude_GPS) + "\tLongitude: " + String(Longitude_GPS));
url = "script.google.com/macros/s/" + Script_ID + "/exec?value1=" + String(Latitude_GPS) + "&value2=" + String(Longitude_GPS);
Serial.println("AT+HTTPINIT");
Serial1.println("AT+HTTPINIT");
delay(1000);
updateSerial();
Serial.println("AT+HTTPSSL=1");
Serial1.println("AT+HTTPSSL=1");
delay(1000);
updateSerial();
Serial.println("AT+HTTPPARA=\"CID\",1");
Serial1.println("AT+HTTPPARA=\"CID\",1");
delay(1000);
updateSerial();
Serial.println("AT+HTTPPARA=\"URL\","+url);
Serial1.println("AT+HTTPPARA=\"URL\","+url);
delay(1000);
updateSerial();
Serial.println("AT+HTTPACTION=0");
Serial1.println("AT+HTTPACTION=0");
delay(200);
updateSerial();
delay(2000);
Serial1.println("AT+HTTPREAD");
Serial1.println("AT+HTTPREAD");
delay(1000);
updateSerial();
Serial.println("AT+HTTPTERM");
Serial1.println("AT+HTTPTERM");
delay(2000);
updateSerial();
}
}
}
if(!gps.location.isValid() && millis() > 5000)
{
responce = "";
Serial1.println("AT+CLBS=1,1"); delay(5000); //Request for location data
while (Serial1.available())
{
char letter = Serial1.read();
responce = responce + String(letter); //Store the location information in string responce
delay(1000);
}
Serial.print("Result Obtained as:"); Serial.print(responce); Serial.println("*******");
prepare_message(); delay(1000); //use prepare_message funtion to prepare the link with the obtained LAT and LONG co-ordinates
Serial.println("Latitude: " + Latitude + "\tLongitude: " + Longitude);
url = "script.google.com/macros/s/" + Script_ID + "/exec?value1=" + Latitude + "&value2=" + Longitude;
Serial.println("AT+HTTPINIT");
Serial1.println("AT+HTTPINIT");
delay(1000);
updateSerial();
Serial.println("AT+HTTPSSL=1");
Serial1.println("AT+HTTPSSL=1");
delay(1000);
updateSerial();
Serial.println("AT+HTTPPARA=\"CID\",1");
Serial1.println("AT+HTTPPARA=\"CID\",1");
delay(1000);
updateSerial();
Serial.println("AT+HTTPPARA=\"URL\","+url);
Serial1.println("AT+HTTPPARA=\"URL\","+url);
delay(1000);
updateSerial();
Serial.println("AT+HTTPACTION=0");
Serial1.println("AT+HTTPACTION=0");
delay(200);
updateSerial();
delay(2000);
Serial1.println("AT+HTTPREAD");
Serial1.println("AT+HTTPREAD");
delay(1000);
updateSerial();
Serial.println("AT+HTTPTERM");
Serial1.println("AT+HTTPTERM");
delay(2000);
updateSerial();
}
}