def connect():
    import network
    from time import sleep, sleep_ms
 
    ssid = "YourSSID"
    password = "totallysecurepassword"

    print("Connecting to WiFi")
 
    station = network.WLAN(network.STA_IF)
 
    if station.isconnected() == True:
        print("Already connected")
        return True
 
    station.active(True)
    station.connect(ssid, password) # Timeout 10 Seconds
 
    while station.status() == 1:
        # 1 connecting?
        # 2 ???
        # 3 failed?
        # 5 connected?
        sleep_ms(500)
    
    print("Connection status")
    print(station.status())
        
    if station.isconnected():
        print("Connection successful")
        print(station.ifconfig())
        return True
    else:
        return False