Network connect weird behavior?

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
fefe
Posts: 8
Joined: Tue May 28, 2019 5:52 pm

Network connect weird behavior?

Post by fefe » Wed May 29, 2019 10:46 pm

Hi,

I noticed very weird behavior when migrating from the ESP8266 to ESP32.

when running the following to connect to WIFI:

[code]wlan_sta.connect(ssid, password)[/code]

When inputting incorrect password credential, the ESP32 will keep trying to auto connect and will continue to throw the following:

WIFI_REASON_AUTH_EXPIRE, WIFI_REASON_NO_AP_FOUND, WIFI_REASON_ASSOC_EXPIRE, or any of the other exceptions (they are listed below)

meaning if you are running a socket like I was in my case it would hang the program since the ESP32 will continue to try to reconnect.

The solution to this problem was to do the following...

[code]
wlan_sta.active(True)
wlan_sta.connect(ssid, password)
for retry in range(100):
if wlan_sta.isconnected():
return True
time.sleep(.1)

if not wlan_sta.isconnected():
wlan_sta.active(False)
return False
else:
return True
[/code]


This way when disabling the wlan_sta it will not hang your program and the esp32 won't keep trying to auto reconnect.

Some other key observations I have made were that

The ESP-8266 persists WIFI Credentials even after being disconnected from power (non-volatile) and will auto connect on boot or any disconnect event.

The ESP-32 does only persists WIFI Credentials while turned on and will attempt to auto connect if wifi disconnects on its own. When disconnected from power it loses the credentials (volatile).

I guess I am a bit confused because the ESP32 has 2 cores so why would the program hang if the wifi connectivity runs on one core while my main program runs on the other. If someone can explain this to me that would be great.

Also, does the ESP32 have a greater wifi range when compared to the ESP8266?



WIFI_REASON_UNSPECIFIED = 1,
WIFI_REASON_AUTH_EXPIRE = 2,
WIFI_REASON_AUTH_LEAVE = 3,
WIFI_REASON_ASSOC_EXPIRE = 4,
WIFI_REASON_ASSOC_TOOMANY = 5,
WIFI_REASON_NOT_AUTHED = 6,
WIFI_REASON_NOT_ASSOCED = 7,
WIFI_REASON_ASSOC_LEAVE = 8,
WIFI_REASON_ASSOC_NOT_AUTHED = 9,
WIFI_REASON_DISASSOC_PWRCAP_BAD = 10,
WIFI_REASON_DISASSOC_SUPCHAN_BAD = 11,
WIFI_REASON_IE_INVALID = 13,
WIFI_REASON_MIC_FAILURE = 14,
WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT = 15,
WIFI_REASON_GROUP_KEY_UPDATE_TIMEOUT = 16,
WIFI_REASON_IE_IN_4WAY_DIFFERS = 17,
WIFI_REASON_GROUP_CIPHER_INVALID = 18,
WIFI_REASON_PAIRWISE_CIPHER_INVALID = 19,
WIFI_REASON_AKMP_INVALID = 20,
WIFI_REASON_UNSUPP_RSN_IE_VERSION = 21,
WIFI_REASON_INVALID_RSN_IE_CAP = 22,
WIFI_REASON_802_1X_AUTH_FAILED = 23,
WIFI_REASON_CIPHER_SUITE_REJECTED = 24,

WIFI_REASON_BEACON_TIMEOUT = 200,
WIFI_REASON_NO_AP_FOUND = 201,
WIFI_REASON_AUTH_FAIL = 202,
WIFI_REASON_ASSOC_FAIL = 203,
WIFI_REASON_HANDSHAKE_TIMEOUT = 204,

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

ESPx chip characteristics

Post by pythoncoder » Thu May 30, 2019 8:53 am

fefe wrote:
Wed May 29, 2019 10:46 pm
...
The ESP-8266 persists WIFI Credentials even after being disconnected from power (non-volatile) and will auto connect on boot or any disconnect event.

The ESP-32 does only persists WIFI Credentials while turned on and will attempt to auto connect if wifi disconnects on its own. When disconnected from power it loses the credentials (volatile)...
This is a deliberate design feature of the two chips.
fefe wrote:
Wed May 29, 2019 10:46 pm
...
Also, does the ESP32 have a greater wifi range when compared to the ESP8266?...
Range is more a function of the quality of the design of the board you are using rather than of the ESP chip, at least in my experience. Some boards are hopeless.
Peter Hinch
Index to my micropython libraries.

Post Reply