A different color can be selected for each minute
This commit is contained in:
parent
093ab81c34
commit
a20064bf61
11
main.lua
11
main.lua
@ -47,6 +47,17 @@ function displayTime()
|
|||||||
time = getTime(sec, timezoneoffset)
|
time = getTime(sec, timezoneoffset)
|
||||||
print("Local time : " .. time.year .. "-" .. time.month .. "-" .. time.day .. " " .. time.hour .. ":" .. time.minute .. ":" .. time.second)
|
print("Local time : " .. time.year .. "-" .. time.month .. "-" .. time.day .. " " .. time.hour .. ":" .. time.minute .. ":" .. time.second)
|
||||||
words = display_timestat(time.hour, time.minute)
|
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)
|
ledBuf = generateLEDs(words, color)
|
||||||
-- Write the buffer to the LEDs
|
-- Write the buffer to the LEDs
|
||||||
ws2812.write(ledBuf)
|
ws2812.write(ledBuf)
|
||||||
|
32
webpage.lua
32
webpage.lua
@ -1,6 +1,7 @@
|
|||||||
-------------
|
-------------
|
||||||
--- The webpage for the Webserver
|
--- The webpage for the Webserver
|
||||||
function sendWebPage(conn,answertype)
|
function sendWebPage(conn,answertype)
|
||||||
|
|
||||||
if (ssid == nil) then
|
if (ssid == nil) then
|
||||||
ssid="Not set"
|
ssid="Not set"
|
||||||
end
|
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 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 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))
|
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 = "<tr><th>Color 1. Minute</th><td><input type=\"color\" name=\"colorMin1\" value=\"" .. hexColor1 .. "\"></td><td /></tr>"
|
||||||
|
buf = buf .."<tr><th>Color 2. Minute</th><td><input type=\"color\" name=\"colorMin2\" value=\"" .. hexColor2 .. "\"></td><td /></tr>"
|
||||||
|
buf = buf .."<tr><th>Color 3. Minute</th><td><input type=\"color\" name=\"colorMin3\" value=\"" .. hexColor3 .. "\"></td><td /></tr>"
|
||||||
|
buf = buf .."<tr><th>Color 4. Minute</th><td><input type=\"color\" name=\"colorMin4\" value=\"" .. hexColor4 .. "\"></td><td /></tr>"
|
||||||
|
buf = buf .."<tr><th>Three quater</th><td><input type=\"checkbox\" name=\"threequater\" ".. (threequater and "checked" or "") .. "></td><td>Dreiviertel Joa/nei</td></tr>"
|
||||||
|
buf = buf .. "<tr><td colspan=\"3\"><div align=\"center\"><input type=\"submit\" value=\"Save Configuration\" onclick=\"this.value='Submitting ..';this.disabled='disabled'; this.form.submit();\"></div></td></tr>"
|
||||||
|
buf = buf .. "<tr><td colspan=\"3\"><div align=\"center\"><input type=\"submit\" name=\"action\" value=\"Reboot\"></div></td></tr>"
|
||||||
|
buf = buf .."</table></form>"
|
||||||
|
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"
|
local buf="HTTP/1.1 200 OK\nServer: NodeMCU\nContent-Type: text/html\n\n"
|
||||||
if (node.heap() < 8000) then
|
if (node.heap() < 8000) then
|
||||||
buf = buf .. "<h1>Busy, please come later again</h1>"
|
buf = buf .. "<h1>Busy, please come later again</h1>"
|
||||||
@ -46,14 +69,7 @@ function sendWebPage(conn,answertype)
|
|||||||
buf = buf .."<tr><th>SNTP Server</th><td><input name=\"sntpserver\" value=\"" .. sntpserverhostname .. "\"></td><td>ntp server to sync the time</tr>"
|
buf = buf .."<tr><th>SNTP Server</th><td><input name=\"sntpserver\" value=\"" .. sntpserverhostname .. "\"></td><td>ntp server to sync the time</tr>"
|
||||||
buf = buf .."<tr><th>Offset to UTC time</th><td><input type=\"number\" name=\"timezoneoffset\" value=\"" .. timezoneoffset .. "\"></td><td>Define the offset to UTC time in hours. E.g +1</tr>"
|
buf = buf .."<tr><th>Offset to UTC time</th><td><input type=\"number\" name=\"timezoneoffset\" value=\"" .. timezoneoffset .. "\"></td><td>Define the offset to UTC time in hours. E.g +1</tr>"
|
||||||
buf = buf .."<tr><th>Color</th><td><input type=\"color\" name=\"fcolor\" value=\"" .. hexColor .. "\"></td><td /></tr>"
|
buf = buf .."<tr><th>Color</th><td><input type=\"color\" name=\"fcolor\" value=\"" .. hexColor .. "\"></td><td /></tr>"
|
||||||
--buf = buf .."<tr><th>Color 1. Min</th><td><input type=\"color\" name=\"colM1\" value=\"" .. hexColor1 .. "\"></td><td /></tr>"
|
|
||||||
--buf = buf .."<tr><th>Color 2. Min</th><td><input type=\"color\" name=\"colM2\" value=\"" .. hexColor2 .. "\"></td><td /></tr>"
|
|
||||||
--buf = buf .."<tr><th>Color 3. Min</th><td><input type=\"color\" name=\"colM3\" value=\"" .. hexColor3 .. "\"></td><td /></tr>"
|
|
||||||
--buf = buf .."<tr><th>Color 4. Min</th><td><input type=\"color\" name=\"colM4\" value=\"" .. hexColor4 .. "\"></td><td /></tr>"
|
|
||||||
buf = buf .."<tr><th>Three quater</th><td><input type=\"checkbox\" name=\"threequater\" ".. (threequater and "checked" or "") .. "></td><td>Dreiviertel Joa/nei</td></tr>"
|
|
||||||
buf = buf .. "<tr><td colspan=\"3\"><div align=\"center\"><input type=\"submit\" value=\"Save Configuration\" onclick=\"this.value='Submitting ..';this.disabled='disabled'; this.form.submit();\"></div></td></tr>"
|
|
||||||
buf = buf .. "<tr><td colspan=\"3\"><div align=\"center\"><input type=\"submit\" name=\"action\" value=\"Reboot\"></div></td></tr>"
|
|
||||||
buf = buf .."</table></form>"
|
|
||||||
if answertype==2 then
|
if answertype==2 then
|
||||||
buf = buf .. "<h2><font color=\"green\">New configuration saved</font></h2\n>"
|
buf = buf .. "<h2><font color=\"green\">New configuration saved</font></h2\n>"
|
||||||
elseif answertype==3 then
|
elseif answertype==3 then
|
||||||
|
@ -17,13 +17,18 @@ function startWebServer()
|
|||||||
end
|
end
|
||||||
|
|
||||||
ssid, password, bssid_set, bssid = wifi.sta.getconfig()
|
ssid, password, bssid_set, bssid = wifi.sta.getconfig()
|
||||||
|
endOfPage=false
|
||||||
sendWebPage(conn,1)
|
sendWebPage(conn,1)
|
||||||
conn:on("sent", function(conn)
|
conn:on("sent", function(conn)
|
||||||
conn:close()
|
if (endOfPage==true) then
|
||||||
-- Clear the webpage generation
|
conn:close()
|
||||||
sendWebPage=nil
|
-- Clear the webpage generation
|
||||||
print("Clean webpage from RAM")
|
sendWebPage=nil
|
||||||
collectgarbage()
|
print("Clean webpage from RAM")
|
||||||
|
collectgarbage()
|
||||||
|
else
|
||||||
|
sendWebPage(conn,10)
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user