Added time synchronization again
This commit is contained in:
parent
6874d1545b
commit
7140717696
53
main.lua
53
main.lua
@ -1,14 +1,18 @@
|
|||||||
-- Main Module
|
-- Main Module
|
||||||
function startSetupMode()
|
|
||||||
tmr.stop(0)
|
function mydofile(mod)
|
||||||
tmr.stop(1)
|
|
||||||
-- start the webserver module
|
|
||||||
mod="webserver"
|
|
||||||
if (file.open(mod .. ".lua")) then
|
if (file.open(mod .. ".lua")) then
|
||||||
dofile( mod .. ".lua")
|
dofile( mod .. ".lua")
|
||||||
else
|
else
|
||||||
dofile(mod .. ".lc")
|
dofile(mod .. ".lc")
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function startSetupMode()
|
||||||
|
tmr.stop(0)
|
||||||
|
tmr.stop(1)
|
||||||
|
-- start the webserver module
|
||||||
|
mydofile("webserver")
|
||||||
|
|
||||||
wifi.setmode(wifi.SOFTAP)
|
wifi.setmode(wifi.SOFTAP)
|
||||||
cfg={}
|
cfg={}
|
||||||
@ -20,20 +24,6 @@ function startSetupMode()
|
|||||||
startWebServer()
|
startWebServer()
|
||||||
end
|
end
|
||||||
|
|
||||||
print("Solving dependencies")
|
|
||||||
dependModules = { "timecore" , "wordclock", "displayword" }
|
|
||||||
for _,mod in pairs(dependModules) do
|
|
||||||
print("Loading " .. mod)
|
|
||||||
if (file.open(mod .. ".lua")) then
|
|
||||||
dofile( mod .. ".lua")
|
|
||||||
else
|
|
||||||
dofile(mod .. ".lc")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
ledPin=4
|
|
||||||
-- Color is defined as GREEN, RED, BLUE
|
|
||||||
color=string.char(0,0,250)
|
|
||||||
|
|
||||||
function syncTimeFromInternet()
|
function syncTimeFromInternet()
|
||||||
--ptbtime1.ptb.de
|
--ptbtime1.ptb.de
|
||||||
@ -47,6 +37,11 @@ function syncTimeFromInternet()
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function normalOperation()
|
||||||
|
ledPin=4
|
||||||
|
-- Color is defined as GREEN, RED, BLUE
|
||||||
|
color=string.char(0,0,250)
|
||||||
|
|
||||||
connect_counter=0
|
connect_counter=0
|
||||||
-- Wait to be connect to the WiFi access point.
|
-- Wait to be connect to the WiFi access point.
|
||||||
tmr.alarm(0, 500, 1, function()
|
tmr.alarm(0, 500, 1, function()
|
||||||
@ -62,9 +57,12 @@ tmr.alarm(0, 500, 1, function()
|
|||||||
tmr.stop(0)
|
tmr.stop(0)
|
||||||
print('IP: ',wifi.sta.getip())
|
print('IP: ',wifi.sta.getip())
|
||||||
|
|
||||||
|
tmr.alarm(2, 500, 0 ,function()
|
||||||
|
syncTimeFromInternet()
|
||||||
|
end)
|
||||||
print("Start webserver...")
|
print("Start webserver...")
|
||||||
tmr.alarm(2, 2000, 0 ,function()
|
tmr.alarm(3, 2000, 0 ,function()
|
||||||
dofile("webserver.lua")
|
mydofile("webserver")
|
||||||
startWebServer()
|
startWebServer()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@ -102,11 +100,22 @@ tmr.alarm(1, 15000, 1 ,function()
|
|||||||
time=nil
|
time=nil
|
||||||
collectgarbage()
|
collectgarbage()
|
||||||
end)
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- Logic
|
|
||||||
if ( file.open("config.lua") ) then
|
if ( file.open("config.lua") ) then
|
||||||
|
--- Normal operation
|
||||||
|
print("Solving dependencies")
|
||||||
|
dependModules = { "timecore" , "wordclock", "displayword" }
|
||||||
|
for _,mod in pairs(dependModules) do
|
||||||
|
print("Loading " .. mod)
|
||||||
|
mydofile(mod)
|
||||||
|
end
|
||||||
wifi.setmode(wifi.STATION)
|
wifi.setmode(wifi.STATION)
|
||||||
dofile("config.lua")
|
dofile("config.lua")
|
||||||
|
normalOperation()
|
||||||
else
|
else
|
||||||
|
-- Logic for inital setup
|
||||||
startSetupMode()
|
startSetupMode()
|
||||||
end
|
end
|
Loading…
Reference in New Issue
Block a user