ESP-32 config wifi in micropython

Make a file with the name ConnectWifi.py with the following code:

def do_connect():
    import network
    sta_if = network.WLAN(network.STA_IF)
    if not sta_if.isconnected():
        print('connecting to network...')
        sta_if.active(True)
        sta_if.connect('essd', 'password')
        while not sta_if.isconnected():
            pass
        print('network config:', sta_if.ifconfig())

Edit boot.py to:

import ConnectWifi
ConnectWifi.do_connect()

Upload both files with ampy to the esp-32

ampy -p /dev/ttyUSB0 put boot.py
ampy -p /dev/ttyUSB0 put ConnectWifi.py

Now when your micropython device boots up it will connect immediately connect to the configured wifi-network.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.