Code: Select all
def connect():
import network
from utils.conf import ip, subnet, gateway, dns, ssid, password
station = network.WLAN(network.STA_IF)
if station.isconnected() == True:
print("Already connected")
return
station.active(True)
station.ifconfig((ip,subnet,gateway,dns))
station.connect(ssid, password)
while station.isconnected() == False:
pass
print("Connection successful")
print(station.ifconfig())
def disconnect():
import network
station = network.WLAN(network.STA_IF)
station.disconnect()
station.active(False)
Code: Select all
try:
connect()
except:
print("no connectWifi")
disconnect()
Code: Select all
no AP found
I (64636) wifi: STA_DISCONNECTED, reason:201
no AP found
I (66696) wifi: STA_DISCONNECTED, reason:201