MaxO/wlan.py
2020-11-15 18:47:23 +01:00

26 lines
730 B
Python
Executable File

def do_connect(ssid, password, tries=5):
from network import WLAN, STA_IF
from time import sleep
print('Loading Wifi module...')
sta_if = WLAN(STA_IF)
if not sta_if.isconnected():
sta_if.active(True)
sta_if.connect(ssid, password)
for i in range(tries):
print('Connecting to network (try {})...'.format(i+1))
if sta_if.isconnected():
netconf = sta_if.ifconfig()
print('network config:', netconf)
return netconf[0]
sleep(1)
else:
print("Failed to connect in {} seconds.".format(tries))
if __name__ == '__main__':
import netconf
doconnect(netconf.ssid, netconf.password)