tzapu / WiFiManager

ESP8266 WiFi Connection manager with web captive portal
http://tzapu.com/esp8266-wifi-connection-manager-library-arduino-ide/
MIT License
6.63k stars 1.98k forks source link

wifiManager.autoConnect crashes ESP on MDNS.begin with Fatal exception 28(LoadProhibitedCause): #537

Open chadham opened 6 years ago

chadham commented 6 years ago

Basic Infos

Hardware

WiFimanager Branch/Release: Development Version 0.12.0 (per Arduino Library Manager) Hardware: NodeMcu 1.0 (ESP12-E module)

Core Version: Version 0.12.0 (per Arduino Library Manager) Downloaded the latest git and confirmed issue on it

Description

Problem description: If wifiManager.autoconnect is used to connect the esp8266, it crashes when MDNS.begin(..) is called

Settings in IDE

Module: NodeMcu 1.0 (ESP12-E module)

Additional libraries: ESP8266mDNS.h

Sketch

#include <Arduino.h>
#include <ESP8266mDNS.h>
#include <WiFiManager.h>

WiFiManager wifiManager;

void setup() {
  Serial.begin(115200);
  Serial.setDebugOutput(true);
  WiFi.disconnect();
  wifiManager.autoConnect("DEVICE", "123456789");  //THIS CAUSES MNDS.being to crash
  /* // WORKS IF YOU USE THIS CODE BLOCK INSTEAD
  WiFi.begin("router", "password1234"); 
  while (WiFi.status() != WL_CONNECTED) { 
    Serial.print("."); 
    delay(1000);
  }
  */
  Serial.print("\nConnected to "); Serial.print(WiFi.SSID()); Serial.print(" ,IP address is "); Serial.print(WiFi.localIP()); Serial.print(" and signal strength is "); Serial.println(WiFi.RSSI());

  if (!MDNS.begin("hello")) { Serial.println("Error setting up MDNS responder!"); }
  else { Serial.println("Started MDNS"); }

}

void loop() {}

Debug Messages

USING WIFIMANAGER.AUTOCONNECT

rl�d⸮⸮|�⸮l⸮|⸮$⸮c|⸮⸮⸮⸮;⸮c⸮c⸮⸮g'⸮lng⸮⸮⸮bx⸮⸮l;l{lx⸮o⸮⸮d⸮⸮#g⸮|d⸮⸮#⸮⸮no⸮�$⸮⸮l ⸮ogl n{⸮⸮⸮gc⸮ls⸮⸮n#⸮d⸮⸮⸮c⸮l ⸮⸮g⸮*WM: 
*WM: AutoConnect
bcn 0
del if1
mode : sta(2c:3a:e8:43:17:f7)
*WM: Connecting as wifi client...
*WM: Using last saved values, should be faster
*WM: Connection result: 
*WM: 0
mode : sta(2c:3a:e8:43:17:f7) + softAP(2e:3a:e8:43:17:f7)
add if1
dhcp server start:(ip:192.168.4.1,mask:255.255.255.0,gw:192.168.4.1)
bcn 100
*WM: SET AP STA
*WM: 
*WM: Configuring access point... 
*WM: DEVICE
*WM: 123456789
*WM: AP IP address: 
*WM: 192.168.4.1
*WM: HTTP server started
add 1
aid 1
station: b0:70:2d:82:d3:90 join, AID = 1
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Request redirected to captive portal
*WM: Handle root
scandone
*WM: Scan done
*WM: DUP AP: Router
*WM: DUP AP: Router
*WM: HP-Print-06-LaserJet 200
*WM: -40
*WM: Router
*WM: -54
*WM: Iro
*WM: -66
*WM: ASUS
*WM: -89
*WM: Sent config page
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Request redirected to captive portal
*WM: Handle root
*WM: WiFi save
*WM: Sent wifi save page
*WM: Connecting to new AP
*WM: Connecting as wifi client...
scandone
switch to channel 6
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 5
cnt 

connected with Router, channel 6
dhcp client start...
ip:10.0.1.111,mask:255.255.255.0,gw:10.0.1.1
*WM: Connection result: 
*WM: 3
station: b0:70:2d:82:d3:90 leave, AID = 1
rm 1
bcn 0
del if1
pm open,type:2 0
mode : sta(2c:3a:e8:43:17:f7)
sl

