Skip to main content
Bumped by Community user
deleted 142 characters in body; edited title
Source Link
dda
  • 1.6k
  • 1
  • 12
  • 17

SIM808 module  : GSM location command (AT+CIPGSMLOC=1,1) giving wrong value after execution of sending message command  (AT+CMGS=+91xxxxxxxx)

I wrote the code that if an interrupt is generated, get gsmGSM location and send a message. first

The first time the interrupt is generated, I got the correct gsmGSM location using (AT+CIPGSMLOC=1,1)AT+CIPGSMLOC=1,1 and successfully sendsent a message using command AT+CMGS=+91xxxxxxxx)the AT+CMGS=+91xxxxxxxxcommand.

But the next time whenan interrupt was generated then AT+CIPGSMLOC=1,1 is giving AT+CIPGSMLOC=1,1 gave a wrong location. When i When I commented out the code to send a message then, on every interrupt generated , iI am getting the correct gsmGSM location. So it seems like the problem is occurring after sending a message. butBut I have no clue what exactly is going wrong  . followingFollowing is my code.

Note: on restarting ofthe module, I'm again getting the correct location the first time, before sending a message.

void setup() {
  mySerial.begin(9600);                 
  Serial.begin(9600);  
  
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
 
  // initialize the pushbutton pin as an input:
  pinMode(sensorPin, INPUT);
  // Attach an interrupt to the ISR vector
  attachInterrupt(0, pin_ISR, FALLING);
} 

/////////***GSM RESPONSE***///////////     
String DisplayGSMResponse()
  {
      if(mySerial.available())
      {
      String gsm_input="";
      while(mySerial.available()) 
      {
      gsm_input+= (char)mySerial.read();
      }
      gsm_input.trim();
      
      delay(1000);
      Serial.println(gsm_input);
      return gsm_input;
      }
} 

void SendMessage(String mobNum,String Location)
  {
  Serial.println("Sending message..");
 
  mySerial.println("AT+CMGF=1");   
  //Sets the GSM Module in Text Mode
  delay(2000); 
  // Delay of 1000 milli seconds or 1 second
  DisplayGSMResponse();
  
  mySerial.println("AT+CMGS=\""+mobNum+"\"\r");
  // mobile Number
  delay(4000);
  DisplayGSMResponse();
  cleanBuffer();
  mySerial.print("test");
  // The SMS text you want to send
  delay(100);
  mySerial.println((char)26);
  // ASCII code of CTRL+Z
  delay(8000);
  DisplayGSMResponse();
} 

void gprsInit() {
  if (isGPRSInit) {
    return;
  }
  Serial.println("GPRS INITIALIZING");
  mySerial.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");
  delay(2000);
  DisplayGSMResponse();
  
  mySerial.println("AT+SAPBR=3,1,\"APN\",\"INTERNET\"");
  delay(2000);
  DisplayGSMResponse();
  
  mySerial.println("AT+SAPBR=1,1");
  delay(8000);
  DisplayGSMResponse();
  
  mySerial.println("AT+SAPBR=2,1");
  delay(2000);
  DisplayGSMResponse();
 
  isGPRSInit = true;
}
     
void gprsterm() {
  mySerial.println("AT+SAPBR=0,1");
  delay(1000);
  DisplayGSMResponse();
  isGPRSInit = false;
} 

String getGPS() {
  Serial.println("GETTING GPS LOCATION");
  String loc = "";
  String location = "";
  
  mySerial.println("AT+CIPGSMLOC=1,1");
  delay(3000);
  loc = DisplayGSMResponse();  
  
  return location; 
}

void loop() {
   if (buttonState == 1)
   {
    detachInterrupt(0);
    
    gprsInit();
    location = getGPS();
    SendMessage(mobileNumber, location);
    
    gprsterm();
    Serial.println("location = " + location);
    buttonState = 0;
    location = "";
    attachInterrupt(0, pin_ISR, FALLING );
  }
}

void pin_ISR() {
  buttonState = 1;
  Serial.println("interrupt");
}

EDIT: added gprsterm funcfunction.

Note: I removed the interrupt and called the code inside the loop function twice. The first time I got a correct result. The second time a wrong result. soSo it interrupt seems like the interrupt is not be causing the problem.

