Repeatable OSError: Wifi Internal Error in sta_if.connect
Port, board and/or hardware
ESP32-C3 and S3
MicroPython version
MicroPython v1.25.0 on 2025-04-15; ESP32C3 module with ESP32C3
Reproduction
Power-cycle the board and run the following code (in my case, in Thonny):
import network, time
sta_if = network.WLAN(network.WLAN.IF_STA)
sta_if.active(True)
print('foo')
sta_if.connect("no-such-network", "password")
time.sleep(5)
print('bar')
sta_if.connect("no-such-network", "password")
time.sleep(5)
print('baz')
Expected behaviour
No response
Observed behaviour
foo
bar
Traceback (most recent call last):
File "<stdin>", line 10, in <module>
OSError: Wifi Internal Error
(where line 10 is the second connect)
I get similar results when the first connect() is a real network with the wrong password, the second connect() is the same wrong network/password as the first, or the second connect() is a real network with the right password.
In fact, the sleep()s don't seem to be required either.
Additional Information
Power-cycling the board before running the test may be required for reproducibility.
Bug also manifests in the latest preview ESP32_GENERIC_C3-20250709-v1.26.0-preview.364.gdf05caea6.bin
and ESP32_GENERIC_S3-SPIRAM_OCT-20250709-v1.26.0-preview.364.gdf05caea6.bin
Unfortunately I don't have other boards to test with right now.
Code of Conduct
Yes, I agree
ESP32 wifi issues
Port, board and/or hardware
ESP32
MicroPython version
esp32-20220618-v1.19.1.bin
Reproduction
Issue No.1:On startup
Issue No.2:On startup / while running
Expected behaviour
Connected to the wifi smooth and keep that.
Observed behaviour
Issue No.1: "Wifi internal error" occurs. After power off and on, sometimes it works but mostly not. Once it gets recovered, it keep working without any error which looks strange for me. Just adding print(anything) may have solved...
Issue No.2:I'm using 30+ ESP32 with micropython. Most of them connect wifi smooth and keep it. But some 1 or 2 of them suddenly start struggling to connect wifi when start up(cannot connect even after the reboot, unplug power and plug) or lose connection when it's working. But after a while, it works completely normal. The boards which have this issue is random.
(1)This is the code to connect wifi.
"""Wifi"""
def connect_wifi(ssid, passkey, timeout=5):
global speed_filtered, bias, speed_raw
wifi= network.WLAN(network.STA_IF)
wifi.active(False)
time.sleep(1)
wifi.active(True)
wifi.connect(ssid, passkey)
start = time.time()
start_count = time.time()
while not wifi.isconnected():
print('*')
time.sleep(1)
if time.time()-start > timeout:
wifi.disconnect()
time.sleep(1)
wifi.connect(ssid, passkey)
start = time.time()
if wifi.isconnected():
print('Connected')
print(time.time() - start_count)
return wifi
.
(2) this is the code to check wifi status. if it's not connected, it try to reconnect.
if wifi.isconnected():
if wifi_strength > 80:
wifi_strength_category = 4
elif wifi_strength > 60:
wifi_strength_category = 3
elif wifi_strength > 40:
wifi_strength_category = 2
else:
wifi_strength_category = 1
else:
wifi = connect_wifi(SSID_NAME, SSID_PASS)
Additional Information
No, I've provided everything above.
Code of Conduct
Yes, I agree