I have here a loop wherein the arduino calls and text the user its coordinate by means of sim808 GPS module. My problem is the GPS coordinate only show once, the text message that i have received showed a blank coordinates. Please help
#include <SoftwareSerial.h>
SoftwareSerial gps(11,10);//RX,TX//
String lattitude, longitude;
#define DEBUG true
String data[5];
char phone[] ="xxxxxxxxx";// replace this with your phone no.
int Sim808Pin = 9;
int Sim808Button = 7;
bool bAdmin,bGetloc,bHelp,bClrmsg=0;
int i = 0;
char c;
void setup() {
pinMode(Sim808Pin,OUTPUT);
pinMode(Sim808Button,INPUT);
gps.begin(9600);
Serial.begin(9600);
Serial.println("wait for 5 sec");
delay(5000);
sendData("AT+CGNSPWR=1",1000,DEBUG);//Turn on GPS(GNSS - Global Navigation Satellite System)
delay(500);
sendData("AT+CGNSSEQ=RMC",1000,DEBUG);
delay(500);
sendData("AT+CGNSPWR?",1000,DEBUG);
}
void loop() {
// miss_call();
//delay(2000);
//sms_send();
//delay (1000);
gps_location();
delay(1000);
}
String sendData (String command , const int timeout ,boolean debug){
String response = "";
gps.println(command);
long int time = millis();
int i = 0;
while ( (time+timeout ) > millis()){
while (gps.available()){
char c = gps.read();
response +=c;
}
}
if (debug){
if (response.indexOf(phone)>=0){bAdmin=1;}
if (response.indexOf("Get Location")>=0){bGetloc=1;}
if (response.indexOf("Help")>=0){bHelp=1;}
if (response.indexOf("Clear Messages")>=0){bClrmsg=1;}
Serial.print(response);
}
return response;
}
void miss_call(){
Serial.println("Calling.......");
gps.print("ATD"); // Call command ATD9730579463;
gps.print(phone);
gps.println(";");
delay(10000);
Serial.println("Call disconected");
gps.println("ATH");
delay(1000);
}
void sms_send()
{ gps.println("AT+CMGF=1"); // Select Text mode for messsaging
delay(500);
gps.print("AT+CMGS=\"");
gps.print(phone);
gps.println("\"");
delay(1000);
gps.print("http://maps.google.com/maps?q=loc:");
gps.print(lattitude);
gps.print(",");
gps.print(longitude);
delay(500);
gps.println((char)26);
delay(100);
Serial.println("Message is sent");
delay(100);
}
void gps_location(){
int i=0;
longitude = "";
lattitude = "";
for(i=0; i<5; i++)
data[i]="";
i=0;
Serial.println("--GPS--request--given----");
gps.flush();
long int time = millis();
gps.println("AT+CGNSINF");
while ((time+1000 ) > millis()){
while(gps.available()){
c = gps.read();
if (c != ',') {
data[i] +=c;
delay(20);
}
else
i++;
}
if(i==5)
break;
}
lattitude = data[3];
longitude = data[4];
Serial.print("lattitude = ");
Serial.println(lattitude);
Serial.print("longitude = ");
Serial.println(longitude);
}