V1.12 Wifi Connection Failures

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
jdts
Posts: 36
Joined: Mon Dec 23, 2019 2:55 pm

V1.12 Wifi Connection Failures

Post by jdts » Tue Dec 31, 2019 6:34 pm

My esp32 wifi connection is now quite flaky after upgrading to v1.12. Sometimes connection works, sometimes not. Failure usually looks like a CONNECTED status followed quickly by STA_DISCONNECTED:

Code: Select all

I (48672) network: event 3
connecting to network [9]...
I (49692) wifi: mode : sta (a4:cf:12:9a:67:e4)
I (49692) wifi: STA_START
I (49822) wifi: new:<1,0>, old:<1,0>, ap:<255,255>, sta:<1,0>, prof:1
I (50662) wifi: state: init -> auth (b0)
I (50672) wifi: state: auth -> assoc (0)
I (50672) wifi: state: assoc -> run (10)
I (50692) wifi: connected with mynetwork, channel 1, BW20, bssid = 98:01:a7:e6:94:70
I (50692) wifi: pm start, type: 1

I (50692) network: CONNECTED
I (54702) wifi: state: run -> init (0)
I (54702) wifi: pm stop, total sleep time: 3261317 us / 4010648 us

I (54702) wifi: new:<1,0>, old:<1,0>, ap:<255,255>, sta:<1,0>, prof:1
I (54712) wifi: STA_DISCONNECTED, reason:8
E (54712) wifi: esp_wifi_connect 1156 wifi not start
I (54722) wifi: error attempting to reconnect: 0x3002
I (54722) wifi: flush txq
I (54722) wifi: stop sw txq
I (54732) wifi: lmac stop hw txq
I (54732) network: event 3
connecting to network [10]...
I (55752) wifi: mode : sta (a4:cf:12:9a:67:e4)
I (55752) wifi: STA_START
I (55872) wifi: new:<1,0>, old:<1,0>, ap:<255,255>, sta:<1,0>, prof:1
I (56722) wifi: state: init -> auth (b0)
I (56722) wifi: state: auth -> assoc (0)
I (56732) wifi: state: assoc -> run (10)
I (56752) wifi: connected with mynetwork, channel 1, BW20, bssid = 98:01:a7:e6:94:70
I (56752) wifi: pm start, type: 1

I (56752) network: CONNECTED
I (60762) wifi: state: run -> init (0)
I (60762) wifi: pm stop, total sleep time: 3364294 us / 4013070 us

I (60762) wifi: new:<1,0>, old:<1,0>, ap:<255,255>, sta:<1,0>, prof:1
I (60772) wifi: STA_DISCONNECTED, reason:8
E (60772) wifi: esp_wifi_connect 1156 wifi not start
I (60772) wifi: flush txq
I (60772) wifi: stop sw txq
I (60782) wifi: error attempting to reconnect: 0x3002
I (60782) wifi: lmac stop hw txq
I have fiddled with my `wifi.py` quite a bit but so far have been unable to correct:

Code: Select all

# Connect wifi and set host
import time
import network

HOSTNAME="myhost"
wlan = network.WLAN(network.STA_IF)

def activate(timeout=5000):
    wlan.active(True)
    for _ in range(5):
        try:
            wlan.config(dhcp_hostname=HOSTNAME)
        except OSError:
            time.sleep_ms(500)

    start=time.ticks_ms()
    
    if not wlan.isconnected():
        wlan.connect('mynetwork', 'mypassword')
        while not wlan.isconnected():
            time.sleep_ms(100)
            if time.ticks_diff(time.ticks_ms(),start) > timeout: break
    
def start(quiet=False):
    for i in range(1,11):
        if not quiet: print('connecting to network{}...'.
                            format(" [{}]".format(i) if i>1 else ""))
        activate()
        if wlan.isconnected():
            break
        wlan.active(False)
        time.sleep(1)
    if not wlan.isconnected():
        print("Failed to connect wifi!")
        return(None)

    if not quiet: print(HOSTNAME,'network config:', wlan.ifconfig())
    return(wlan)
Sometimes it does connect on the 3rd or 4th try, more common it's "STA_DISCONNECTED, reason:8" for all 10 tries. Anyone else experiencing this? Any idea what "reason: 8" signifies?

jdts
Posts: 36
Joined: Mon Dec 23, 2019 2:55 pm

Re: V1.12 Wifi Connection Failures

Post by jdts » Tue Dec 31, 2019 6:46 pm

Quick follow-up: "Reason: 8" comes from my "wlan.active(False)" statement after failure to connect is detected. If I remove that, the logs are much less revealing:

Code: Select all

connecting to network...
I (1232) phy: phy_version: 4102, 2fa7a43, Jul 15 2019, 13:06:06, 0, 0
I (1232) wifi: mode : sta (a4:cf:12:9a:67:e4)
I (1232) wifi: STA_START
I (1362) wifi: new:<1,0>, old:<1,0>, ap:<255,255>, sta:<1,0>, prof:1
I (2202) wifi: state: init -> auth (b0)
I (2212) wifi: state: auth -> assoc (0)
I (2212) wifi: state: assoc -> run (10)
I (2232) wifi: connected with mynetwork, channel 1, BW20, bssid = 98:01:a7:e6:94:70
I (2232) wifi: pm start, type: 1

I (2232) network: CONNECTED
connecting to network [2]...
connecting to network [3]...
connecting to network [4]...
connecting to network [5]...
connecting to network [6]...
connecting to network [7]...
connecting to network [8]...
connecting to network [9]...
connecting to network [10]...
Failed to connect wifi!

jdts
Posts: 36
Joined: Mon Dec 23, 2019 2:55 pm

Re: V1.12 Wifi Connection Failures

Post by jdts » Tue Dec 31, 2019 7:01 pm

Update to followup: Resetting my router fixed the issue, which had persisted for about 24hrs. Kind of alarming that an ESP32 can give a router such conniptions. I had even reset the ARP cache on the router. If you encounter something similar, try power-cycling your router.

Post Reply