From a3aa7018d162bab33a864d5008e8f6168069c371 Mon Sep 17 00:00:00 2001 From: Ollo Date: Fri, 5 Feb 2021 20:58:15 +0100 Subject: [PATCH] Further optimisation in webserver --- init.lua | 9 ++++----- webserver.lua | 37 +++++++++---------------------------- 2 files changed, 13 insertions(+), 33 deletions(-) diff --git a/init.lua b/init.lua index 2f14baa..f92b063 100644 --- a/init.lua +++ b/init.lua @@ -6,7 +6,7 @@ MAXLEDS=110 counter1=0 ws2812.write(string.char(0,0,0):rep(114)) local bootledtimer = tmr.create() -bootledtimer:register(5000, tmr.ALARM_AUTO, function (t) +bootledtimer:register(500, tmr.ALARM_AUTO, function (t) counter1=counter1+1 spaceLeds = math.max(MAXLEDS - (counter1*2), 0) ws2812.write(string.char(128,0,0):rep(counter1) .. string.char(0,0,0):rep(spaceLeds) .. string.char(0,0,64):rep(counter1)) @@ -50,6 +50,8 @@ end initTimer = tmr.create() initTimer:register(5000, tmr.ALARM_SINGLE, function (t) bootledtimer:unregister() + t:unregister() + collectgarbage() if ( (file.open("main.lua")) or (file.open("timecore.lua")) or @@ -66,7 +68,7 @@ initTimer:register(5000, tmr.ALARM_SINGLE, function (t) print("Rebooting ...") -- reboot repairs everything node.restart() - elseif (file.open("main.lc")) then + else if ( file.open("config.lua") ) then --- Normal operation print("Starting main") @@ -79,9 +81,6 @@ initTimer:register(5000, tmr.ALARM_SINGLE, function (t) -- Logic for inital setup startSetupMode() end - else - print("No Main file found") end - t:unregister() end) initTimer:start() diff --git a/webserver.lua b/webserver.lua index edf6346..f8b6f2f 100644 --- a/webserver.lua +++ b/webserver.lua @@ -74,35 +74,16 @@ end function fillDynamicMap() replaceMap = {} ssid, _ = wifi.sta.getconfig() - - if (ssid == nil) then - ssid="Not set" - end - if (sntpserverhostname == nil) then - sntpserverhostname="ptbtime1.ptb.de" - end - if (timezoneoffset == nil) then - timezoneoffset=1 - end + if (ssid == nil) then return replaceMap end + if (sntpserverhostname == nil) then sntpserverhostname="ptbtime1.ptb.de" end + if (timezoneoffset == nil) then timezoneoffset=1 end -- Set the default color, if nothing is set - if (color == nil) then - color=string.char(0,0,250) - end - if (color1 == nil) then - color1=color - end - if (color2 == nil) then - color2=color - end - if (color3 == nil) then - color3=color - end - if (color4 == nil) then - color4=color - end - if (colorBg == nil) then - colorBg=string.char(0,0,0) -- black is the default background color - end + if (color == nil) then color=string.char(0,0,250) end + if (color1 == nil) then color1=color end + if (color2 == nil) then color2=color end + if (color3 == nil) then color3=color end + if (color4 == nil) then color4=color end + if (colorBg == nil) then colorBg=string.char(0,0,0) end local hexColor = "#" .. string.format("%02x",string.byte(color,2)) .. string.format("%02x",string.byte(color,1)) .. string.format("%02x",string.byte(color,3)) local hexColor1 = "#" .. string.format("%02x",string.byte(color1,2)) .. string.format("%02x",string.byte(color1,1)) .. string.format("%02x",string.byte(color1,3)) local hexColor2 = "#" .. string.format("%02x",string.byte(color2,2)) .. string.format("%02x",string.byte(color2,1)) .. string.format("%02x",string.byte(color2,3))