2018-05-31 15:05:12 +01:00
|
|
|
from network import WLAN as wlan, STA_IF as staif, AP_IF as apif
|
2018-05-31 23:43:31 +01:00
|
|
|
from time import sleep_ms
|
2018-05-31 15:05:12 +01:00
|
|
|
|
2018-05-31 23:43:31 +01:00
|
|
|
sleep_ms(100)
|
2018-05-31 15:05:12 +01:00
|
|
|
#make sure AP mode is off and station mode is on
|
|
|
|
if wlan(apif).active() == True:
|
|
|
|
wlan(apif).active(False)
|
|
|
|
if wlan(staif).active() != True:
|
|
|
|
wlan(staif).active(True)
|
|
|
|
|
|
|
|
#we don't want to go through all this crap if stored network details are available
|
|
|
|
#this is inside an if statement because this file gets executed after deepsleep
|
|
|
|
# so we may still be connected(?)
|
|
|
|
if wlan(staif).isconnected() != True:
|
|
|
|
nets=wlan(staif).scan()
|
|
|
|
found_net=False
|
|
|
|
for net in nets:
|
|
|
|
if net[0] == b'WiFiNetworkName':
|
|
|
|
wlan(staif).connect("WiFiNetworkName","WiFiNetworkPSK")
|
|
|
|
found_net=True
|
|
|
|
break
|
|
|
|
elif net[0] == b'WiFiNetworkName':
|
|
|
|
wlan(staif).connect("WiFiNetworkName","WiFiNetworkPSK")
|
|
|
|
found_net=True
|
|
|
|
break
|
|
|
|
if found_net == False:
|
|
|
|
print("couldn't connect to wifi, nets found: %s" % nets)
|
2018-05-31 23:43:31 +01:00
|
|
|
print("to fix temporarily, run: wlan(staif).connect('yournet','yourpass'), followed shortly after by wlan(staif).ifconfig()")
|
2018-05-31 15:05:12 +01:00
|
|
|
#exit
|
|
|
|
else:
|
|
|
|
#Loop until wifi is connected and passes DHCP, or until 30 seconds have elapsed.
|
|
|
|
slept=0
|
|
|
|
while wlan(staif).ifconfig()[0] == '0.0.0.0' or wlan(staif).isconnected() == False:
|
|
|
|
if slept > 300:
|
|
|
|
break
|
2018-05-31 23:43:31 +01:00
|
|
|
sleep_ms(100)
|
2018-05-31 15:05:12 +01:00
|
|
|
slept+=1
|
|
|
|
|
2018-05-31 21:39:23 +01:00
|
|
|
#import webrepl
|
|
|
|
#webrepl.start()
|