We're working on a project which one of its function is to send gps location through sms. We're using this Sim808 GPS GSM Module – Sending Gps Location SMS | alselectro as a basis. Everything works fine at first but after the first message instead of sending correct coordinates, it just add the new coordinate to the old one. Please help and Thank you so much
We're using arduino uno and sim808
The attached file is the output we get, it's the same for when we run the serial monitor. Thank you so much
#include <SoftwareSerial.h>
SoftwareSerial sim808(7,8);
char phone_no[] = "09056647398"; // replace with your phone no.
String data[5];
#define DEBUG true
String state,timegps,latitude,longitude;
void setup() {
sim808.begin(9600);
Serial.begin(9600);
delay(50);
sim808.print("AT+CSMP=17,167,0,0"); // set this parameter if empty SMS received
delay(100);
sim808.print("AT+CMGF=1\r");
delay(400);
sendData("AT+CGNSPWR=1",1000,DEBUG);
delay(50);
sendData("AT+CGNSSEQ=RMC",1000,DEBUG);
delay(150);
}
void loop() {
sendTabData("AT+CGNSINF",1000,DEBUG);
if (state !=0) {
Serial.println("State :"+state);
Serial.println("Time :"+timegps);
Serial.println("Latitude :17.635343"+latitude);
Serial.println("Longitude :121.742960"+longitude);
sim808.print("AT+CMGS=\"");
sim808.print(phone_no);
sim808.println("\"");
delay(300);
sim808.print("http://maps.google.com/maps?q=loc:");
sim808.print("17.635343");
sim808.print(",");
sim808.print ("121.742960");
delay(200);
sim808.println((char)26); // End AT command with a ^Z, ASCII code 26
delay(200);
sim808.println();
delay(20000);
sim808.flush();
} else {
Serial.println("GPS Initialising...");
}
}
void sendTabData(String command , const int timeout , boolean debug){
sim808.println(command);
long int time = millis();
int i = 0;
while((time+timeout) > millis()){
while(sim808.available()){
char c = sim808.read();
if (c != ',') {
data[i] +=c;
delay(100);
} else {
i++;
}
if (i == 5) {
delay(100);
goto exitL;
}
}
}exitL:
if (debug) {
state = data[1];
timegps = data[2];
latitude = data[3];
longitude =data[4];
}
}
String sendData (String command , const int timeout ,boolean debug){
String response = "";
sim808.println(command);
long int time = millis();
int i = 0;
while ( (time+timeout ) > millis()){
while (sim808.available()){
char c = sim808.read();
response +=c;
}
}
if (debug) {
Serial.print(response);
}
return response;
}