**Connected to Router ,IP address is 10.0.1.111 and signal strength is -59
Fatal exception 28(LoadProhibitedCause):**
epc1=0x40225ba3, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000098, depc=0x00000000

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

ctx: cont 
sp: 3fff0670 end: 3fff0aa0 offset: 01a0

>>>stack>>>
3fff0810:  fffffffe 00000000 4010100f 3fff284c  
3fff0820:  4021ffd0 3fff1d5c 3fff145c 3fff3044  
3fff0830:  3fff2dfa 40231e47 3fff284c 3fff1344  
3fff0840:  00000000 40220c83 3ffee1ec 40106b9c  
3fff0850:  3fff2dfa 40104456 3fff1d5c 3fff3044  
3fff0860:  0000002e 3fff0f00 3fff1d5c 401043d1  
3fff0870:  3fff2db4 3ffe973d 3fff184f 40222a3f  
3fff0880:  3ffee8f8 3ffee9f0 40224b34 3fff0f35  
3fff0890:  3fff0f00 3fff0f00 3fff2db4 4010453d  
3fff08a0:  40211f93 3fff2db4 3fff2dfa 40211f9c  
3fff08b0:  00000008 3fff08e0 4022451b 3ffeea10  
3fff08c0:  3ffee9f0 40224b34 3ffee8f8 3fff2e08  
3fff08d0:  3fff2db4 3fff3368 3fff0f00 40218031  
3fff08e0:  005e0001 4000fb00 60000200 3fff0990  
3fff08f0:  00000018 3fff3368 3fff2db4 40218ab8  
3fff0900:  40222b38 3ffee1ec 00000000 00000000  
3fff0910:  3fff0984 00000001 00000000 00000002  
3fff0920:  3fff0e60 00000004 3ffe8a81 40219130  
3fff0930:  4023a9ba 3ffe8a95 3ffe8a81 3fff3364  
3fff0940:  00000000 3fff2db4 3fff2e20 40218af8  
3fff0950:  3fff0f00 3fff0980 00000004 3fff3364  
3fff0960:  00000016 3fff0f00 3fff3364 40218289  
3fff0970:  3fff0f00 3fff0980 00000004 40211ff8  
3fff0980:  00000494 0104a8c0 3fff105c 40212034  
3fff0990:  3fff3368 3fff0f00 3fff2ebc 4021835a  
3fff09a0:  3fff3314 3ffef76c 3fff0a50 00000020  
3fff09b0:  3fff0a1c 3fff0f00 3fff3364 40218533  
3fff09c0:  3fff0a1c 3ffe98d4 3fff0f00 402185bf  
3fff09d0:  3fff0900 00000001 3fff0a50 00000001  
3fff09e0:  3ffef724 3ffef768 3ffef724 402025ce  
3fff09f0:  00000000 3ffef768 3fff0a40 40100690  
3fff0a00:  3ffef98c 000003af 00000000 4020ad78  
3fff0a10:  00000000 3ffef768 3ffef750 fb0000e0  
3fff0a20:  00000000 3ffef768 3ffef724 3ffefa70  
3fff0a30:  00000000 3ffef768 3ffef724 4020386a  
3fff0a40:  3fff2d3c 3fff0a70 40202234 402026f0  
3fff0a50:  00000000 00000000 3ffef9b0 4020a1e0  
3fff0a60:  3fffdad0 3ffef768 3ffef9b0 40202128  
3fff0a70:  3ffe93b8 6f01000a 00000000 feefeffe  
3fff0a80:  feefeffe 00000000 3ffefa68 4020ae84  
3fff0a90:  feefeffe feefeffe 3ffefa80 40100710  
<<<stack<<<

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

load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
v4ceabea9
~ld
scandone
*WM: 
*WM: AutoConnect
*WM: Connecting as wifi client...
*WM: Using last saved values, should be faster
*WM: Connection result: 
*WM: 0
mode : sta(2c:3a:e8:43:17:f7) + softAP(2e:3a:e8:43:17:f7)
add if1
dhcp server start:(ip:192.168.4.1,mask:255.255.255.0,gw:192.168.4.1)
bcn 100
*WM: SET AP STA
*WM: 
*WM: Configuring access point... 
*WM: DEVICE
*WM: 123456789
*WM: AP IP address: 
*WM: 192.168.4.1
*WM: HTTP server started

Works fine when using WiFi.being(said, password)

Here is that output

