Sim800L

Good evening to all, I ask for help to the people of Arduino because I'm trying something new and I do not know how to do it...
I'm using an Arduino Mega 2560 and the Sim800L module, I found a code that allows me to view the messages I send him on the serial monitor. So far so good, my problem is how to save this word in a variable that I can use later in my code. Let me explain better, I would like to send them like turn on and off and turn on and off a LED, I know that there are examples on the internet but I would like to avoid libraries already made. I want to use the command String Comparison Operators only that I have to save the string received somewhere ...

Attached I put my code and what I read in the serial, I hope I explained well ...

void setup()
{
  //Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
  Serial.begin(9600);
  //Begin serial communication with Arduino and SIM800L
  Serial1.begin(9600);

  Serial.println("Initializing..."); 
  delay(1000);

  Serial1.println("AT"); //Once the handshake test is successful, it will back to OK
  updateSerial();
  
  Serial1.println("AT+CMGF=1"); // Configuring TEXT mode
  updateSerial();
  Serial1.println("AT+CNMI=1,2,0,0,0"); // Decides how newly arrived SMS messages should be handled
  updateSerial();
}

void loop()
{
  updateSerial();
  }

void updateSerial()
{
  delay(500);
  while (Serial.available()) 
  {
    Serial1.write(Serial.read());//Forward what Serial received to Software Serial Port
  }
  while(Serial1.available()) 
  {
    Serial.write(Serial1.read());//Forward what Software Serial received to Serial Port
  }
}
Initializing...
AT

OK
AT+CMGF=1

OK
AT+CNMI=1,2,0,0,0

OK

+CMT: "+41762957962","","19/08/07,20:19:36+08"
On

my problem is how to save this word in a variable that I can use later in my code.

const String at = "AT";
const String atcmgf1 = "AT+CMGF=1";
const String atcnmi1 = "AT+CNMI=1,2,0,0,0";

void setup() { 
Serial.begin(9600);
}

void loop() {
Serial.println(at);
delay(1000);
Serial.println(atcmgf1);
delay(1000);
Serial.println(atcnmi1);
delay(5000);
}

Bye, thank you so much for your help.
When I start your program I read this on the serial monitor:

Initializing...
AT

OK
AT+CMGF=1

OK
AT+CNMI=1,2,0,0,0

OK
AT
AT+CMGF=1
AT+CNMI=1,2,0,0,0
AT
AT+CMGF=1
AT+CNMI=1,2,0,0,0
AT
AT+CMGF=1
AT+CNMI=1,2,0,0,0
AT
AT+CMGF=1
AT+CNMI=1,2,0,0,0

+CMT: "+41762957962","","19/08/08,10:43:59+08"
Hello

and that's not exactly what I need... I would like to save the word "Hello" in a const String so I can use it but I do not know how to do it....

Can anyone help me? Thank you very much :slight_smile:

I would like to save the word "Hello" in a const String so I can use it but I do not know how to do it....

Just declare const String variable equal to hello.

const String word_Hello = "Hello";