Serial.read to multiple variable

i am working on a script and stay now at a point where i dont know how to do it.

i have a esp32 connected to a gsm800L

it connect to the network all works fine.

i can send this command gsm_send_serial("AT+CLBS=1,1");

and i see the response in the serial monitor.

23:16:23.562 -> Send ->: AT+CLBS=1,1
23:16:23.562 -> AT+CLBS=1,1
23:16:25.853 -> +CLBS: 0,16.231825,47.826818,550

how can i grab this information from serial and write it to 2 variable?

variable 1=16.231825
variable 2=47.826818

----------------------------my code---------------------------

gsm_send_serial("AT+CLBS=1,1");

String gps = Serial.read();

------------------is definitly wrong :)) --------------------

I would suggest to study Serial Input Basics to handle this

Read lines coming on serial, check if it starts with +CLBS with strncmp(), if so extract the data with atof()

Thanks ,

My code looks like this now

gsm_send_serial("AT+SAPBR=1,1");
  gsm_send_serial("AT+SAPBR=2,1");
  while (Serial2.available()) {             //to clear serial buffer 
    Serial.write(Serial2.read());
  } 
  gsm_send_serial("AT+CLBS=1,1");          //command you required 
  while(!Serial2.available()){
  delay(1);
  }                          //wait till data recive
  char charIncome;                    //define tempory charactor to store
  String dataRecived="";                 //serial data to process
  while (Serial2.available()) {            //while serial communication available
    charIncome =Serial2.read();            //read serial data
    dataRecived = dataRecived+charIncome; // make the string with incoming charactors
  }
  Serial.print("dataRecived="); //print string value
  Serial.println(dataRecived); //print string value
  int startPoint= dataRecived.indexOf("+CLBS:");  //find the position of the string
  int secondStartPoint= dataRecived.indexOf("," ,startPoint ); //find the 1st coma (,)position of the string
  int thirdStartPoint= dataRecived.indexOf("," ,secondStartPoint+1 ); //find the 2nd coma (,)position of the string
  variable1 =dataRecived.substring(secondStartPoint+1 ,thirdStartPoint); //output variable 1 as string   
  int fourthStartPoint= dataRecived.indexOf("," ,thirdStartPoint+1 ); //find the 3rd coma (,)position of the string
  variable2 =dataRecived.substring(thirdStartPoint+1,fourthStartPoint); //output variable 2 as string
  
  gsm_send_serial("AT+HTTPINIT");
  gsm_send_serial("AT+HTTPPARA=CID,1");

from 10 trys 1 time is working the other times it stuck at the command and dont go to the next one.

13:56:47.391 ->  --- Start GPRS & HTTP --- 
13:56:47.391 -> Send ->: AT+SAPBR=1,1
13:56:47.437 -> AT+SAPBR=1,1

13:56:47.998 -> OK
13:56:50.373 -> 
13:56:50.373 -> Send ->: AT+SAPBR=2,1
13:56:50.467 -> AT+SAPBR=2,1

13:56:50.467 -> +SAPBR: 1,1,"10.193.201.244"
13:56:50.467 -> 
13:56:50.467 -> OK
13:56:53.374 -> 
13:56:53.374 -> Send ->: AT+CLBS=1,1
13:56:53.421 -> AT+CLBS=1,1

13:56:55.808 -> +CLBS: 0,16.231521,47.826600,550
13:56:55.808 -> 
13:56:55.808 -> OK
13:56:56.369 ->

the httpinit command dont come

you did not apply the tutorial's technics.

You are basically trying to second guess when the data is coming back which will lead to disappointment with any asynchronous protocol

basically a while loop just based on available() as you do

 while (Serial2.available()) {            //while serial communication available
    charIncome =Serial2.read();            //read serial data
    dataRecived = dataRecived+charIncome; // make the string with incoming charactors
  }

can't guarantee that you'll get in dataRecived the full answer because the data might be coming in at a much slower pace you remove it from the buffer. So at some point available() will say 0, nothing to read yet, but some data might still be coming in, just not arrived yet at the baud rate you selected.

If you know answers form a full line terminated by a new line ('\n') read what's incoming until you get this '\n' and then parse the buffer. Don't just stop when available() says there is nothing to read

gorogdaniel:
My code looks like this now

Why not just use the appropriate function from my Serial Input Basics Tutorial ?

...R