8000 esp32 - <WLAN>.isconnected() logic fails when static IP address has been configured · Issue #3837 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content
esp32 - <WLAN>.isconnected() logic fails when static IP address has been configured #3837
Closed
@glenn20

Description

@glenn20

network.WLAN(network.STA_IF).isconnected() currently tests if wifi is connected by testing if an IP address has been set. This logic assumes IP address is assigned by DHCP. It fails if a static IP address configured. Static IP address assignment has the advantage of a slightly faster connect time.

Eg. the standard wifi connect workflow is broken for static IP address:

def connect():
    import network
    sta_if = network.WLAN(network.STA_IF)
    if not sta_if.isconnected():
        print('connecting to network...')
        sta_if.active(True)
        # Set static IP address - connects faster
        sta_if.ifconfig(('192.168.1.101', '255.255.255.0', '192.168.1.1', '8.8.8.8'))
        sta_if.connect('ssid', 'password')
        while not sta_if.isconnected():
            pass
    print('Network config:', sta_if.ifconfig())

as sta_if.isconnected() returns True immediately after the ifconfig() call.
An appropriate fix is to set a flag after GOT_IP event is recieved.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0