- Wed Oct 24, 2018 7:35 am
#78842
Okay, some background theory here.
The ESP is (at least in hardware) NOT the same as an ATMEL (as used in an Arduino).
Where the ATMEL controller only has 1 flow of code to worry about, the ESP has to keep two flows (or "Processes") of code running "At the same time".
One "Process" is responsible for the WiFi-stack (everything related to communicating over WiFi) and this process is "Hidden", while the other "Process" is available to you, the programmer: in here your sketch is stored.
The WiFi process has a timer (the
"Watchdog Timer") built in that will be set to 0 when the process is given time to execute.
However every clock-tick the WiFi process is
not running, this timer gets incremented.
As long as the timer doesn't reach a certain value (the "Time-out value"), the WiFi-stack is happy and everything is fine.
But... if the timer
does reach the time-out value, the watchdog timer will trip and a watchdog timer reset (WDT) will occur (the message you see in the log).
Since the Arduino core for the ESP isn't
a pre-emptive multitasker (and thus not able to automagically run both the WiFi-process as the process of your sketch at the same time), help from your code is needed to keep both processes running simultaneously.
This is done by regularly handing control over to the WiFi-process from within your sketch, by issuing a "yield()" command.
Since (from a µC's perspective) pausing your own code is a waste of time (which can be also used to let the WiFi-process do its thing), you can also use the delay() command.
Effectively even delay(0) would be okay, but since delay() is often used in "Standard" code to pause for a while, behind the scenes it's (kind of) transposed over the yield() command, to give the WiFi-stack as much "Air to breathe" as possible.
So, back to your sketch:
- It's not necessary to issue 5 second delays.
- Be sure that the ports defined in your sketch actually reflect reality (i.e. double-check that a sensor, motor, LED or display is actually correctly connected to said port and working).
- Don't use tight loops (like while(1);) without giving processing time to the WiFi stack (instead use while(1) { yield() };)
- Always copy and paste the exact sketch and resulting log to this forum; do not report back with "Y results into almost the same as X", since it really doesn't.
Please see my signature about assuming things. - Last but not least: read, read, try and try again and when in doubt: just ask
Assumption is the mother of all f*ckups. At least: that's what I'm assuming.