When reading serial sometimes the input data is too large to save, but we need to search inside it anyway , for a certain words .
Right now we accumulate all the data and only then look for the specific word. I would like to do that while reading, without saving the data , so to improve this one :
boolean waitFor(char *target, long timeout)
{
unsigned long tm=millis();
while( 1 )
{
if( millis() - tm >= timeout )
return 0;
char wifiContent[50]={0};
int readWifiIndex=0;
while( wifiSerial.available() )
{
if(readWifiIndex<50)
{
wifiContent[readWifiIndex]=(char)wifiSerial.read();
readWifiIndex++;
delay(1);
}
}
//**check of specific words
if( strstr(wifiContent,target) )
return 1;
}
}
Update: I have changed my code to search WHILE i read, and everything is great now .