EDIT2: onOne interesting thing I found is that at my home it is showing correct results every time, but in the office it is showing a wrong location on second location call i.e after sms got triggeredthe SMS was sent and then if we do gsmget the GSM location call using AT+CIPGSMLOC=1,1AT+CIPGSMLOC=1,1.

SIM808 module  : GSM location command (AT+CIPGSMLOC=1,1) giving wrong value after execution of sending message command(AT+CMGS=+91xxxxxxxx)

I wrote the code that if interrupt generated, get gsm location and send a message. first time interrupt generated, got correct gsm location using (AT+CIPGSMLOC=1,1) and successfully send message using command AT+CMGS=+91xxxxxxxx)

But next time when interrupt generated then AT+CIPGSMLOC=1,1 is giving wrong location. When i commented the code to send message then on every interrupt generated , i am getting correct gsm location. So it seems like problem is occurring after sending message. but no clue what exactly going wrong  . following is my code

Note: on restarting of module again getting correct location first time before sending message

void setup() {
  mySerial.begin(9600);                 
  Serial.begin(9600);  
  
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
 
  // initialize the pushbutton pin as an input:
  pinMode(sensorPin, INPUT);
  // Attach an interrupt to the ISR vector
  attachInterrupt(0, pin_ISR, FALLING);
}
/////////***GSM RESPONSE***///////////     
String DisplayGSMResponse()
 {
      if(mySerial.available())
      {
      String gsm_input="";
      while(mySerial.available()) 
      {
      gsm_input+= (char)mySerial.read();
      }
      gsm_input.trim();
      
      delay(1000);
      Serial.println(gsm_input);
      return gsm_input;
      }
}
void SendMessage(String mobNum,String Location)
 {
  Serial.println("Sending message..");
 
  mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(2000);  // Delay of 1000 milli seconds or 1 second
  DisplayGSMResponse();
  
  mySerial.println("AT+CMGS=\""+mobNum+"\"\r"); // mobile Number
  delay(4000);
  DisplayGSMResponse();
  cleanBuffer();
  mySerial.print("test");// The SMS text you want to send
  delay(100);
  mySerial.println((char)26);// ASCII code of CTRL+Z
  delay(8000);
  DisplayGSMResponse();
}
void gprsInit() {
  if (isGPRSInit) {
    return;
  }
  Serial.println("GPRS INITIALIZING");
  mySerial.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");
  delay(2000);
  DisplayGSMResponse();
  
  mySerial.println("AT+SAPBR=3,1,\"APN\",\"INTERNET\"");
  delay(2000);
  DisplayGSMResponse();
  
  mySerial.println("AT+SAPBR=1,1");
  delay(8000);
  DisplayGSMResponse();
  
  mySerial.println("AT+SAPBR=2,1");
  delay(2000);
  DisplayGSMResponse();
 
  isGPRSInit = true;
}
    void gprsterm(){
  mySerial.println("AT+SAPBR=0,1");
  delay(1000);
  DisplayGSMResponse();
  isGPRSInit = false;
}
String getGPS() {
  Serial.println("GETTING GPS LOCATION");
  String loc = "";
  String location = "";
  
  mySerial.println("AT+CIPGSMLOC=1,1");
  delay(3000);
  loc = DisplayGSMResponse();  
  
  return location; 
}

void loop() {
   if (buttonState == 1)
   {
    detachInterrupt(0);
    
    gprsInit();
    location = getGPS();
    SendMessage(mobileNumber, location);
    
    gprsterm();
    Serial.println("location = " + location);
    buttonState = 0;
    location = "";
    attachInterrupt(0, pin_ISR, FALLING );
  }
}

void pin_ISR() {
  buttonState = 1;
  Serial.println("interrupt");
}

EDIT: added gprsterm func.

Note: I removed the interrupt and called the code inside loop function twice. first time got correct result. second time wrong result. so it interrupt seems not be causing problem.

EDIT2: on interesting thing I found is that at my home it is showing correct results every time, but in office it is showing wrong location on second location call i.e after sms got triggered and then if we do gsm location call using AT+CIPGSMLOC=1,1.

SIM808 module: GSM location command (AT+CIPGSMLOC=1,1) giving wrong value after execution of sending message command  (AT+CMGS=+91xxxxxxxx)

