Arduino icon indicating copy to clipboard operation
Arduino copied to clipboard

Rebooting when joining WiFi

Open sticilface opened this issue 11 years ago • 48 comments

Using latest version 1.6.1-esp8266-1-1054-g3183c7c

I have a project that has been working fine (at least booting and joining wifi.) now it crashes upon trying to join wifi...

NORMAL ACCESS MODE ENABLED
Scanning for Networks

Joining Wifi Network....
 ets Jan  8 2013,rst cause:2, boot mode:(3,7)

load 0x4010f000, len 1464, room 16 
tail 8
chksum 0x7a
csum 0x7a
e���(�SQS�(RQ�)HT�)SHHHC���r

Not sure what to do next, to help? I should add that the same code compiled on a previous IDE works fine.

sticilface avatar Jun 15 '15 14:06 sticilface

I call wifi mode before, no change.

my way round it, is to hold down reset for a few seconds.. then just blast reset about 5 times in a row.. then it usually works.

im doubtful that it is a code issue on my end, as it was working just fine on this ESP for weeks. stopped working the moment i started using the IDE that makes one binary... and my code works fine on other ESPs so far. This is my test ESP though so it gets used the most!

sticilface avatar Jun 19 '15 07:06 sticilface

You could try to remove power, too.

holgerlembke avatar Jun 19 '15 07:06 holgerlembke

Try call WiFi.disconnect() first. Simple mode change does not work for me - ESP still connect via saved config. As "last chance" try full erase - write blank512k.bin from SDK via esptool.

Is this ESP (test) on breadboard? May be electrical/pull-up issue?

PS: I have build latest git version an hour ago and have no issues neither with wifi nor with malloc(0)

av1024 avatar Jun 19 '15 08:06 av1024

adding WiFi.disconnect() makes no difference

sticilface avatar Jun 19 '15 11:06 sticilface

I have an constant reboots with git versions now. There is no reboots with older (from May 28, two binary file uploaded) build.

  • Using build from May 16:
    • got exception(28) with debug message 'beacon timeout' while wifi router turns off
    • constantly reboots by wdt with same exception while wifi router still off
scandone
Fatal exception (28):
epc1=0x402090ce, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000000, depc=0x00000000
 ets Jan  8 2013,rst cause:2, boot mode:(1,6)
 ets Jan  8 2013,rst cause:4, boot mode:(1,6)
wdt reset
  • Latest git version (1803f3052a) with same Exception(28) but more detailed output:
scandone
Fatal exception (28):
epc1=0x40209212, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000000, depc=0x00000000

Exception (28):
epc1=0x40209212 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

ctx: sys 
sp: 3ffffd30 end: 3fffffb0 offset: 01a0

>>>stack>>>
3ffffed0:  feefeffe 3ffec078 3ffe9874 40209185  
3ffffee0:  3fff36dc 3fff4558 3fff3344 4020807e  
3ffffef0:  40233493 00000000 00000004 402334a6  
3fffff00:  00000001 666b6469 3fff0061 3fff314c  
3fffff10:  00000001 4021ad0e 3fff4558 3fff4558  
3fffff20:  00000000 00000005 c9000000 40233432  
3fffff30:  3fff4558 40233428 00000000 000000ff  
3fffff40:  402318a7 3fff4558 4021e23d 3ffec330  
3fffff50:  00000000 40231663 3fff36f8 00000000  
3fffff60:  3fffdcb0 3fff36f8 00000000 3fffdcb0  
3fffff70:  40231af8 4021932b 3ffec078 40201018  
3fffff80:  4021932b 40219348 3fffdab0 3ffea170  
3fffff90:  4021937e 3fffdab0 3ffeb1bc 40201dd1  
3fffffa0:  40000f49 40000f49 3fffdab0 40000f49  
<<<stack<<<

 ets Jan  8 2013,rst cause:2, boot mode:(3,7)

load 0x4010f000, len 1464, room 16 
tail 8
chksum 0x7a
csum 0x7a
e

av1024 avatar Jun 22 '15 08:06 av1024

From the output, it looks like a null pointer exception inside the system libraries. But I need your .elf file to see where exactly. Could you please upload the elf output file which corresponds to the latest output?

igrr avatar Jun 22 '15 08:06 igrr

FYI, I've rebuild (via old 2-file version because it is "working") main loop with a lot of debug prints and it looks like wifi system reconnecting code does not update WDT. I can see a lot of "scandone/reconnecitng to ..." debug messages without returning back to loop(). For now I use Ticker as software watchdog: invoke reset() after [30] seconds and ESP rebooted by Ticker..

Log for attached elf:

#12203 MAIN/setup: .bmp.begin
#12214 MAIN/setup: .ds.begin
#12277 MAIN/setup: .ds.rescan
Found 1 1-wire sensors
28-56b6c7020000a1
#12346 MAIN/setup: dht.begin
f 0,  = WIFI Settings =
Mode: STA
PHY mode: N
Channel: 1
AP id: 0
Status: 1
Auto connect: 1
SSID (5): idkfa
Passphrase (10): *********
BSSID set: 0
 MAC: 18:fe:34:9e:82:d0
 IP: 0.0.0.0
 SSID: idkfa (31dBm), channel: 1
 Status: DISCONN
 * Telnet started.
