unsigned long startedWaiting = millis();
char buffer[90];
int size = ultrasonic.readBytesUntil('\n', buffer, 80);
while (strchr(buffer, 'IdleSec') == NULL && millis() - startedWaiting <= 10000) {
trow_away=(ultrasonic.read());
size = ultrasonic.readBytesUntil('\n', buffer, 80);
if (sleepT==1) { ultrasonic.write(">PwrIdleCfg:1,1\r\n"); }
else if (sleepT==2) { ultrasonic.write(">PwrIdleCfg:1,2\r\n"); }
delay(300);
}
Im communicating with the serial device which is periodically going to sleep and cant receive commands while sleeping. So to change sleep time i wrote a function using strchrthat checks when sleep time was changed and to keep sending the change command if it has not yet happened. This function works but from time to time it crash my arduino that then restarts.
Any idea why ?
It’s a learning curve…
We’re not trying to be unhelpful, but a fork and a knife are both cutlery, yet do quite different things.
Sometimes you need to understand what you’re looking for - before pitching a solution.
The idea of ‘contains’ a string is quite different to ‘is the same as’…
read about both strchr, strcmp, and strstr… the function references explain the differences.
HINT:
‘x’ is a character constant
“xxx” is a string literal (constant). Typically stored in an array.
Thank you all for your explanations! I think i manage to solve it with strstr().
I believe there were some memory issues as well, that should also be fixed with last update. Fingers crossed.