I wrote the code that if an interrupt is generated, get GSM location and send a message.

The first time the interrupt is generated, I got the correct GSM location using AT+CIPGSMLOC=1,1 and successfully sent a message using the AT+CMGS=+91xxxxxxxxcommand.

But the next time an interrupt was generated, AT+CIPGSMLOC=1,1 gave a wrong location. When I commented out the code to send a message, on every interrupt generated I am getting the correct GSM location. So it seems like the problem is occurring after sending a message. But I have no clue what exactly is going wrong. Following is my code.

Note: on restarting the module, I'm again getting the correct location the first time, before sending a message.

void setup() {
  mySerial.begin(9600);
  Serial.begin(9600);
  while (!Serial) {
  }
  // initialize the pushbutton pin as an input:
  pinMode(sensorPin, INPUT);
  // Attach an interrupt to the ISR vector
  attachInterrupt(0, pin_ISR, FALLING);
} 

/////////***GSM RESPONSE***///////////
String DisplayGSMResponse() {
  if(mySerial.available()) {
    String gsm_input="";
    while(mySerial.available()) {
      gsm_input+= (char)mySerial.read();
    }
    gsm_input.trim();
    delay(1000);
    Serial.println(gsm_input);
    return gsm_input;
  }
} 

void SendMessage(String mobNum,String Location) {
  Serial.println("Sending message..");
  mySerial.println("AT+CMGF=1"); 
  //Sets the GSM Module in Text Mode
  delay(2000); 
  // Delay of 1000 milli seconds or 1 second
  DisplayGSMResponse();
  mySerial.println("AT+CMGS=\""+mobNum+"\"\r");
  // mobile Number
  delay(4000);
  DisplayGSMResponse();
  cleanBuffer();
  mySerial.print("test");
  // The SMS text you want to send
  delay(100);
  mySerial.println((char)26);
  // ASCII code of CTRL+Z
  delay(8000);
  DisplayGSMResponse();
} 

void gprsInit() {
  if (isGPRSInit) {
    return;
  }
  Serial.println("GPRS INITIALIZING");
  mySerial.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");
  delay(2000);
  DisplayGSMResponse();
  mySerial.println("AT+SAPBR=3,1,\"APN\",\"INTERNET\"");
  delay(2000);
  DisplayGSMResponse();
  mySerial.println("AT+SAPBR=1,1");
  delay(8000);
  DisplayGSMResponse();
  mySerial.println("AT+SAPBR=2,1");
  delay(2000);
  DisplayGSMResponse();
  isGPRSInit = true;
}
 
void gprsterm() {
  mySerial.println("AT+SAPBR=0,1");
  delay(1000);
  DisplayGSMResponse();
  isGPRSInit = false;
} 

String getGPS() {
  Serial.println("GETTING GPS LOCATION");
  String loc = "";
  String location = "";
  mySerial.println("AT+CIPGSMLOC=1,1");
  delay(3000);
  loc = DisplayGSMResponse();
  return location;
}

void loop() {
  if (buttonState == 1) {
    detachInterrupt(0);
    gprsInit();
    location = getGPS();
    SendMessage(mobileNumber, location);
    gprsterm();
    Serial.println("location = " + location);
    buttonState = 0;
    location = "";
    attachInterrupt(0, pin_ISR, FALLING );
  }
}

void pin_ISR() {
  buttonState = 1;
  Serial.println("interrupt");
}

EDIT: added gprsterm function.

Note: I removed the interrupt and called the code inside the loop function twice. The first time I got a correct result. The second time a wrong result. So it seems like the interrupt is not be causing the problem.

EDIT2: One interesting thing I found is that at my home it is showing correct results every time, but in the office it is showing a wrong location on second location call i.e after the SMS was sent and we get the GSM location using AT+CIPGSMLOC=1,1.

added 257 characters in body
Source Link
Suri
  • 169
  • 1
  • 2
  • 7

EDIT2: on interesting thing I found is that at my home it is showing correct results every time, but in office it is showing wrong location on second location call i.e after sms got triggered and then if we do gsm location call using AT+CIPGSMLOC=1,1.

EDIT2: on interesting thing I found is that at my home it is showing correct results every time, but in office it is showing wrong location on second location call i.e after sms got triggered and then if we do gsm location call using AT+CIPGSMLOC=1,1.

