However, if I wait a few seconds, then the same function works fine.
Both working and non-working wait 10 seconds until they call wifi.sta.getip()
(The count lines in the not-working part are just so it doesn't stay in the loop forever.)
Please let me know what I'm doing wrong, or what I can do to help solve the problem.
Thanks,
Chuck, N1SPX
This works:
wifi.lua
function wait_wifi()
wifi_ip = "0.0.0.0"
while wifi_ip == "0.0.0.0" do
print("Waiting on Wifi...\n")
print(wifi.sta.getip())
wifi_ip = wifi.sta.getip()
print("New IP = "..wifi_ip.."\n")
if wifi_ip == "0.0.0.0" then
tmr.delay(2000)
end
end
print("Got IP "..wifi_ip.."\n")
end
init.lua
dofile("wifi.lua")
tmr.alarm(10000,0,wait_wifi)
However, the following don't work.
wifi.lua
function wait_wifi()
count = 1
tmr.delay(9000000)
wifi_ip = "0.0.0.0"
while wifi_ip == "0.0.0.0" and count < 20 do
print("Waiting on Wifi...\n")
wifi_ip = wifi.sta.getip()
print("New IP = "..wifi_ip.."\n")
if wifi_ip == "0.0.0.0" then
tmr.delay(2000000)
end
count = count + 1
end
print("Got IP "..wifi_ip.."\n")
end
init.lua
dofile("wifi.lua")
tmr.alarm(1000,0,wait_wifi)