diff --git a/init.lua b/init.lua index 164e15b..2f14baa 100644 --- a/init.lua +++ b/init.lua @@ -27,6 +27,7 @@ function recompileAll() node.compile(k) -- remove the lua file file.remove(k) + node.restart() else print("No code: " .. k) end @@ -46,14 +47,14 @@ function mydofile(mod) end end -local initTimer = tmr.create() +initTimer = tmr.create() initTimer:register(5000, tmr.ALARM_SINGLE, function (t) bootledtimer:unregister() if ( (file.open("main.lua")) or (file.open("timecore.lua")) or (file.open("wordclock.lua")) or - (file.open("displayword.lua")) or + (file.open("displayword.lua")) or (file.open("mqtt.lua")) or (file.open("ds18b20.lua")) or (file.open("telnet.lua")) @@ -66,8 +67,18 @@ initTimer:register(5000, tmr.ALARM_SINGLE, function (t) -- reboot repairs everything node.restart() elseif (file.open("main.lc")) then - print("Starting main") - dofile("main.lc") + if ( file.open("config.lua") ) then + --- Normal operation + print("Starting main") + dofile("main.lc") + wifi.setmode(wifi.STATION) + dofile("config.lua") + normalOperation() + else + mydofile("webserver") + -- Logic for inital setup + startSetupMode() + end else print("No Main file found") end diff --git a/main.lua b/main.lua index a31399c..63afaf1 100644 --- a/main.lua +++ b/main.lua @@ -3,32 +3,6 @@ local looptimer = tmr.create() displayword = {} -function startSetupMode() - -- start the webserver module - mydofile("webserver") - collectgarbage() - wifi.setmode(wifi.SOFTAP) - cfg={} - cfg.ssid="wordclock" - cfg.pwd="wordclock" - wifi.ap.config(cfg) - - -- Write the buffer to the LEDs - local color=string.char(0,128,0) - local white=string.char(0,0,0) - local ledBuf= white:rep(6) .. color .. white:rep(7) .. color:rep(3) .. white:rep(44) .. color:rep(3) .. white:rep(50) - ws2812.write(ledBuf) - color=nil - white=nil - ledBuf=nil - - print("Waiting in access point >wordclock< for Clients") - print("Please visit 192.168.4.1") - startWebServer() - collectgarbage() -end - - function syncTimeFromInternet() if (syncRunning == nil) then syncRunning=true @@ -207,15 +181,6 @@ end -------------------main program ----------------------------- ws2812.init() -- WS2812 LEDs initialized on GPIO2 -if ( file.open("config.lua") ) then - --- Normal operation - wifi.setmode(wifi.STATION) - mydofile("config") - normalOperation() -else - -- Logic for inital setup - startSetupMode() -end ----------- button --------- gpio.mode(3, gpio.INPUT) local btnCounter=0 diff --git a/webserver.lua b/webserver.lua index b61d2d3..ac3b237 100644 --- a/webserver.lua +++ b/webserver.lua @@ -327,4 +327,28 @@ function startWebServer() end) end ---FileView done. + + +function startSetupMode() + -- start the webserver module + collectgarbage() + wifi.setmode(wifi.SOFTAP) + cfg={} + cfg.ssid="wordclock" + cfg.pwd="wordclock" + wifi.ap.config(cfg) + + -- Write the buffer to the LEDs + local color=string.char(0,128,0) + local white=string.char(0,0,0) + local ledBuf= white:rep(6) .. color .. white:rep(7) .. color:rep(3) .. white:rep(44) .. color:rep(3) .. white:rep(50) + ws2812.write(ledBuf) + color=nil + white=nil + ledBuf=nil + + print("Waiting in access point >wordclock< for Clients") + print("Please visit 192.168.4.1") + startWebServer() + collectgarbage() +end \ No newline at end of file