diff --git a/src/wifi.py b/src/wifi.py index 919b819..2ca86aa 100644 --- a/src/wifi.py +++ b/src/wifi.py @@ -2,14 +2,15 @@ import network from time import sleep def connect(ssid, password, ip, gateway): - if ssid == "" or password == "": - print("Missing ssid or password") - return None + try: sta_if = network.WLAN(network.STA_IF) - if ip != "" and gateway != "": - sta_if.ifconfig((ip, '255.255.255.0', gateway, '1.1.1.1')) if not sta_if.isconnected(): + if ssid == "" or password == "": + print("Missing ssid or password") + return None + if ip != "" and gateway != "": + sta_if.ifconfig((ip, '255.255.255.0', gateway, '1.1.1.1')) print('connecting to network...') sta_if.active(True) sta_if.connect(ssid, password)