added gprsterm func and interrupt not a problem finding
Source Link
Suri
  • 169
  • 1
  • 2
  • 7
void setup() {
  mySerial.begin(9600);                 
  Serial.begin(9600);  
  
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // initialize the pushbutton pin as an input:
  pinMode(sensorPin, INPUT);
  // Attach an interrupt to the ISR vector
  attachInterrupt(0, pin_ISR, FALLING);
}
/////////***GSM RESPONSE***///////////     
String DisplayGSMResponse()
{
      if(mySerial.available())
      {
      String gsm_input="";
      while(mySerial.available()) 
      {
      gsm_input+= (char)mySerial.read();
      }
      gsm_input.trim();
      
      delay(1000);
      Serial.println(gsm_input);
      return gsm_input;
      }
}
void SendMessage(String mobNum,String Location)
{
  Serial.println("Sending message..");

  mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(2000);  // Delay of 1000 milli seconds or 1 second
  DisplayGSMResponse();
  
  mySerial.println("AT+CMGS=\""+mobNum+"\"\r"); // mobile Number
  delay(4000);
  DisplayGSMResponse();
  cleanBuffer();
  mySerial.print("test");// The SMS text you want to send
  delay(100);
  mySerial.println((char)26);// ASCII code of CTRL+Z
  delay(8000);
  DisplayGSMResponse();
}
void gprsInit() {
  if (isGPRSInit) {
    return;
  }
  Serial.println("GPRS INITIALIZING");
  mySerial.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");
  delay(2000);
  DisplayGSMResponse();
  
  mySerial.println("AT+SAPBR=3,1,\"APN\",\"INTERNET\"");
  delay(2000);
  DisplayGSMResponse();
  
  mySerial.println("AT+SAPBR=1,1");
  delay(8000);
  DisplayGSMResponse();
  
  mySerial.println("AT+SAPBR=2,1");
  delay(2000);
  DisplayGSMResponse();

  isGPRSInit = true;
}
    void gprsterm(){
  mySerial.println("AT+SAPBR=0,1");
  delay(1000);
  DisplayGSMResponse();
  isGPRSInit = false;
}
String getGPS() {
  Serial.println("GETTING GPS LOCATION");
  String loc = "";
  String location = "";
  
  mySerial.println("AT+CIPGSMLOC=1,1");
  delay(3000);
  loc = DisplayGSMResponse();  
  
  return location; 
}

void loop() {
   if (buttonState == 1)
   {
    detachInterrupt(0);
    
    gprsInit();
    location = getGPS();
    SendMessage(mobileNumber, location);
    
    gprsterm();
    Serial.println("location = " + location);
    buttonState = 0;
    location = "";
    attachInterrupt(0, pin_ISR, FALLING );
  }
}

void pin_ISR() {
  buttonState = 1;
  Serial.println("interrupt");
}

EDIT: added gprsterm func.

Note: I removed the interrupt and called the code inside loop function twice. first time got correct result. second time wrong result. so it interrupt seems not be causing problem.

void setup() {
  mySerial.begin(9600);                 
  Serial.begin(9600);  
  
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // initialize the pushbutton pin as an input:
  pinMode(sensorPin, INPUT);
  // Attach an interrupt to the ISR vector
  attachInterrupt(0, pin_ISR, FALLING);
}
/////////***GSM RESPONSE***///////////     
String DisplayGSMResponse()
{
      if(mySerial.available())
      {
      String gsm_input="";
      while(mySerial.available()) 
      {
      gsm_input+= (char)mySerial.read();
      }
      gsm_input.trim();
      
      delay(1000);
      Serial.println(gsm_input);
      return gsm_input;
      }
}
void SendMessage(String mobNum,String Location)
{
  Serial.println("Sending message..");

  mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(2000);  // Delay of 1000 milli seconds or 1 second
  DisplayGSMResponse();
  
  mySerial.println("AT+CMGS=\""+mobNum+"\"\r"); // mobile Number
  delay(4000);
  DisplayGSMResponse();
  cleanBuffer();
  mySerial.print("test");// The SMS text you want to send
  delay(100);
  mySerial.println((char)26);// ASCII code of CTRL+Z
  delay(8000);
  DisplayGSMResponse();
}
void gprsInit() {
  if (isGPRSInit) {
    return;
  }
  Serial.println("GPRS INITIALIZING");
  mySerial.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");
  delay(2000);
  DisplayGSMResponse();
  
  mySerial.println("AT+SAPBR=3,1,\"APN\",\"INTERNET\"");
  delay(2000);
  DisplayGSMResponse();
  
  mySerial.println("AT+SAPBR=1,1");
  delay(8000);
  DisplayGSMResponse();
  
  mySerial.println("AT+SAPBR=2,1");
  delay(2000);
  DisplayGSMResponse();

  isGPRSInit = true;
}
String getGPS() {
  Serial.println("GETTING GPS LOCATION");
  String loc = "";
  String location = "";
  
  mySerial.println("AT+CIPGSMLOC=1,1");
  delay(3000);
  loc = DisplayGSMResponse();  
  
  return location; 
}

