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

Sat, 25 Feb 2023 19:18:07 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 25 Feb 2023 19:18:07 +0100
branch
mpy_network
changeset 9799
a79430a8811d
parent 9787
163511257f24
child 9828
32c8a5b57332
permissions
-rw-r--r--

MicroPython
- added support for 'paste' mode to circumvent the reset of CircuitPython when executing some commands through the device interface

try:
    import secrets

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

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

        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:
    pass

eric ide

mercurial