With NodeMCU in station mode with the following snippet of code in init.lua it still takes on average about 6 iterations of the loop before an IP address is reported (or IP stack ready state is achieved)
wifi.sta.disconnect()
--settings.lua
SSID = "xxxx"
APPWD = "yyyy"
cfg =
{
ip="192.168.0.85",
netmask="255.255.255.0",
gateway="192.168.0.1"
}
wifi.sta.setip(cfg)
wifi.sta.config(SSID,APPWD)
wifi.sta.autoconnect(1)
-- wait for WIFI ----
function checkWIFI()
print("Waiting for WIFI...")
ipAddr = wifi.sta.getip()
if ( ( ipAddr ~= nil ) and ( ipAddr ~= "0.0.0.0" ) )then
print("IP Address: " ..ipAddr)
else
-- schedule try again
tmr.alarm( 0 , 1000 , 0 , checkWIFI)
end
end
tmr.alarm( 0 , 1000 , 0 , checkWIFI)
Tried with and without static IP configuration, seems no different Is this normal? Is there a way to make faster? Am I just doing it wrong?