GREP Function for serial printing

Hello everybody,

I have a problem with my code.

I have two serie communication.

One for the COM5
One for the SIM800 on GPIO 7, 8

I send a command on the SIM800 to read the SMS.
At this point all is ok.

Now i want to “GREP” the text message because I have too much information on the Serial COM5.
Maybe my code is not fine i don’t know.

If somebody can help me.

Here is my code

// If you have a pin code please put that code before setup :
// String SIM_PIN_CODE = String( "XXXX" );
// And put that code on setup :
// sim800l.print("AT+CPIN=");
// sim800l.println( SIM_PIN_CODE );
// Import of library.
#include <SoftwareSerial.h>
SoftwareSerial sim800l(7, 8); // RX, TX
 String text;     // to storage the text of the sms
 char inchar;
 
void setup() {          // Start of setup.
 Serial.begin(9600);    // Start of modem.
 sim800l.begin(9600);   // Initialisation of serie communication.
 sim800l.print("AT+CMGF=1\r");
 delay(500);
 text=sim800l.print("AT+CMGL=ALL\r");     
 Serial.println(text);//do nothing
}

void loop() {
 if (sim800l.available())
 Serial.write(sim800l.read());

 if (Serial.available()) {
 while(Serial.available()){
 sim800l.write(Serial.read());
 }
 sim800l.println();
 }
  // put your main code here, to run repeatedly:
  String ledOn = "Result command of AT+CMGR=1"; HERE IS MY PROBLEM
  Serial.println(ledOn);

  // substring(index) looks for the substring from the index position to the end:
  if (ledOn.substring(100,102) == "on") {
    Serial.println("You did it");
  }
  // you can also look for a substring in the middle of a string:
  if (ledOn.substring(100, 104) == "Test") {
    Serial.println("You did it");
  }

}

Here is an example of the COM5 print :

Thnaks for help :slight_smile:

You'll have to save that serial response in a variable. A char array makes the most sense. Then I think strstr would be the closest thing to grep. Look that one up in a c++ reference

Delta_G:
You'll have to save that serial response in a variable. A char array makes the most sense. Then I think strstr would be the closest thing to grep. Look that one up in a c++ reference

Hello Delta_G thank you for your answer, i'm kind of begginer on C++ code.
Can you be more specific please.

Thank you

What more do you need? Can you collect the characters you receive into a char array? See here. Serial Input Basics

Or do you need help finding the strstr function and how to use it? Try here. How to Google strstr

Thank you Delta_G i'll check this seeing if i can doing that.