Go Down

Topic: Sending GPS location error (Read 77 times) previous topic - next topic

ravejam

Mar 29, 2019, 09:36 am Last Edit: Mar 29, 2019, 09:43 am by ravejam
We're working on a project which one of its function is to send gps location through sms. We're using this https://alselectro.wordpress.com/2018/05/04/sim808-gps-gsm-module-sending-gps-location-sms/ 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
Code: [Select]
#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;
}




UKHeliBob

Quote
it just add the new coordinate to the old one
The data String is never set back to "" after sending the message.  Do you see how that might cause a problem ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

ravejam

The data String is never set back to "" after sending the message.  Do you see how that might cause a problem ?
Yes, but we tried to set it back to no value or null but it didn't work. Can you suggest we're it's best to put that code? Thank you for responding

UKHeliBob

Quote
we tried to set it back to no value or null but it didn't work
Post what you tried

Quote
Can you suggest we're it's best to put that code?
after you send the data would seem to be logical
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Go Up