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
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)