Page 2 of 3

Re: Can't connect WiFi after restart

Posted: Fri Apr 10, 2020 7:14 pm
by kgschlosser
I am having a very similiar issue. After I restarted my ESP32 I am no longer avle to connect to my WiFi. I have power cycled the ESP32 and also power cycled my WiFi and still no luck.


I tried using the example script. NOTE: I do not have my network secured with a WiFi password. I am connecting to an actual AP and not a router. There is no DHCP server on the AP. I am using a dedicated DHCP server.

Code: Select all


def connect():
    import network
    sta_if = network.WLAN(network.STA_IF)
    if not sta_if.isconnected():
        print('connecting to network...')
        sta_if.active(True)
        sta_if.connect('SSID')
        while not sta_if.isconnected():
            pass

    print('network config:', sta_if.ifconfig())

here is the log of me trying to connect

Code: Select all

ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:5008
ho 0 tail 12 room 4
load:0x40078000,len:10600
ho 0 tail 12 room 4
load:0x40080400,len:5684
entry 0x400806bc
I (533) cpu_start: Pro cpu up.
I (533) cpu_start: Application information:
I (533) cpu_start: Compile time:     Apr 10 2020 00:39:52
I (536) cpu_start: ELF file SHA256:  0000000000000000...
I (542) cpu_start: ESP-IDF:          v3.3.1
I (547) cpu_start: Starting app cpu, entry point is 0x4008363c
I (0) cpu_start: App cpu up.
I (558) heap_init: Initializing. RAM available for dynamic allocation:
I (564) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM
I (570) heap_init: At 3FFB6388 len 00001C78 (7 KiB): DRAM
I (576) heap_init: At 3FFB9A20 len 00004108 (16 KiB): DRAM
I (583) heap_init: At 3FFBDB5C len 00000004 (0 KiB): DRAM
I (589) heap_init: At 3FFCC818 len 000137E8 (77 KiB): DRAM
I (595) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (601) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (608) heap_init: At 400999CC len 00006634 (25 KiB): IRAM
I (614) cpu_start: Pro cpu start user code
I (297) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (130) modsocket: Initializing
I (130) pm_esp32: Frequency switching config: CPU_MAX: 240, APB_MAX: 240, APB_MIN: 240, Light sleep: DISABLED
240000000
MicroPython v1.12-357-g740946736 on 2020-04-10; ESP32 module with ESP32
Type "help()" for more information.
>>> import boot
I (5040) pm_esp32: Frequency switching config: CPU_MAX: 240, APB_MAX: 240, APB_MIN: 240, Light sleep: DISABLED
240000000
>>> boot.connect()
I (10620) wifi: wifi driver task: 3ffd2ea0, prio:23, stack:3584, core=0
I (21393) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (21393) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (21423) wifi: wifi firmware version: ac331d7
I (21423) wifi: config NVS flash: enabled
I (21423) wifi: config nano formating: disabled
I (21423) wifi: Init dynamic tx buffer num: 32
I (21423) wifi: Init data frame dynamic rx buffer num: 32
I (21433) wifi: Init management frame dynamic rx buffer num: 32
I (21443) wifi: Init management short buffer num: 32
I (21443) wifi: Init static rx buffer size: 1600
I (21443) wifi: Init static rx buffer num: 10
I (21453) wifi: Init dynamic rx buffer num: 32
connecting to network...
I (21553) phy: phy_version: 4102, 2fa7a43, Jul 15 2019, 13:06:06, 0, 0
I (21553) wifi: mode : sta (4c:11:ae:cc:0c:e4)
I (21553) wifi: STA_START
I (22403) wifi: new:<8,0>, old:<1,0>, ap:<255,255>, sta:<8,0>, prof:1
I (22403) wifi: state: init -> auth (b0)
I (23403) wifi: state: auth -> init (200)
I (23403) wifi: new:<8,0>, old:<8,0>, ap:<255,255>, sta:<8,0>, prof:1
I (23403) wifi: STA_DISCONNECTED, reason:2
I (25463) wifi: STA_DISCONNECTED, reason:205
I (25583) wifi: new:<8,0>, old:<8,0>, ap:<255,255>, sta:<8,0>, prof:1
I (25583) wifi: state: init -> auth (b0)
I (26583) wifi: state: auth -> init (200)
I (26583) wifi: new:<8,0>, old:<8,0>, ap:<255,255>, sta:<8,0>, prof:1
I (26583) wifi: STA_DISCONNECTED, reason:2
I (28643) wifi: STA_DISCONNECTED, reason:205
I (28763) wifi: new:<8,0>, old:<8,0>, ap:<255,255>, sta:<8,0>, prof:1
I (28763) wifi: state: init -> auth (b0)
I (29763) wifi: state: auth -> init (200)
I (29763) wifi: new:<8,0>, old:<8,0>, ap:<255,255>, sta:<8,0>, prof:1
I (29763) wifi: STA_DISCONNECTED, reason:2
I (31823) wifi: STA_DISCONNECTED, reason:205
I (31943) wifi: new:<8,0>, old:<8,0>, ap:<255,255>, sta:<8,0>, prof:1
I (31943) wifi: state: init -> auth (b0)
I (32943) wifi: state: auth -> init (200)
I (32943) wifi: new:<8,0>, old:<8,0>, ap:<255,255>, sta:<8,0>, prof:1
I (32943) wifi: STA_DISCONNECTED, reason:2
Everything was working without issue. then all of a sudden after a restart I am not able to connect no matter what I do. I have not flashed the ESP32 again. I will be trying this. The problem is 100% with MicroPython/ESP32 and is not my AP or my DHCP. I know this because I do not have a single log entry for even an attempt to connect.

