2015-09-10 15:28:09 +02:00
|
|
|
-- Constants
|
2015-09-11 13:47:00 +02:00
|
|
|
SSID = "MessWLAN"
|
|
|
|
APPWD = "UNVmpwbr6heQnMQ7ykXT"
|
2015-09-11 09:51:54 +02:00
|
|
|
CMDFILE = "mqtt.lua"
|
2015-09-10 15:28:09 +02:00
|
|
|
|
|
|
|
-- Some control variables
|
2015-09-11 09:51:54 +02:00
|
|
|
wifiTrys = 0
|
|
|
|
NUMWIFITRYS = 200
|
2015-09-10 15:28:09 +02:00
|
|
|
|
|
|
|
function launch()
|
2015-09-11 11:32:31 +02:00
|
|
|
print("A")
|
|
|
|
print("B: " .. wifi.sta.getip())
|
2015-09-11 09:51:54 +02:00
|
|
|
tmr.alarm(0, 5000, 0, function() dofile(CMDFILE) end )
|
2015-09-10 15:28:09 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function checkWIFI()
|
|
|
|
if ( wifiTrys > NUMWIFITRYS ) then
|
2015-09-11 11:32:31 +02:00
|
|
|
print("C")
|
2015-09-10 15:28:09 +02:00
|
|
|
else
|
|
|
|
ipAddr = wifi.sta.getip()
|
|
|
|
if ( ( ipAddr ~= nil ) and ( ipAddr ~= "0.0.0.0" ) )then
|
|
|
|
tmr.alarm( 1 , 500 , 0 , launch )
|
|
|
|
else
|
|
|
|
tmr.alarm( 0 , 2500 , 0 , checkWIFI)
|
2015-09-11 11:32:31 +02:00
|
|
|
print("D: " .. wifiTrys)
|
2015-09-10 15:28:09 +02:00
|
|
|
wifiTrys = wifiTrys + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-09-11 11:32:31 +02:00
|
|
|
print("E")
|
2015-09-10 15:28:09 +02:00
|
|
|
|
|
|
|
ipAddr = wifi.sta.getip()
|
|
|
|
if ( ( ipAddr == nil ) or ( ipAddr == "0.0.0.0" ) ) then
|
2015-09-11 11:32:31 +02:00
|
|
|
print("F")
|
2015-09-10 15:28:09 +02:00
|
|
|
wifi.setmode( wifi.STATION )
|
|
|
|
wifi.sta.config( SSID , APPWD)
|
2015-09-11 11:32:31 +02:00
|
|
|
print("G")
|
2015-09-11 09:51:54 +02:00
|
|
|
tmr.alarm( 0 , 2500 , 0 , checkWIFI )
|
2015-09-10 15:28:09 +02:00
|
|
|
else
|
|
|
|
launch()
|
|
|
|
end
|