Hi guys, I'm working on a project where I send some AT commands, and I want to send a new commands only after recieving the "OK", so I made this function where the at commands are the inputs:
int WaitResp(const char* a){
String incomingByte=""; // for incoming Serial data
int len=0;
int i=0;
Serial.flush();
delay(1000);
Serial.write(a);
delay(300);
if(Serial.available()>0) {
// read the incoming byte:
incomingByte = Serial.readString();// read the incoming data as string
// say what you got:
len = incomingByte.length();
char reso[len]={};
incomingByte.toCharArray(reso, 50);
i=len;
if(reso[len-3]=='K')
return 1;
else {
return 0;
}
}
}
it worked only for the first commands, when I did a small loop to see what's happening
for(i=len;i>1;i=i-1){
Serial.print(reso[len-i]);
}
it show this :
AT
AT
OK
AT+CGNSTST=0
AT
OK
OK
AT+CGNSTST=0
OK
And it's stop like this, even tho there're more commands to come.
can anyone help me to resolve this please?
NB: I'm using a hardware serial.