Closed
Description
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.