clear more variables

This commit is contained in:
Ollo 2021-02-11 21:48:05 +01:00
parent 744c36b8b5
commit 72734f1337

View File

@ -83,11 +83,51 @@ function normalOperation()
color=string.char(0,0,250)
end
print("start: " , node.heap())
-------------------------------------------------------------
-- Define the main loop
local setupCounter=5
local alive=0
looptimer:register(2500, tmr.ALARM_AUTO, function (lt)
if (setupCounter > 4) then
syncTimeFromInternet()
setupCounter=setupCounter-1
alive = 1
elseif (setupCounter > 3) then
-- Here the WLAN is found, and something is done
mydofile("mqtt")
if (startMqttClient ~= nil) then
startMqttClient()
else
print("NO Mqtt found")
mydofile("telnet")
end
setupCounter=setupCounter-1
elseif (setupCounter > 2) then
if (startTelnetServer ~= nil) then
startTelnetServer()
else
displayTime()
end
setupCounter=setupCounter-1
elseif ( (alive % 120) == 0) then
-- sync the time every 5 minutes
syncTimeFromInternet()
alive = alive + 1
collectgarbage()
else
displayTime()
alive = alive + 1
end
-- Feed the system watchdog.
tmr.wdclr()
end)
-------------------------------------------------------------
-- Connect to Wifi
local connect_counter=0
-- Wait to be connect to the WiFi access point.
local wifitimer = tmr.create()
wifitimer:register(2000, tmr.ALARM_SINGLE, function (t)
wifitimer:register(2000, tmr.ALARM_AUTO, function (timer)
connect_counter=connect_counter+1
if wifi.sta.status() ~= 5 then
print(connect_counter .. "/60 Connecting to AP...")
@ -123,51 +163,11 @@ function normalOperation()
ws2812.write(string.char(0,0,0):rep(114))
end
else
t:unregister()
timer:unregister()
wifitimer=nil
connect_counter=nil
print('IP: ',wifi.sta.getip(), " heap: ", node.heap())
-- Here the WLAN is found, and something is done
mydofile("mqtt")
local setupCounter=5
local alive=0
looptimer:register(2500, tmr.ALARM_AUTO, function (lt)
if (setupCounter > 4) then
syncTimeFromInternet()
setupCounter=setupCounter-1
alive = 1
elseif (setupCounter > 3) then
if (startMqttClient ~= nil) then
startMqttClient()
else
print("NO Mqtt found")
mydofile("telnet")
end
setupCounter=setupCounter-1
elseif (setupCounter > 2) then
if (startTelnetServer ~= nil) then
startTelnetServer()
else
displayTime()
end
setupCounter=setupCounter-1
elseif ( (alive % 120) == 0) then
-- sync the time every 5 minutes
syncTimeFromInternet()
alive = alive + 1
else
displayTime()
alive = alive + 1
end
collectgarbage()
-- Feed the system watchdog.
tmr.wdclr()
end)
looptimer:start()
end
-- when no wifi available, open an accesspoint and ask the user
if (connect_counter >= 60) then -- 300 is 30 sec in 100ms cycle
startSetupMode()
end
end)
wifitimer:start()