diff --git a/main.lua b/main.lua index 6e5a31e..81745e1 100644 --- a/main.lua +++ b/main.lua @@ -47,6 +47,17 @@ function displayTime() time = getTime(sec, timezoneoffset) print("Local time : " .. time.year .. "-" .. time.month .. "-" .. time.day .. " " .. time.hour .. ":" .. time.minute .. ":" .. time.second) words = display_timestat(time.hour, time.minute) + + if ((words.min1 == 1) and (color1 ~= nil)) then + color=color1 + elseif ((words.min2 == 1) and (color2 ~= nil)) then + color=color2 + elseif ((words.min3 == 1) and (color3 ~= nil)) then + color=color1 + elseif ((words.min4 == 1) and (color4 ~= nil)) then + color=color4 + end + ledBuf = generateLEDs(words, color) -- Write the buffer to the LEDs ws2812.write(ledBuf) diff --git a/webpage.lua b/webpage.lua index ebe7ddb..e22b378 100644 --- a/webpage.lua +++ b/webpage.lua @@ -1,6 +1,7 @@ ------------- --- The webpage for the Webserver function sendWebPage(conn,answertype) + if (ssid == nil) then ssid="Not set" end @@ -31,6 +32,28 @@ function sendWebPage(conn,answertype) local hexColor2 = "#" .. string.format("%02x",string.byte(color2,1)) .. string.format("%02x",string.byte(color2,2)) .. string.format("%02x",string.byte(color2,3)) local hexColor3 = "#" .. string.format("%02x",string.byte(color3,1)) .. string.format("%02x",string.byte(color3,2)) .. string.format("%02x",string.byte(color3,3)) local hexColor4 = "#" .. string.format("%02x",string.byte(color4,1)) .. string.format("%02x",string.byte(color4,2)) .. string.format("%02x",string.byte(color4,3)) + + + -- hack for the second part of the page + buf=nil + if (answertype==10) then + buf = "Color 1. Minute" + buf = buf .."Color 2. Minute" + buf = buf .."Color 3. Minute" + buf = buf .."Color 4. Minute" + buf = buf .."Three quaterDreiviertel Joa/nei" + buf = buf .. "
" + buf = buf .. "
" + buf = buf .."" + conn:send(buf) + buf=nil + collectgarbage() + -- Code will only be added once the page is loaded + endOfPage=true + return + end + + local buf="HTTP/1.1 200 OK\nServer: NodeMCU\nContent-Type: text/html\n\n" if (node.heap() < 8000) then buf = buf .. "

Busy, please come later again

" @@ -46,14 +69,7 @@ function sendWebPage(conn,answertype) buf = buf .."SNTP Serverntp server to sync the time" buf = buf .."Offset to UTC timeDefine the offset to UTC time in hours. E.g +1" buf = buf .."Color" - --buf = buf .."Color 1. Min" - --buf = buf .."Color 2. Min" - --buf = buf .."Color 3. Min" - --buf = buf .."Color 4. Min" - buf = buf .."Three quaterDreiviertel Joa/nei" - buf = buf .. "
" - buf = buf .. "
" - buf = buf .."" + if answertype==2 then buf = buf .. "

New configuration saved" elseif answertype==3 then diff --git a/webserver.lua b/webserver.lua index 56dd40a..c899649 100644 --- a/webserver.lua +++ b/webserver.lua @@ -17,13 +17,18 @@ function startWebServer() end ssid, password, bssid_set, bssid = wifi.sta.getconfig() + endOfPage=false sendWebPage(conn,1) conn:on("sent", function(conn) - conn:close() - -- Clear the webpage generation - sendWebPage=nil - print("Clean webpage from RAM") - collectgarbage() + if (endOfPage==true) then + conn:close() + -- Clear the webpage generation + sendWebPage=nil + print("Clean webpage from RAM") + collectgarbage() + else + sendWebPage(conn,10) + end end)