I'v made the code ridiculously long in order to understand why is this not working :
bool waitRespond(char *respond,char *error)
{
mySerial.print("WAITING FOR:"); mySerial.println(respond);
int maxsize=20;
boolean didGot=0;
char inData[maxsize]={0};
int Tindex=0;
unsigned long timeOutKeeper = millis();
while (!didGot)
{
if (millis() - timeOutKeeper >=TIME_OUT_LONG )
{ mySerial.println("TIMEOUT:"); didGot=1; break;}
while ( Serial.available() >0 )
{
if(Tindex>maxsize-1)
{didGot=1;return 0;}
char c = Serial.read();
inData[Tindex]=c;
//prints
mySerial.print("*");
mySerial.print(inData[Tindex]);
//
Tindex++;
inData[Tindex]='\0';
}
if(strstr(inData, respond) != NULL)
{ mySerial.println("FOUND:"); didGot=1; return 1;}
}
So for this input I print ( and get the right result) :
WAITING FOR:CMD
*E*N*D*
*
*C*M*D*
*
FOUND:
and for another input, he will NOT find the string inside , no matter what I try:
WAITING FOR:CMD
*R*e*b*o*o*t**
**C*M*D**
TIMEOUT:
TIMEOUT happens after 18 seconds.
Where timeout parameter is 18 seconds, and the prints (reboot+cmd) happens after 250 milli seconds= right away.