While running this code on my esp32 device:
import utime
import network
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect("Dream Net R-632", "07132711")
max_wait = 10
while max_wait > 0:
"""
0 STAT_IDLE -- no connection and no activity,
1 STAT_CONNECTING -- connecting in progress,
-3 STAT_WRONG_PASSWORD -- failed due to incorrect password,
-2 STAT_NO_AP_FOUND -- failed because no access point replied,
-1 STAT_CONNECT_FAIL -- failed due to other problems,
3 STAT_GOT_IP -- connection successful.
"""
if wlan.status() < 0 or wlan.status() >= 3:
break
max_wait -= 1
print('waiting for connection... ' + str(max_wait))
utime.sleep(1)
if wlan.status() != 3:
raise RuntimeError('network connection failed')
else:
print('wlan connected')
status = wlan.ifconfig()
print('IP address = ' + status[0])
print('subnet mask = ' + status[1])
print('gateway = ' + status[2])
print('DNS server = ' + status[3])
I had run this code on my esp32 device through Thonny ide but always getting the error that: "RuntimeError: network connection failed". Tried running:
wlan.isconnected()
and it's returning me True meaning that wifi is connected. But when I check wlan.status() instead of getting value between 1-5 it's giving me 1010 value which is causing RunTimeError.
I had checked my ssid and pin. Everything is fine except this .status() thing that is returning to 1010.
>>> wlan.active(True)
True
>>> wlan.status()
1010
>>>