Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By WanaGo
#17796 Hello,

I have a case where some code is taking more than 1second ( I think ) to execute, and its causing the wdt to reset.

I remember seeing somewhere some sort of command you can put in to give time back to the WiFi which I guess would reset this wdt, but I cannot find it.

putting a delay(1) solves the problem too, but I dont 100% know why. Im guessing delay is not blocking like in an Arduino, and it gives time back to the system or something and just stops executing the sketch?

Some info would be great

Thanks
User avatar
By WanaGo
#17797 Ah found it.
Was in the github readme

Timing and delays

millis and micros return the number of milliseconds and microseconds elapsed after reset, respectively.

delay pauses the sketch for a given number of milliseconds and allows WiFi and TCP/IP tasks to run. delayMicroseconds pauses for a given number of microseconds.

Remember that there is a lot of code that needs to run on the chip besides the sketch when WiFi is connected. WiFi and TCP/IP libraries get a chance to handle any pending events each time the loop() function completes, OR when delay(...) is called. If you have a loop somewhere in your sketch that takes a lot of time (>50ms) without calling delay(), you might consider adding a call to delay function to keep the WiFi stack running smoothly.

There is also a yield() function which is equivalent to delay(0). The delayMicroseconds function, on the other hand, does not yield to other tasks, so using it for delays more than 20 milliseconds is not recommended.