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.
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