src/eric7/MicroPython/Devices/MCUScripts/picowWiFiConnect.py

Sun, 12 Mar 2023 14:56:04 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 12 Mar 2023 14:56:04 +0100
branch
mpy_network
changeset 9878
a82014a9e57b
parent 9836
902ec9a04ebe
child 9890
66a6d3f131cc
permissions
-rw-r--r--

MicroPython
- Added support for Ethernet enabled boards.

try:
    import secrets

    def connectWiFi():
        import network
        import rp2
        from time import sleep

        country = secrets.WIFI_COUNTRY
        if country:
            rp2.country(country)

        print("Connecting WiFi to '{0}' ...".format(secrets.WIFI_SSID))
        wifi = network.WLAN(network.STA_IF)
        wifi.active(False)
        wifi.active(True)
        wifi.connect(secrets.WIFI_SSID, secrets.WIFI_KEY if secrets.WIFI_KEY else None)
        max_wait = 140
        while max_wait:
            if wifi.status() < 0 or wifi.status() >= 3:
                break
            max_wait -= 1
            sleep(0.1)
        if wifi.isconnected():
            print("WiFi connected:", wifi.ifconfig())
        else:
            print("WiFi connection failed")

    connectWiFi()
except ImportError:
    print("WiFi secrets are kept in 'secrets.py', please add them there!")

eric ide

mercurial