void loop() {
   if (buttonState == 1)
   {
    detachInterrupt(0);
    
    gprsInit();
    location = getGPS();
    SendMessage(mobileNumber, location);
    
    gprsterm();
    Serial.println("location = " + location);
    buttonState = 0;
    location = "";
    attachInterrupt(0, pin_ISR, FALLING );
  }
}

void pin_ISR() {
  buttonState = 1;
  Serial.println("interrupt");
}
void setup() {
  mySerial.begin(9600);                 
  Serial.begin(9600);  
  
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // initialize the pushbutton pin as an input:
  pinMode(sensorPin, INPUT);
  // Attach an interrupt to the ISR vector
  attachInterrupt(0, pin_ISR, FALLING);
}
/////////***GSM RESPONSE***///////////     
String DisplayGSMResponse()
{
      if(mySerial.available())
      {
      String gsm_input="";
      while(mySerial.available()) 
      {
      gsm_input+= (char)mySerial.read();
      }
      gsm_input.trim();
      
      delay(1000);
      Serial.println(gsm_input);
      return gsm_input;
      }
}
void SendMessage(String mobNum,String Location)
{
  Serial.println("Sending message..");

  mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(2000);  // Delay of 1000 milli seconds or 1 second
  DisplayGSMResponse();
  
  mySerial.println("AT+CMGS=\""+mobNum+"\"\r"); // mobile Number
  delay(4000);
  DisplayGSMResponse();
  cleanBuffer();
  mySerial.print("test");// The SMS text you want to send
  delay(100);
  mySerial.println((char)26);// ASCII code of CTRL+Z
  delay(8000);
  DisplayGSMResponse();
}
void gprsInit() {
  if (isGPRSInit) {
    return;
  }
  Serial.println("GPRS INITIALIZING");
  mySerial.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");
  delay(2000);
  DisplayGSMResponse();
  
  mySerial.println("AT+SAPBR=3,1,\"APN\",\"INTERNET\"");
  delay(2000);
  DisplayGSMResponse();
  
  mySerial.println("AT+SAPBR=1,1");
  delay(8000);
  DisplayGSMResponse();
  
  mySerial.println("AT+SAPBR=2,1");
  delay(2000);
  DisplayGSMResponse();

  isGPRSInit = true;
}
    void gprsterm(){
  mySerial.println("AT+SAPBR=0,1");
  delay(1000);
  DisplayGSMResponse();
  isGPRSInit = false;
}
String getGPS() {
  Serial.println("GETTING GPS LOCATION");
  String loc = "";
  String location = "";
  
  mySerial.println("AT+CIPGSMLOC=1,1");
  delay(3000);
  loc = DisplayGSMResponse();  
  
  return location; 
}

void loop() {
   if (buttonState == 1)
   {
    detachInterrupt(0);
    
    gprsInit();
    location = getGPS();
    SendMessage(mobileNumber, location);
    
    gprsterm();
    Serial.println("location = " + location);
    buttonState = 0;
    location = "";
    attachInterrupt(0, pin_ISR, FALLING );
  }
}

void pin_ISR() {
  buttonState = 1;
  Serial.println("interrupt");
}

EDIT: added gprsterm func.

Note: I removed the interrupt and called the code inside loop function twice. first time got correct result. second time wrong result. so it interrupt seems not be causing problem.

Source Link
Suri
  • 169
  • 1
  • 2
  • 7
Loading