from network import WLAN, STA_IF, AP_IF, AUTH_WPA_WPA2_PSK from time import sleep station = WLAN(STA_IF); station.active(True) def connect(): ssid = "" station = WLAN(STA_IF); station.active(True) wlans=station.scan() # Scan for available access points for wlan in wlans: print(" - ",wlan[0].decode()) if wlan[0].decode()=="WLAN-muster": ssid=wlan[0].decode(); password="1234567890" if wlan[0].decode()=="mrge-ap-bu46": ssid=wlan[0].decode(); password="" if wlan[0].decode()=="meineSSID": # Beispiel anpassen ssid=wlan[0].decode(); password="meinPasswort" # Kann beliebig erweitert werden if ssid != "": print("Verbinde mit :",ssid) station = WLAN(STA_IF) if station.isconnected() == True: print(" - WLAN schon verbunden") else: print("Wird verbunden") station.active(True) station.connect(ssid,password) while station .isconnected() == False: print(".",end="") sleep(0.5) print("\nVerbindung erfolgreich") print(station.ifconfig()) def disconnect(): station.disconnect()