#12747 MAIN/setup:  mqtt...
#12771 MAIN/setup: .mqtt.begin
#12774 MAIN/setup: cli.add
 * Register callback for 'print'
 * Register callback for 'reset'
 * Register callback for 'restart'
 * Register callback for 'monitor'
 * Register callback for 'eeprom'
 * Register callback for 'debug'
 * Register callback for 'esp'
 * Register callback for 'wifi'
 * Register callback for 'mqtt'
 * Register callback for 'offs'
 * Register callback for 'telnet'
 * Register callback for 'ntp'
 * Register callback for 'led'
 * Register callback for 'out'
#13788 MAIN/loop: 
#13790 MAIN/loop: wifi_connect(10s)
scandone
Fatal exception (28):
epc1=0x4020956e, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000000, depc=0x00000000

Exception (28):
epc1=0x4020956e epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

ctx: sys 
sp: 3ffffd30 end: 3fffffb0 offset: 01a0

>>>stack>>>
3ffffed0:  3fff1fe0 00008640 3ffe998c 402094e1  
3ffffee0:  3fff37fc 3fff4678 3fff3464 402083da  
3ffffef0:  402337ef 00000000 00000004 40233802  
3fffff00:  00000001 666b6469 3fff0061 3fff326c  
3fffff10:  00000001 4021b06a 3fff4678 3fff4678  
3fffff20:  00000000 00000005 c9000000 4023378e  
3fffff30:  3fff4678 40233784 00000000 000000ff  
3fffff40:  40231c03 3fff4678 3fff2008 3ffee168  
3fffff50:  00000000 402319bf 3fff3818 00000000  
3fffff60:  3fffdcb0 3fff3818 00000000 3fffdcb0  
3fffff70:  40231e54 3ffec6f0 000000f5 3ffec6f0  
3fffff80:  40219687 3fff2008 3fffdab0 3ffea290  
3fffff90:  402196da 3fffdab0 00000000 3fffdcc0  
3fffffa0:  40000f49 40000f49 3fffdab0 40000f49  
<<<stack<<<

 ets Jan  8 2013,rst cause:2, boot mode:(1,6)


 ets Jan  8 2013,rst cause:4, boot mode:(1,6)

wdt reset

Hmmm... can't attach file... https://www.dropbox.com/s/rwi1nf7cznngey7/sens_v2.cpp.elf?dl=0

av1024 avatar Jun 22 '15 08:06 av1024

These stack traces are a real life saver!

igrr avatar Jun 22 '15 10:06 igrr

Ok. Both of exception and returning to main loop() seems to be solved.

av1024 avatar Jun 22 '15 11:06 av1024

Yet another exception. As from Imroy's issue 8:

  • stop mqtt broker
  • turn off Wifi router (was lock-down esp)
  • got exception with 'beacon timeout' debug output

Possibly is enough to turn off wifi router only

#1051615 MAIN/loop:  loop60 connected
.oobeacon timeout
rm 0
pm close 7 0 0/1048432360
f 0, 
ctx: cont 
sp: 3ffeaf20 end: 3ffeb2b0 offset: 01b0

>>>stack>>>
3ffeb0d0:  00000002 3ffe9d48 3ffe9d20 4020a663  
3ffeb0e0:  02e7a8c0 40101d1c 00000000 00000003  
3ffeb0f0:  3ffe3710 0037025b 3ffe9d48 3ffe9d48  
3ffeb100:  00000000 3ffe9d20 3ffeb150 4020a734  
3ffeb110:  3fff4ce8 00000003 00000000 3ffeb1f0  
3ffeb120:  3ffeb150 3ffe9d48 3ffe9d20 4020a914  
3ffeb130:  4020fae9 3ffe9d20 3ffeb174 4020fc90  
3ffeb140:  00000001 3ffeb1fc 3ffe9d20 4020a9b7  
3ffeb150:  3ffe93b0 00000001 00000101 3fff5070  
3ffeb160:  0000000e 0000000e 3fff6230 00000016  
3ffeb170:  00000016 3fff4dd0 00000003 00000003  
3ffeb180:  3fff5090 00000000 00000000 3fff50a8  
3ffeb190:  00000000 00000000 0000000f 3fff5050  
3ffeb1a0:  00000003 00000003 3fff50c0 00000016  
3ffeb1b0:  00000016 40101b8f 3ffeb1f0 4020fba8  
3ffeb1c0:  00000000 3ffeb208 3ffeb1f0 4020fbe0  
3ffeb1d0:  3ffe8d5f 00000064 3ffe9d1c 3ffe9db8  
3ffeb1e0:  3ffe9d20 00000000 3ffe9d1c 40203f77  
3ffeb1f0:  3fff4b48 00000003 00000003 3fff4d58  
3ffeb200:  00000016 00000016 3fff4cc8 0000000e  
3ffeb210:  0000000e 3fff5028 00000016 00000016  
3ffeb220:  3ffe9da0 00000001 60000000 40201eb4  
3ffeb230:  00ff0000 ff000000 3ffeb308 00000000  
3ffeb240:  3ffe9d1c 3ffe9974 3ffeb308 40207ff1  
3ffeb250:  3ffe9260 00000000 000003e8 00000003  
3ffeb260:  00000000 00000000 0000000d 0000000d  
3ffeb270:  0000000b 00000000 00000000 40102361  
3ffeb280:  40201e3d 00000000 00000000 3ffeb2dc  
3ffeb290:  3fffdc20 00000000 3ffeb2d4 40201e9a  
3ffeb2a0:  00000000 00000000 3ffea290 40100450  
<<<stack<<<

 ets Jan  8 2013,rst cause:2, boot mode:(3,7)

