Problems receiving message to send location of GPS (GY-Neo6MV2) using gsm 800l

Hello, I am doing a code on receiving sms to ask for location using gsm 800l. When i tried separately, i manage to send message automatically when received an sms called "check". However, when i combined the code, i am able to send the location manually through the serial monitor but not by sending sms to ask for location. I will be so grateful if anyone could help me with the code. Thank you :slight_smile:

this is my test code for receiving sms to send message

#include <SoftwareSerial.h>
SoftwareSerial sim(3, 2);

int _timeout;
String _buffer;
String number = "+60127487271"; //-> change with your number
String c;
void setup() {
  //delay(7000); //delay for 7 seconds to make sure the modules get the signal
  Serial.begin(9600);
  _buffer.reserve(50);
  Serial.println("Sistem Started...");
  sim.begin(9600);
  delay(1000);
  Serial.println("Type s to send an SMS, r to receive an SMS, and c to make a call");
}


void SendMessage()
{
  Serial.println ("Sending Message");
  sim.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);
  Serial.println ("Set SMS Number");
  sim.println("AT+CMGS=\"" + number + "\"\r"); //Mobile phone number to send message
  delay(1000);
  String SMS = "Hello, how are you?";
  sim.println(SMS);
  delay(100);
  sim.println((char)26);// ASCII code of CTRL+Z
  delay(1000);
  _buffer = _readSerial();
}

void RecieveMessage()
{
  Serial.println ("SIM800L Read an SMS");
  delay (1000);
  sim.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS
  delay(1000);
  Serial.write ("Unread Message done");
}

String _readSerial() {
  _timeout = 0;
  while  (!sim.available() && _timeout < 12000  )
  {
    delay(13);
    _timeout++;
  }
  if (sim.available()) {
    return sim.readString();
  }
}

void callNumber() {
  sim.print (F("ATD"));
  sim.print (number);
  sim.print (F(";\r\n"));
  _buffer = _readSerial();
  Serial.println(_buffer);
}
void loop() {
  if (Serial.available() > 0)
    switch (Serial.read())
    {
      case 's':
        SendMessage();
        break;
      case 'r':
        RecieveMessage();
        break;
      case 'c':
        callNumber();
        break;
    }
  if (sim.available() > 0)
    Serial.write(sim.read());
      
    if (sim.available() > 0)
   {
    String c= sim.readString();
  c.trim();
  if (c.indexOf("check")>=0)
  { SendMessage();
    sim.print("\r");
    delay(1000);}
   }}

this is my code when combined with gps

#include <TinyGPS++.h>

#include <SoftwareSerial.h>
//gsmmodule
SoftwareSerial sim(3, 2);
int _timeout;
String _buffer;
String number = "+60127487271"; //-> change with your number

//gpsmodule
static const int RXPin = 11, TXPin = 12;
static const uint32_t GPSBaud = 9600;
// The TinyGPS++ object
TinyGPSPlus gps;
// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);
void setup() {
  //delay(7000); //delay for 7 seconds to make sure the modules get the signal
  Serial.begin(9600);
  _buffer.reserve(50);
  Serial.println("Sistem Started...");
  sim.begin(9600);
  delay(1000);
  Serial.println("Type s to send an SMS, r to receive an SMS, and c to make a call");
  ss.begin(GPSBaud);

}




void SendMessage()
{
  Serial.println ("Sending Message");
  sim.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);
  Serial.println ("Set SMS Number");
  sim.println("AT+CMGS=\"" + number + "\"\r"); //Mobile phone number to send message
  delay(1000);
  float SMS1 = (gps.location.lat());
  float SMS2 = (gps.location.lng());
  sim.print("https://www.google.com/maps/?q=");
  sim.print(SMS1,6);
  sim.print(",");
  sim.print(SMS2,6);
  delay(100);
  sim.println((char)26);// ASCII code of CTRL+Z
  delay(1000);
  _buffer = _readSerial();
}

void RecieveMessage()
{
  Serial.println ("SIM800L Read an SMS");
  delay (1000);
  sim.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS
  delay(1000);
  Serial.write ("Unread Message done");
}

String _readSerial() {
  _timeout = 0;
  while  (!sim.available() && _timeout < 12000  )
  {
    delay(13);
    _timeout++;
  }
   if (sim.available() > 0)
    Serial.write(sim.read());
    
    if (sim.available() > 0)
   {
    String c= sim.readString();
  c.trim();
  if (c.indexOf("OKAY")>=0)
  {
    sim.print("\r");
    
    delay(1000);}
  }
}

void callNumber() {
  Serial.println ("Calling...");
  sim.print (F("ATD"));
  sim.print (number);
  sim.print (F(";\r\n"));
  _buffer = _readSerial();
  Serial.println(_buffer);
}

void loop(){
  

  if (Serial.available() > 0)
    switch (Serial.read())
    {
      case 's':
        SendMessage();
        break;
      case 'r':
        RecieveMessage();
        break;
      case 'c':
        callNumber();
        break;
    }
  if (sim.available() > 0)
    Serial.write(sim.read());
    // This sketch displays information every time a new sentence is correctly encoded.
    if (sim.available() > 0)
   {
    String c= sim.readString();
  c.trim();
  if (c.indexOf("check")>=0)
  { SendMessage();
    sim.print("\r");
    delay(1000);}
   }
  while (ss.available() > 0){
    gps.encode(ss.read());
    if (gps.location.isUpdated()){
      Serial.print("Latitude= "); 
      Serial.print(gps.location.lat(), 6);
      Serial.print(" Longitude= "); 
      Serial.println(gps.location.lng(), 6);
    }
    }
}

it has been a long time since iwas using 800l, no access today.
As far as i can remember :

  1. terminator esc-z was a "print", not a "println".
  2. the phonenumber structure was different for call / sms. One was WITH country number and the other was WITHOUT (for example , numbercall="123456789", numbersms="060123456789" or opposite)

I hope i helped

edit***********
I had used these lines

sim.print("AT+CMGF=1\r"); // set SMS mode to text

sim.println("AT+CMGS= ""....""\r");

//Send Ctrl+Z / ESC to denote SMS message is complete
sim.print((char)26);