This section of the log from my AP shows me connecting with my cell phone. You can see the entries. I had the ESP32 trying to connect while I connected with my cell phone. but yet you see no attempt to connect from the ESP.

the MAC address for the ESP32 is 4c:11:ae:cc:0c:e4

I disconnected my cell phone from the 5ghz side of my AP and connected it to the 2.4 GHZ that is why you see the disconnect then the reconnect

ath8 = 5ghz
ath0 = 2.4ghz

Code: Select all

1	2020 April-10 11:31:40	Station has associated. Interface: ath8, MAC: c0:ee:fb:6c:4e:99	
2	2020 April-10 11:31:40	starting accounting session 00000027-00000001 Interface: ath8, MAC: c0:ee:fb:6c:4e:99	
3	2020 April-10 11:31:47	Station has disassociated. Interface: ath8, MAC: c0:ee:fb:6c:4e:99	
4	2020 April-10 11:31:48	Station has associated. Interface: ath0, MAC: 46:25:34:15:5f:66	
5	2020 April-10 11:31:48	starting accounting session 00000027-00000003 Interface: ath0, MAC: 46:25:34:15:5f:66	
6	2020 April-10 11:31:59	web login successful 
The ESP32 is not even trying to make the connection so I am not exactly sure where it is coming up with WIFI_REASON_AUTH_EXPIRE as a failure reason when it hasn't even tried to connect.

I just tried enabling security on my AP and adding the password to the connect script and still no luck. It still spits out the same error.

Re: Can't connect WiFi after restart

Posted: Fri Apr 10, 2020 9:40 pm
by tve
Frustrating!
There have been some fixes in esp-idf v4 around wifi auth, but dunno...

Re: Can't connect WiFi after restart

Posted: Fri Apr 10, 2020 10:18 pm
by kgschlosser
I tried reflashing the thing with MicroPython and no luck there. I also set the IP to static and still no luck.
I tried enabling security on my AP and that didn't work either.
The AP is not showing any association to the ESP at all.

When I removed the password from MicroPython for my AP and I forgot to turn off the security on the AP. When the ESP32 tried to connect I got a different error. Probably that the password was bad or some such thing I am sure. So it is trying to negotiate a connection. There is something that MicroPython is getting wrong during the initial handshaking and authentication check.

Does the ESP store any information about the last AP it connected to that would persist between flashes??

Is there a way to enable a more intense debugging routine one that would log all of the data that is being passed between the ESP and the AP??

I looked at the ESP SDK and it doesn't appear liek there is a whole hell of alot in terms of debugging ability in the network end of things.

Re: Can't connect WiFi after restart

