I have each setup wifi and Setup AP working seperately but when I try to integrate them I am having issue.
My issue is around how to introduce a "sleep" while waiting for the wifi setup to establish.
Here is some mocked up code.
-- testing a loop
--Need to add a delay while waiting for wifi status.
trycount=0
badreturn=5
print ("setting up ssid")
tmr.alarm(1, 1000, 1, function()
if badreturn <= 4 then
print("IP unavaiable, Waiting try " .. trycount )
trycount = trycount + 1
if trycount >= 10 then
print ("setting up AP mode")
tmr.stop(1)
end -- end if trycount
else
tmr.stop(1)
end --end if status
end) --end tmr
print ("SHOW my IPs")
When I run it with badreturn=5, ie a good wifi setup it seems to work correctly
and I see on my debug window
setting up ssid
SHOW my IPs
When I set badreturn=4, ie a failed wifi setup, keep trying then go into ap mode. I see this
setting up ssid
SHOW my IPs
> IP unavaiable, Waiting try 0
IP unavaiable, Waiting try 1
IP unavaiable, Waiting try 2
IP unavaiable, Waiting try 3
IP unavaiable, Waiting try 4
IP unavaiable, Waiting try 5
IP unavaiable, Waiting try 6
IP unavaiable, Waiting try 7
IP unavaiable, Waiting try 8
IP unavaiable, Waiting try 9
setting up AP mode
Why is the SHOW my IPs running before the timer loop completes? How Can get a sleep/wait/delay into my script soemthing like this
-- testing a loop
--Need to add a delay while waiting for wifi status.
trycount=0
badreturn=4
print ("setting up ssid")
if badreturn <= 4 then
print("IP unavaiable, Waiting try " .. trycount )
trycount = trycount + 1
if trycount >= 10 then
print ("setting up AP mode")
end -- end if trycount
SLEEP(1) -- sleep 1 second
end --end if status
end) --end tmr
print ("SHOW my IPs")
Baring no solution, anyone have code that will try to connect to a WIFI and if it fails go into AP mode.
Many thanks. -gary