Read and store message using sim800L

I am able to receive message using SIM 800L using the code given below.
I need help in storing the message received for which I tried using this:
String str = Serial.readString(); Serial.println(“str”+str);
after the second delay line.
The problem is no data gets stored in str. Can someone suggest me some idea such that I can store the data. I want to obtain the message sent from the mobile on the sim present in sim800L so that I can compare it with a string and perform necessary actions.
Thanks in advance.

void ReceeiveMessage()
{
  Serial.println ("SIM800L Read ");
  delay (1000);
  sim.println("AT+CNMI=2,1,0,0,0"); 
 delay(1000);
       Serial.write ("Message done ");
 
}

Are you using an Arduino to communicate with the SIM 800l? If that’s the case, the Serial in your Serial.readString() probably refers to the Serial port used by the Arduino to comunicate with your PC, and if you defined another object with that name, I suggest you to change the name to avoid confusion.

@viedana, I am using Arduino UNO to communicate with SIM 800L.
With the code given above by me, I was able to print the message on Serial Monitor.
I want to extract and store this message in a variable.
Can you please help me out?

I assume the sim object in your snippet is an instance of a SoftwareSerial class or something like that. If that’s the case, you should be able to store the SIM800’s responses by doing something like:

String str = sim.readString();

Compare this with the line you posted: String str = Serial.readString();, which would instead store anything you write on the Serial Monitor.

Then in order to print on the Serial Monitor the contents of str you do:

Serial.print("str: ");
Serial.println(str);

Also, I’m not very familiar with the void ReceeiveMessage() function, but if I have to guess, it is triggered only when you receive a message sent by the Serial Monitor/PC. If so, at least for a starting point, I would suggest you to put the logic to process the SIM800’s responses in the void loop() function, something like this:

void loop()
{
    if (sim.available()) // We only need to capture the message when there is something new coming from the port
    {
        String str = sim.readString();

        // Do your response processing in here
    }
}