Code: Select all
def connect(timeout=10,ssid=None,passkey=None):
from network import WLAN,STA_IF, AP_IF
sta = WLAN(STA_IF)
if not sta.isconnected():
sta.active(True)
sta.connect(ssid,passkey)
from time import sleep_ms
for count in range(timeout*10):
if sta.isconnected(): break
sleep_ms(100)
if not sta.isconnected():
sta = WLAN(AP_IF)
sta.active(True)
print('Connect msec:',count*100,'ifconfig:',sta.ifconfig())
return sta
wl = connect(timeout=5,ssid='wlan@mywan',passkey='mypass')
print(wl.ifconfig())