1384, room 16 tail 8 chksum 0x2d csum 0x2d v4ceabea9 ~ld ;l�d⸮⸮|�⸮$⸮| ⸮ $⸮c|ǃ⸮⸮{⸮c⸮ c⸮⸮og⸮l'o⸮⸮⸮ #x⸮⸮l;l{lp⸮n⸮ ⸮ d⸮⸮ co⸮|l⸮ ⸮c⸮⸮'o⸮�d⸮⸮$⸮no$'{⸮⸮⸮gc⸮ls⸮⸮' c ⸮d܃⸮c⸮l`⸮⸮g⸮scandone ...scandone state: 0 -> 2 (b0) .state: 2 -> 3 (0) state: 3 -> 5 (10) add 0 aid 5 cnt

connected with Router, channel 6 dhcp client start... ip:10.0.1.111,mask:255.255.255.0,gw:10.0.1.1

Connected to Router ,IP address is 10.0.1.111 and signal strength is -53 Started MDNS

tablatronix commented 6 years ago

Well for one you are removing wifi credentials every time you reboot WiFi.disconnect(); deletes credentials !

tablatronix commented 6 years ago

cannot reproduce with any combination of versions

chadham commented 6 years ago

Wifi.disconnect call was intentional as I want to force wifiManager to load each time (for testing this issue, will be removed once fixed).

I stripped it down to the minimal code per above, and am able to reproduce on 2 NodeMCU's to eliminate (or at least reduce) the chance of flash corruption on one.

Also deleted and downloaded latest version from here.

Any chance Im on a older firmware version on the nodeMCU? How do I check the firmware version?

tablatronix commented 6 years ago

What is your esp core?

chadham commented 6 years ago

I’m not sure. It’s a stock wemos nodemcu dev board. How do I tell what the core version is?

tablatronix commented 6 years ago

are you using esp staging, or 2.4.0 ?

chadham commented 6 years ago

Im sorry, but I don't understand the question. If you are asking about the WifiManager version, its whatever you get when you download the library from the clone or download button.

chadham commented 6 years ago

its 2.4.0

tablatronix commented 6 years ago

k

tablatronix commented 6 years ago

still cannot reproduce, works for me

*WM: Connecting as wifi client...
scandone
switch to channel 11
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 1

connected with SSID, channel 11
dhcp client start...
cnt 
ip:10.80.21.143,mask:255.255.240.0,gw:10.80.16.1
*WM: Connection result: 
*WM: 3
station: dc:0c:5c:e2:24:41 leave, AID = 1
rm 1
bcn 0
del if1
pm open,type:2 0
mode : sta(2c:3a:e8:43:1f:5e)

Connected to SSID ,IP address is 10.80.21.143 and signal strength is -65
Started MDNS
tablatronix commented 6 years ago

If you use arduino ide you can install esp exception decoder tool and decode that exception. Also erase with esptool.

Not sure what else to suggest

chadham commented 6 years ago

Still happening. Here is the stack trace

I don't know who David is and why its trying to access /home/david/... right after MDNSResponder::_listen()

and the last Serial..println I get is after the MDNS.begin call

Any idea what to make of this..?

*EDITED with trace from test harness (vs main code line) Decoding 33 results 0x40220184: ieee80211_output_pbuf at ?? line ? 0x40104456: glue2esp_linkoutput at /home/david/dev/esp8266/origin/tools/sdk/lwip2/builder/glue-esp/lwip-esp.c line 292 0x401043d1: glue2esp_linkoutput at /home/david/dev/esp8266/origin/tools/sdk/lwip2/builder/glue-esp/lwip-esp.c line 263 0x4010453d: new_linkoutput at /home/david/dev/esp8266/origin/tools/sdk/lwip2/builder/glue-lwip/lwip-git.c line 240 0x40212147: ethernet_output at /home/david/dev/esp8266/origin/tools/sdk/lwip2/builder/lwip2-src/src/netif/ethernet.c line 305 0x40212150: ethernet_output at /home/david/dev/esp8266/origin/tools/sdk/lwip2/builder/lwip2-src/src/netif/ethernet.c line 305 0x401051da: os_printf_plus at ?? line ? 0x40232f26: pp_attach at ?? line ? 0x402181e5: etharp_output_LWIP2 at /home/david/dev/esp8266/origin/tools/sdk/lwip2/builder/lwip2-src/src/core/ipv4/etharp.c line 893 0x40218c6c: ip4_output_if_opt_src at /home/david/dev/esp8266/origin/tools/sdk/lwip2/builder/lwip2-src/src/core/ipv4/ip4.c line 962 0x402192e4: mem_malloc at /home/david/dev/esp8266/origin/tools/sdk/lwip2/builder/lwip2-src/src/core/mem.c line 136 0x40106c91: __wrap_spi_flash_read at /Users/mchadha/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.0/cores/esp8266/core_esp8266_phy.c line 267 0x40248d10: sleep_reset_analog_rtcreg_8266 at ?? line ? 0x40218cac: ip4_output_if_opt at /home/david/dev/esp8266/origin/tools/sdk/lwip2/builder/lwip2-src/src/core/ipv4/ip4.c line 788 0x4021843d: igmp_send at /home/david/dev/esp8266/origin/tools/sdk/lwip2/builder/lwip2-src/src/core/ipv4/igmp.c line 570 0x402121ac: do_memp_malloc_pool at /home/david/dev/esp8266/origin/tools/sdk/lwip2/builder/lwip2-src/src/core/memp.c line 231 0x402121e8: memp_malloc at /home/david/dev/esp8266/origin/tools/sdk/lwip2/builder/lwip2-src/src/core/memp.c line 231 0x4021850e: igmp_lookup_group at /home/david/dev/esp8266/origin/tools/sdk/lwip2/builder/lwip2-src/src/core/ipv4/igmp.c line 570 0x402186e7: igmp_start_timer at /home/david/dev/esp8266/origin/tools/sdk/lwip2/builder/lwip2-src/src/core/ipv4/igmp.c line 570 : (inlined by) igmp_joingroup_netif at /home/david/dev/esp8266/origin/tools/sdk/lwip2/builder/lwip2-src/src/core/ipv4/igmp.c line 521 0x40218773: igmp_joingroup at /home/david/dev/esp8266/origin/tools/sdk/lwip2/builder/lwip2-src/src/core/ipv4/igmp.c line 570 0x40202542: MDNSResponder::_listen() at /Users/mchadha/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.0/libraries/ESP8266mDNS/ESP8266mDNS.cpp line 396 0x40100690: free at /Users/mchadha/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.0/cores/esp8266/umm_malloc/umm_malloc.c line 1737 0x4020af2c: operator delete(void) at /Users/mchadha/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.0/cores/esp8266/abi.cpp line 84 0x402037de: MDNSResponder::begin(char const*) at /Users/mchadha/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.0/libraries/ESP8266mDNS/ESP8266mDNS.cpp line 396 0x402021a8: _M_manager at /Users/mchadha/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.0/libraries/ESP8266mDNS/ESP8266mDNS.cpp line 396 0x40202664: operator() at /Users/mchadha/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.0/libraries/ESP8266mDNS/ESP8266mDNS.cpp line 396 : (inlined by) _M_invoke at /Users/mchadha/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/functional line 2071 0x4020a394: Print::println(int, int) at /Users/mchadha/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.0/cores/esp8266/Print.cpp line 87 0x40202110: setup at /Users/mchadha/Documents/Arduino/wifiandMDNStest/wifiandMDNStest.ino line 23 0x4020b038: loop_wrapper at /Users/mchadha/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.0/cores/esp8266/core_esp8266_main.cpp line 57 0x40100710: cont_norm at /Users/mchadha/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.0/cores/esp8266/cont.S line 109

tablatronix commented 6 years ago

Whats all that json stuff?

chadham commented 6 years ago

Replaced test harness stack above

tablatronix commented 6 years ago

This looks like an mdns error

chadham commented 6 years ago

Interesting question is why it works if I hardcode the ssid and password and fails if I connect through wifimanager

Sent from my iPhone

On Feb 22, 2018, at 2:30 PM, Shawn A notifications@github.com wrote:

This looks like an mdns error

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

tablatronix commented 6 years ago

We use webserver and dnsserver, we switch mode several times?

Try making sure the wifi is at the right state or a known state, before starting mdns, set mode etc.

I think there is a mdns debug flag in the files.

Not entirely sure whats going on here, but that stack seems far from wifimanager.

Another thing you can try put wifimanager in a different scope.

tablatronix commented 6 years ago

What lwip do you have selected in arduino?

chadham commented 6 years ago

Thanks, let me try checking the state.

Should I not assume that wifimanager.Connect blocks until WiFi is successfully setup?

Ie do u wait for connection success confirm before returning?

Sent from my iPhone

On Feb 22, 2018, at 2:36 PM, Shawn A notifications@github.com wrote:

We use webserver and dnsserver, we switch mode several times?

Try making sure the wifi is at the right state or a known state, before starting mdns, set mode etc.

I think there is a mdns debug flag in the files.

Not entirely sure whats going on here, but that stack seems far from wifimanager.

Another thing you can try put wifimanager in a different scope.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

tablatronix commented 6 years ago

Master, Yes by default, development has a lot more features to choose

tablatronix commented 6 years ago

Actually Lwip might only be an option in staging esp.

chadham commented 6 years ago

I’ll check WiFi state once back at my computer but if you only release on successful connection, count if that’s what is causing it. Stay tuned.

Sent from my iPhone

On Feb 22, 2018, at 3:16 PM, Shawn A notifications@github.com wrote:

Master, Yes by default, development has a lot more features to choose

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

chadham commented 6 years ago

What is lwip and how do I check?

Sent from my iPhone

On Feb 22, 2018, at 3:22 PM, Shawn A notifications@github.com wrote:

Actually Lwip might only be an option in staging esp.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

tablatronix commented 6 years ago

Have you tried esptool erase ?

chadham commented 6 years ago

No. You think it’s corruption in the flash? I tied two different esp’s, same issue.

Let me read up on esptool erase

Sent from my iPhone

On Feb 22, 2018, at 3:24 PM, Shawn A notifications@github.com wrote:

Have you tried esptool erase ?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

chadham commented 6 years ago

Looks complex .. a couple of quick questions..

  1. Im on a Mac, any issues running esptool?
  2. Once I erase, what do I need to do? Can I upload my sketch through Arduino's IDE as normal or do I need to put a boot loader or something else back on the ESP via ESP tool?
  3. Im assuming I can brick the device .. in which case I should take the time to understand what Im doing vs just doing it immediately..

appreciate any guidance

chadham commented 6 years ago

iwi variant is V2 Prebuilt

chadham commented 6 years ago

Checked and confirmed WiFi.Status() is reporting connected (3)

tablatronix commented 6 years ago

Esptool just erases flash Needs python Esptool.py -p /dev/tty/... erase_flash

Upload fine after

tablatronix commented 6 years ago

There are corruption bugs in 2.4.0

chadham commented 6 years ago

issue remains after erase_flash....

Not sure what else to try here...

tablatronix commented 6 years ago

maybe someone else will reproduce, I have not been able to. I even added mdns to the development branch and it worked fine.

tablatronix commented 6 years ago

do you get this on release as well?

https://github.com/tzapu/WiFiManager/releases/tag/0.12

tablatronix commented 6 years ago

maybe post to esp issues and someone will know what those are.

lwip ieee80211_output_pbuf etc

tablatronix commented 6 years ago

Is this still an issue?

MarcFontaine commented 6 years ago

MDNS did not work for me with 2.4.0 and work with 2.4.1

chadham commented 6 years ago

Yes :(

Sent from my iPhone

On Mar 14, 2018, at 9:55 AM, Shawn A notifications@github.com wrote:

Is this still an issue?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

tablatronix commented 6 years ago

Try 2.4.1 or staging maybe. Still not seeing this, could it be router specific?

myk3y commented 6 years ago

Im getting the same Exception 28 with MDNS and WiFiManager - 2.4.0 and 2.4.1 using the Arduino IDE.

If I bypass WiFiManager and hard-code my wireless setup, works fine with the same code.

Might try PlatformIO.

tablatronix commented 6 years ago

hmm sketch code?

tablatronix commented 6 years ago

There are 1 or 2 known issues with esp32 I have found, I have implemented some workarounds in the library, are you seeing this with the latest commits from development branch ? , have you pulled recently ?

I suspect this is a race condition issue , which makes sense since wm exposes it, and normal use does not, since wm switches modes back and forth alot.

myk3y commented 6 years ago

Not using an esp32 - esp12e based Wemos mini lite.

Remove wifimanager from the equation and the exact same code works perfectly

Regards,

Mike

On Apr 6, 2018, at 01:58, Shawn A notifications@github.com wrote:

There are 1 or 2 known issues with esp32 I have found, I have implemented some workarounds in the library, are you seeing this with the latest commits , have you pulled recently ?

I suspect this is a race condition issue , which makes sense since wm exposes it, and normal use does not, since wm switches modes back and forth alot.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

tablatronix commented 6 years ago

Sorry I meant esp8266