load 0x4010f000, len 1464, room 16 
tail 8
chksum 0x7a
csum 0x7a

Updated elf here: https://www.dropbox.com/s/rwi1nf7cznngey7/sens_v2.cpp.elf?dl=0

UPD: Got about 3000 exception lines when wifi router turned on but not yet ready (like 5sec up to wdt reset)

Fatal exception (0): 
epc1=0x4010f280, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000000, depc=0x00000000
...

av1024 avatar Jun 22 '15 12:06 av1024

The first one you posted is a WDT reset when code spins inside PubSubClient::send_reliably -> PubSubClient::wait_for(uchar,ushort) function. I think i have added a workaround for such a use case but apparently it got broken. I'll check that, but meanwhile you can add yield(); into the while loop inside PubSubClient::wait_for.

As for the second issue, it's a mysterious one, because 0x4010f280 is an address inside the bootloader. I'll try to reproduce that.

igrr avatar Jun 22 '15 13:06 igrr

As for me it is not good idea to use delayMicroseconds in loop... I think delay(1) instead of delayMicroseconds(100) enough here. (may be I'm wrong and >=1ms is too long here)

... Replacing delayMicrosecond by delay(1) solves first issue. (I'll create and issue on @Imroy 's project)

the second really was mysterious )) because I can't reproduce it too

av1024 avatar Jun 22 '15 13:06 av1024

delay(1) is too much a delay here, yield(); should take less time.

if you ever find out how to reproduce the second one reliably, please let me know — i'm sure i have seen such behaviour once or twice but wasn't able to isolate the issue.

igrr avatar Jun 22 '15 13:06 igrr

My module does this repeatedly. crashes when joining the wifi, and before the setup is completed. What usually fixes it (and this is what i've been doing all weekend) is to reboot the module, 5-6 times, by grounding rst, very quickly. this then i'd say 90% of the time. fixes it. Its weird, but i do to know what could cause this behaviour.

sticilface avatar Jun 22 '15 13:06 sticilface

@sticilface the change in 1c8b52b fixed this for @av1024, perhaps it will also help in your case?

igrr avatar Jun 22 '15 13:06 igrr

ah sorry, I shall give it a go!

sticilface avatar Jun 22 '15 13:06 sticilface

delay(1) is too much a delay here, yield(); should take less time.

yield() also work ok. (I'm not sure why 100us delay needed while waiting for network i/o)

... possibly isolate second issue. this code prints error message and make crash after reboot:

wifi_bad_cnt ++;
    if (wifi_bad_cnt > WIFI_REBOOT_COUNT) {
      Serial.println("Too many connect fails. Try reboot.");
      Serial.flush();
      WiFi.disconnect();
      delay(1000);
      ESP.reset();
    }
Too many connect fails. Try reboot.
scandone

 ets Jan  8 2013,rst cause:4, boot mode:(3,7)

wdt reset
load 0x4010f000, len 1464, room 16 
tail 8
chksum 0x7a
csum 0x7a
Fatal exception (0): 
epc1=0x4010f280, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000000, depc=0x00000000

Moreover for now the CLI command reset now get the same error. The "reset" handler is:

if (s == "reset") {
    prn.println(F("\n\r\n\r *** RESET ***\n\r"));
    delay(1000);
    ESP.reset();
  }

av1024 avatar Jun 22 '15 13:06 av1024

Ah right. Looks like ESP.reset() doesn't work at all. Please use

ESP.restart();
delay(5000);

as a workaround until i push a fix for that issue.

igrr avatar Jun 22 '15 14:06 igrr

Ok. I already have 'restart' handler and it work (even w/o delay)

av1024 avatar Jun 22 '15 14:06 av1024

Guys, this is excellent work. I have this issue with PubSubClient and thought I was going mad. Adding the Serial.setDebugOutput(true); function gave me a nice clear indication it is not a fatal exception error for me. The problem for me only occurs now if MQTT has established a connection to the broker and subscribed to channels. If I take down my wireless router that the ESP8266 is connected to at this point I get the WDT reset condition. I am thinking it could be at that moment the class try's to do a keep alive type ping and bombs out. Please let me know anyone when a fix has been found.

Thanks Danbicks wdt 1

danbicks avatar Jun 24 '15 19:06 danbicks