As the title says... Chat on...

User avatar
By Eyal
#77480 I have an app (using esp8266) that has this flow:
- set wifi static IP
- read many sensors (ow, i2c)
- wait for wifi GOT_IP (register eventmon with idle app)
- send report to a server

This used to work nicely, the 'wait' part was around 60ms. Earlier this year I updated the fw and the wait went up to around 800ms. This is a significant issue as the device runs from battery.

I now decided to look into the issue and noticed that when the ow connection was bad, and the 'read' was fast (80ms) the wait was 60ms, but when the ow read worked (taking 220ms) the wait was longer (800ms).

I enabled logging and saw that what actually happens during the 'wait' is a DISCONNECT (reason AUTH_EXPIRE) quickly followed by a successful reconnection (GOT_IP). It seems that if the app is kept busy (reading ow and i2c devices) the wifi engine experiences some kind of internal time-out.

Is it possible that hogging the CPU causes wifi to fail? If so, how does one deal avoid the failure?

TIA
User avatar
By marcelstoer
#77492 It's hard to tell without seeing any code. I suggest you try our GitHub issues list and a provide an absolutely minimal but complete example that exhibits this behavior. However, it might as well be an issue in the SDK from Espressif; we've seen some issues lately on both NodeMCU and Arduino core.
User avatar
By Eyal
#77493 I plan to do this. I already have a small app that tracks the progress of wifi and I will add a busy loop and see if at some point it leads to a disconnect.

[later] The sample is now attached. Took me a while to notice the error at the top saying that I cannot upload lua files....

At the top I nominate my static IP etc. The module was separately initialised with the proper SSID/pwd and auto_connect was set.

The startup_delay and busy_time are important, and are fine tuned to show the problem.
Looks like some internal timing issue.

Launching dowifi from inside an alarm is required to show the problem. I expect that this gives the wifi engine time to proceed but then the delay in dowifi starves the engine leading to a failure.

My module is a bare modern esp-07 with 1MB flash. No other device is attached and it runs directly from a LiFePO4 battery.

A sample output follows. At times the reason is 4.
Code: Select allNodeMCU 2.2.0.0 build dev-20180730-1334-62f48fe-1m-all powered by Lua 5.1.4 on SDK 2.2.1(6ab97e9)
0.169650 sta.status=1 sta.getip=192.168.2.73/255.255.255.0
0.171354 startup delayed 50ms
> 0.230532 busy delay 1000ms
1.237743 delay done
1.244741 registering eventmons
1.276882 DISCONNECTED reason 2
1.286543 retry 1
1.415341 STA_CONNECTED
1.433145 STA_GOT_IP
1.443628 have connection sta.status=5 sta.getip=192.168.2.73/255.255.255.0
1.454473 deep sleep 2s


HTH

[much later] I added some yields where I do the readings (6 ow devices and one i2c) and wifi is now often connecting quickly.

The yield is a 1ms alarm replacing a direct function call. I need to experiment with different timeouts, but will let it run this way for a day or two.

I still want to understand what causes the disconnects.
Attachments
code sample
(2.72 KiB) Downloaded 525 times