Immidealty update the variables, when storing a new configuration; Another name for the foreground color in HTML page
This commit is contained in:
parent
cee1eeb6f3
commit
b0d64e4140
@ -47,7 +47,7 @@ Please note that all settings are mandatory<br /><br />
|
|||||||
<tr><th>WIFI-Password</th><td><input id="password" name="password"></td><td>Password of the wireless network</td></tr>
|
<tr><th>WIFI-Password</th><td><input id="password" name="password"></td><td>Password of the wireless network</td></tr>
|
||||||
<tr><th>SNTP Server</th><td><input id="sntpserver" name="sntpserver" value="$SNTPSERVER"></td><td>Server to sync the time with. Only one ntp server is allowed.</tr>
|
<tr><th>SNTP Server</th><td><input id="sntpserver" name="sntpserver" value="$SNTPSERVER"></td><td>Server to sync the time with. Only one ntp server is allowed.</tr>
|
||||||
<tr><th>Offset to UTC time</th><td><input id="timezoneoffset" name="timezoneoffset" value="$TIMEOFFSET"></td><td>Define the offset to UTC time in hours. For example +1 hour for Germany</tr>
|
<tr><th>Offset to UTC time</th><td><input id="timezoneoffset" name="timezoneoffset" value="$TIMEOFFSET"></td><td>Define the offset to UTC time in hours. For example +1 hour for Germany</tr>
|
||||||
<tr><th>Color</th><td><input type="color" name="fcolor" value="$HEXCOLOR"></td><td>LED Color for all minutes, divisible by five</td></tr>
|
<tr><th>Color</th><td><input type="color" name="fcolor" value="$HEXCOLORFG"></td><td>LED Color for all minutes, divisible by five</td></tr>
|
||||||
<tr><th>1. Minute Color</th><td><input type="color" name="colorMin1" value="$HEXCOLOR1"></td><td>First minute after</td></tr>
|
<tr><th>1. Minute Color</th><td><input type="color" name="colorMin1" value="$HEXCOLOR1"></td><td>First minute after</td></tr>
|
||||||
<tr><th>2. Minute Color</th><td><input type="color" name="colorMin2" value="$HEXCOLOR2"></td><td>Second minute after</td></tr>
|
<tr><th>2. Minute Color</th><td><input type="color" name="colorMin2" value="$HEXCOLOR2"></td><td>Second minute after</td></tr>
|
||||||
<tr><th>3. Minute Color</th><td><input type="color" name="colorMin3" value="$HEXCOLOR3"></td><td>Third minute after</td></tr>
|
<tr><th>3. Minute Color</th><td><input type="color" name="colorMin3" value="$HEXCOLOR3"></td><td>Third minute after</td></tr>
|
||||||
|
@ -5,7 +5,7 @@ configFile="config.lua"
|
|||||||
sentBytes=0
|
sentBytes=0
|
||||||
function sendPage(conn, nameOfFile, replaceMap)
|
function sendPage(conn, nameOfFile, replaceMap)
|
||||||
collectgarbage()
|
collectgarbage()
|
||||||
print("Sending " .. nameOfFile .. " " .. sentBytes .. "B already")
|
print("Sending " .. nameOfFile .. " " .. sentBytes .. "B already; " .. node.heap() .. "B in heap")
|
||||||
conn:on("sent", function(conn)
|
conn:on("sent", function(conn)
|
||||||
if (sentBytes == 0) then
|
if (sentBytes == 0) then
|
||||||
conn:close()
|
conn:close()
|
||||||
@ -68,7 +68,7 @@ function sendPage(conn, nameOfFile, replaceMap)
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function fillDynamicMap()
|
function fillDynamicMap()
|
||||||
replaceMap = {}
|
replaceMap = {}
|
||||||
ssid, _ = wifi.sta.getconfig()
|
ssid, _ = wifi.sta.getconfig()
|
||||||
|
|
||||||
@ -110,7 +110,7 @@ function fillDynamicMap()
|
|||||||
replaceMap["$TIMEOFFSET"]=timezoneoffset
|
replaceMap["$TIMEOFFSET"]=timezoneoffset
|
||||||
replaceMap["$THREEQUATER"]=(threequater and "checked" or "")
|
replaceMap["$THREEQUATER"]=(threequater and "checked" or "")
|
||||||
replaceMap["$ADDITIONAL_LINE"]=""
|
replaceMap["$ADDITIONAL_LINE"]=""
|
||||||
replaceMap["$HEXCOLOR"]=hexColor
|
replaceMap["$HEXCOLORFG"]=hexColor
|
||||||
replaceMap["$HEXCOLOR1"]=hexColor1
|
replaceMap["$HEXCOLOR1"]=hexColor1
|
||||||
replaceMap["$HEXCOLOR2"]=hexColor2
|
replaceMap["$HEXCOLOR2"]=hexColor2
|
||||||
replaceMap["$HEXCOLOR3"]=hexColor3
|
replaceMap["$HEXCOLOR3"]=hexColor3
|
||||||
@ -125,7 +125,7 @@ function startWebServer()
|
|||||||
|
|
||||||
if (payload:find("GET /") ~= nil) then
|
if (payload:find("GET /") ~= nil) then
|
||||||
--here is code for handling http request from a web-browser
|
--here is code for handling http request from a web-browser
|
||||||
|
|
||||||
if (sendPage ~= nil) then
|
if (sendPage ~= nil) then
|
||||||
print("Sending webpage.html ...")
|
print("Sending webpage.html ...")
|
||||||
-- Load the sendPagewebcontent
|
-- Load the sendPagewebcontent
|
||||||
@ -170,45 +170,58 @@ function startWebServer()
|
|||||||
local red = tonumber(string.sub(hexColor, 1, 2), 16)
|
local red = tonumber(string.sub(hexColor, 1, 2), 16)
|
||||||
local green = tonumber(string.sub(hexColor, 3, 4), 16)
|
local green = tonumber(string.sub(hexColor, 3, 4), 16)
|
||||||
local blue = tonumber(string.sub(hexColor, 5, 6), 16)
|
local blue = tonumber(string.sub(hexColor, 5, 6), 16)
|
||||||
color=string.char(green, red, blue)
|
file.write("color=string.char(" .. green .. "," .. red .. "," .. blue .. ")\n")
|
||||||
|
-- fill the current values
|
||||||
|
color=string.char(red, green, blue)
|
||||||
end
|
end
|
||||||
if ( _POST.colorMin1 ~= nil) then
|
if ( _POST.colorMin1 ~= nil) then
|
||||||
local hexColor=string.sub(_POST.colorMin1, 4)
|
local hexColor=string.sub(_POST.colorMin1, 4)
|
||||||
local red = tonumber(string.sub(hexColor, 1, 2), 16)
|
local red = tonumber(string.sub(hexColor, 1, 2), 16)
|
||||||
local green = tonumber(string.sub(hexColor, 3, 4), 16)
|
local green = tonumber(string.sub(hexColor, 3, 4), 16)
|
||||||
local blue = tonumber(string.sub(hexColor, 5, 6), 16)
|
local blue = tonumber(string.sub(hexColor, 5, 6), 16)
|
||||||
file.write("color1=string.char(" .. green .. "," .. red .. "," .. blue .. ")\n")
|
file.write("color1=string.char(" .. red .. "," .. green .. "," .. blue .. ")\n")
|
||||||
|
-- fill the current values
|
||||||
|
color1=string.char(red, green, blue)
|
||||||
end
|
end
|
||||||
if ( _POST.colorMin2 ~= nil) then
|
if ( _POST.colorMin2 ~= nil) then
|
||||||
local hexColor=string.sub(_POST.colorMin2, 4)
|
local hexColor=string.sub(_POST.colorMin2, 4)
|
||||||
local red = tonumber(string.sub(hexColor, 1, 2), 16)
|
local red = tonumber(string.sub(hexColor, 1, 2), 16)
|
||||||
local green = tonumber(string.sub(hexColor, 3, 4), 16)
|
local green = tonumber(string.sub(hexColor, 3, 4), 16)
|
||||||
local blue = tonumber(string.sub(hexColor, 5, 6), 16)
|
local blue = tonumber(string.sub(hexColor, 5, 6), 16)
|
||||||
file.write("color2=string.char(" .. green .. "," .. red .. "," .. blue .. ")\n")
|
file.write("color2=string.char(" .. red .. "," .. green .. "," .. blue .. ")\n")
|
||||||
|
-- fill the current values
|
||||||
|
color2=string.char(red, green, blue)
|
||||||
end
|
end
|
||||||
if ( _POST.colorMin3 ~= nil) then
|
if ( _POST.colorMin3 ~= nil) then
|
||||||
local hexColor=string.sub(_POST.colorMin3, 4)
|
local hexColor=string.sub(_POST.colorMin3, 4)
|
||||||
local red = tonumber(string.sub(hexColor, 1, 2), 16)
|
local red = tonumber(string.sub(hexColor, 1, 2), 16)
|
||||||
local green = tonumber(string.sub(hexColor, 3, 4), 16)
|
local green = tonumber(string.sub(hexColor, 3, 4), 16)
|
||||||
local blue = tonumber(string.sub(hexColor, 5, 6), 16)
|
local blue = tonumber(string.sub(hexColor, 5, 6), 16)
|
||||||
file.write("color3=string.char(" .. green .. "," .. red .. "," .. blue .. ")\n")
|
file.write("color3=string.char(" .. red .. "," .. green .. "," .. blue .. ")\n")
|
||||||
|
-- fill the current values
|
||||||
|
color3=string.char(red, green, blue)
|
||||||
end
|
end
|
||||||
if ( _POST.colorMin4 ~= nil) then
|
if ( _POST.colorMin4 ~= nil) then
|
||||||
local hexColor=string.sub(_POST.colorMin4, 4)
|
local hexColor=string.sub(_POST.colorMin4, 4)
|
||||||
local red = tonumber(string.sub(hexColor, 1, 2), 16)
|
local red = tonumber(string.sub(hexColor, 1, 2), 16)
|
||||||
local green = tonumber(string.sub(hexColor, 3, 4), 16)
|
local green = tonumber(string.sub(hexColor, 3, 4), 16)
|
||||||
local blue = tonumber(string.sub(hexColor, 5, 6), 16)
|
local blue = tonumber(string.sub(hexColor, 5, 6), 16)
|
||||||
file.write("color4=string.char(" .. green .. "," .. red .. "," .. blue .. ")\n")
|
file.write("color4=string.char(" .. red .. "," .. green .. "," .. blue .. ")\n")
|
||||||
|
-- fill the current values
|
||||||
|
color4=string.char(red, green, blue)
|
||||||
end
|
end
|
||||||
file.write("color=string.char(" .. string.byte(color,1) .. "," .. string.byte(color, 2) .. "," .. string.byte(color, 3) .. ")\n")
|
|
||||||
if (getTime ~= nil) then
|
if (getTime ~= nil) then
|
||||||
time = getTime(sec, timezoneoffset)
|
time = getTime(sec, timezoneoffset)
|
||||||
file.write("print(\"Config from " .. time.year .. "-" .. time.month .. "-" .. time.day .. " " .. time.hour .. ":" .. time.minute .. ":" .. time.second .. "\")\n")
|
file.write("print(\"Config from " .. time.year .. "-" .. time.month .. "-" .. time.day .. " " .. time.hour .. ":" .. time.minute .. ":" .. time.second .. "\")\n")
|
||||||
end
|
end
|
||||||
if (_POST.threequater ~= nil) then
|
if (_POST.threequater ~= nil) then
|
||||||
file.write("threequater=true\n")
|
file.write("threequater=true\n")
|
||||||
|
-- fill the current values
|
||||||
|
threequater=true
|
||||||
else
|
else
|
||||||
file.write("threequater=nil\n") -- unset threequater
|
file.write("threequater=nil\n") -- unset threequater
|
||||||
|
-- fill the current values
|
||||||
|
threequater=nil
|
||||||
end
|
end
|
||||||
file.close()
|
file.close()
|
||||||
collectgarbage()
|
collectgarbage()
|
||||||
@ -217,15 +230,14 @@ function startWebServer()
|
|||||||
print("Rename config")
|
print("Rename config")
|
||||||
if (file.rename(configFile .. ".new", configFile)) then
|
if (file.rename(configFile .. ".new", configFile)) then
|
||||||
print("Successfully")
|
print("Successfully")
|
||||||
tmr.alarm(3, 5, 0 ,function()
|
tmr.alarm(3, 20, 0 ,function()
|
||||||
dofile(configFile) -- load the new values
|
|
||||||
replaceMap=fillDynamicMap()
|
replaceMap=fillDynamicMap()
|
||||||
replaceMap["$ADDITIONAL_LINE"]="<h2><font color=\"green\">New configuration saved</font></h2>"
|
replaceMap["$ADDITIONAL_LINE"]="<h2><font color=\"green\">New configuration saved</font></h2>"
|
||||||
print("Send success to client")
|
print("Send success to client")
|
||||||
sendPage(conn, "webpage.html", replaceMap)
|
sendPage(conn, "webpage.html", replaceMap)
|
||||||
end)
|
end)
|
||||||
else
|
else
|
||||||
tmr.alarm(3, 5, 0 ,function()
|
tmr.alarm(3, 20, 0 ,function()
|
||||||
replaceMap=fillDynamicMap()
|
replaceMap=fillDynamicMap()
|
||||||
replaceMap["$ADDITIONAL_LINE"]="<h2><font color=\"red\">ERROR</font></h2>"
|
replaceMap["$ADDITIONAL_LINE"]="<h2><font color=\"red\">ERROR</font></h2>"
|
||||||
sendPage(conn, "webpage.html", replaceMap)
|
sendPage(conn, "webpage.html", replaceMap)
|
||||||
|
Loading…
Reference in New Issue
Block a user