src/eric7/MicroPython/Devices/MCUScripts/esp32WiFiConnect.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 9795
11b4d39d7584
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

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

    try:
        nvs = esp32.NVS("wifi_creds")
        buf = bytearray(1024)
        size = nvs.get_blob("ssid", buf)
        ssid = buf[:size].decode()
        size = nvs.get_blob("password", buf)
        password = buf[:size].decode()

        wifi = network.WLAN(network.STA_IF)
        wifi.active(False)
        wifi.active(True)
        wifi.connect(ssid, password)
        max_wait = 140
        print("Connecting WiFi to '{0}'...".format(ssid))
        while max_wait and wifi.status() == network.STAT_CONNECTING:
            max_wait -= 1
            sleep(0.1)
        print("Connection status:", wifi.isconnected())
    except:
        pass

connectWiFi()

eric ide

mercurial