Posted: Sat Apr 11, 2020 2:57 am
by kgschlosser
I tried v4.0 and still the same problem.

Re: Can't connect WiFi after restart

Posted: Sat Apr 11, 2020 3:05 am
by kgschlosser
I found an issue that may be the same problem I am having.

https://github.com/espressif/esp-idf/issues/4987

It seems like this issue might be fixed with newer versions of the idf. Dunno.. This is above my programming skills. I do not know if I would be able to compile MicroPython using a newer version of the idf.

Re: Can't connect WiFi after restart

Posted: Sat Apr 11, 2020 3:19 am
by kgschlosser
well well well, would you look at that. Now knowing how temperamental these ESP chips are to things like a/c bounce from crappy filters in cheap wall warts I decided to check on the power going into this thing. I have mine connected via USB to my PC. and low and behold at an idle state not even trying to connect it is drawing 500mA which is the max output of a typical USB port on a PC. What is strange is I am able to flash the thing. which is what typically draws the most current.

I am going to move some things around and get this thing plugged into a USB 3.0 port which has a higher mA rating.

That sounds bad.

Posted: Sat Apr 11, 2020 5:03 am
by pythoncoder
I would beware. An ESP32 with SPIRAM here consumes 28mA at idle. Unless you have other hardware drawing current, something is wrong and feeding it more current may cause havoc.

Re: Can't connect WiFi after restart

Posted: Sat Apr 11, 2020 5:26 pm
by kgschlosser
well it's not the USB.

I flashed the ESP32 with MicroPython 1.9.4 and it started working. It's a wee bit flaky still and will produce a bunch of the same errors when it first tries to connect. like 8 or 9 times before it manages to connect. But tht is better then not connecting at all.

There is something really wrong with the authentication bits. It could be a problem in the ESP SDK and not in MicroPython. I would be willing to use VirtualHere to create a USB over IP bridge so it can be tested to see if a posisble cause can be tracked down.

Or if there is a way to enable some in depth debugging output so the data can be gone over to look for a possible problem..

IDK how else I would be able to help. The same problem does exist in 1.9.4 but it manages to get past it after several tries. The really strange thing is it was working fine with 1.12 then I pressed the reset button and it would no longer connect even after I erased and reflashed the thing several times. It still would not connect.

I have another access point I am going to try and see if it connects to that. It could be the AP and the ESP are simply bumping heads for some reason.

Re: Can't connect WiFi after restart

Posted: Sat Apr 11, 2020 5:28 pm
by kgschlosser
also. as far as the mA is concerned. It is not the actual draw, it is the draw that is reported by the ESP32 or the chip for the USB on the ESP32. Which I believe is the "peak" draw or what it can possibly draw.

Re: Can't connect WiFi after restart

Posted: Sat Apr 11, 2020 5:53 pm
by kgschlosser
I found the issue!!!!!


I came across some information about using WiFi and not being able to use some of the pins. It only stated that the pins would not function properly and made no mention of the WiFi not working properly. But low and behold I moved the pins I was using that were ADC2 pins to pins that are ADC1 and the problem went away! So it would appear that not only the pins are effected when being used when WiFi is running but also the WiFi is effected when something is connected to the pins.
Here is a list of ADC 2 and ADC1 pins for reference.

ADC1_CH0 (GPIO 36)
ADC1_CH1 (GPIO 37)
ADC1_CH2 (GPIO 38)
ADC1_CH3 (GPIO 39)
ADC1_CH4 (GPIO 32)
ADC1_CH5 (GPIO 33)
ADC1_CH6 (GPIO 34)
ADC1_CH7 (GPIO 35)
ADC2_CH0 (GPIO 4)
ADC2_CH1 (GPIO 0)
ADC2_CH2 (GPIO 2)
ADC2_CH3 (GPIO 15)
ADC2_CH4 (GPIO 13)
ADC2_CH5 (GPIO 12)
ADC2_CH6 (GPIO 14)
ADC2_CH7 (GPIO 27)
ADC2_CH8 (GPIO 25)
ADC2_CH9 (GPIO 26)

This is worth mentioning in the documentation. It is something that can cause a real headache.