Color can be set via the WebInterface
This commit is contained in:
parent
4ddbebd040
commit
d166fb68df
7
main.lua
7
main.lua
@ -67,8 +67,11 @@ function displayTime()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function normalOperation()
|
function normalOperation()
|
||||||
-- Color is defined as GREEN, RED, BLUE
|
-- use default color, if nothing is defined
|
||||||
color=string.char(0,0,250)
|
if (color == nil) then
|
||||||
|
-- Color is defined as GREEN, RED, BLUE
|
||||||
|
color=string.char(0,0,250)
|
||||||
|
end
|
||||||
|
|
||||||
connect_counter=0
|
connect_counter=0
|
||||||
-- Wait to be connect to the WiFi access point.
|
-- Wait to be connect to the WiFi access point.
|
||||||
|
22
webpage.lua
22
webpage.lua
@ -10,6 +10,11 @@ function sendWebPage(conn,answertype)
|
|||||||
if (timezoneoffset == nil) then
|
if (timezoneoffset == nil) then
|
||||||
timezoneoffset=1
|
timezoneoffset=1
|
||||||
end
|
end
|
||||||
|
-- Set the default color, if nothing is set
|
||||||
|
if (color == nil) then
|
||||||
|
color=string.char(0,0,250)
|
||||||
|
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>"
|
||||||
@ -17,13 +22,16 @@ function sendWebPage(conn,answertype)
|
|||||||
buf = buf .. "<html>"
|
buf = buf .. "<html>"
|
||||||
buf = buf .. "<head><title>WordClock Setup Page</title>"
|
buf = buf .. "<head><title>WordClock Setup Page</title>"
|
||||||
buf = buf .. "</head><body>\n"
|
buf = buf .. "</head><body>\n"
|
||||||
buf = buf .. "<h1>Welcome to the WordClock</h1>Please note that all settings are mandatory<br /><br />"
|
buf = buf .. "<h1>Welcome to the WordClock</h1>"
|
||||||
buf = buf .."<form action=\"\" method=\"POST\">"
|
buf = buf .."<form action=\"\" method=\"POST\">"
|
||||||
buf = buf .."<table id=\"table-6\">"
|
buf = buf .."<table>"
|
||||||
buf = buf .."<tr><th>WIFI-SSID</b></th><td><input id=\"ssid\" name=\"ssid\" value=\"" .. ssid .. "\"></td><td>SSID of the wireless network</td></tr>"
|
buf = buf .."<tr><th>WIFI-SSID</b></th><td><input name=\"ssid\" value=\"" .. ssid .. "\"></td><td /></tr>"
|
||||||
buf = buf .."<tr><th>WIFI-Password</th><td><input id=\"password\" name=\"password\"></td><td>Password of the wireless network</td></tr>"
|
buf = buf .."<tr><th>WIFI-Password</th><td><input name=\"password\"></td><td /></tr>"
|
||||||
buf = buf .."<tr><th>SNTP Server</th><td><input id=\"sntpserver\" name=\"sntpserver\" value=\"" .. sntpserverhostname .. "\"></td><td>Server to sync the time with. Only one ntp server is allowed.</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 id=\"timezoneoffset\" name=\"timezoneoffset\" value=\"" .. timezoneoffset .. "\"></td><td>Define the offset to UTC time in hours. For example +1 hour for Germany</tr>"
|
buf = buf .."<tr><th>Offset to UTC time</th><td><input name=\"timezoneoffset\" value=\"" .. timezoneoffset .. "\"></td><td>Define the offset to UTC time in hours. E.g +1</tr>"
|
||||||
|
buf = buf .."<tr><th>Red</th><td><input type=\"number\" name=\"red\" value=\"" .. string.byte(color,1) .. "\"></td><td /></tr>"
|
||||||
|
buf = buf .."<tr><th>Green</th><td><input type=\"number\" name=\"green\" value=\"" .. string.byte(color,2) .. "\"></td><td /></tr>"
|
||||||
|
buf = buf .."<tr><th>Blue</th><td><input type=\"number\" name=\"blue\" value=\"" .. string.byte(color,3) .. "\"></td><td>All Colors: 0 - 255</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\" 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 .. "<tr><td colspan=\"3\"><div align=\"center\"><input type=\"submit\" name=\"action\" value=\"Reboot\"></div></td></tr>"
|
||||||
buf = buf .."</table></form>"
|
buf = buf .."</table></form>"
|
||||||
@ -39,4 +47,4 @@ function sendWebPage(conn,answertype)
|
|||||||
conn:send(buf)
|
conn:send(buf)
|
||||||
buf=nil
|
buf=nil
|
||||||
collectgarbage()
|
collectgarbage()
|
||||||
end
|
end
|
||||||
|
@ -58,14 +58,23 @@ function startWebServer()
|
|||||||
print("Clean webpage from RAM")
|
print("Clean webpage from RAM")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
if ((_POST.ssid~=nil) and (_POST.password~=nil) and (_POST.sntpserver~=nil) and (_POST.timezoneoffset~=nil)) then
|
if ((_POST.ssid~=nil) and (_POST.sntpserver~=nil) and (_POST.timezoneoffset~=nil)) then
|
||||||
print("New config!")
|
print("New config!")
|
||||||
|
if (_POST.password==nil) then
|
||||||
|
_, password, _, _ = wifi.sta.getconfig()
|
||||||
|
print("Restoring password : " .. password)
|
||||||
|
_POST.password = password
|
||||||
|
password = nil
|
||||||
|
end
|
||||||
-- Safe configuration:
|
-- Safe configuration:
|
||||||
file.remove(configFile .. ".new")
|
file.remove(configFile .. ".new")
|
||||||
sec, _ = rtctime.get()
|
sec, _ = rtctime.get()
|
||||||
file.open(configFile.. ".new", "w+")
|
file.open(configFile.. ".new", "w+")
|
||||||
file.write("-- Config\n" .. "wifi.sta.config(\"" .. _POST.ssid .. "\",\"" .. _POST.password .. "\")\n" .. "sntpserverhostname=\"" .. _POST.sntpserver .. "\"\n" .. "timezoneoffset=\"" .. _POST.timezoneoffset .. "\"\n")
|
file.write("-- Config\n" .. "wifi.sta.config(\"" .. _POST.ssid .. "\",\"" .. _POST.password .. "\")\n" .. "sntpserverhostname=\"" .. _POST.sntpserver .. "\"\n" .. "timezoneoffset=\"" .. _POST.timezoneoffset .. "\"\n")
|
||||||
file.write("print(\"Config from " .. sec .. "\")\n")
|
if ( (_POST.red ~= nil) and (_POST.green ~= nil) and (_POST.blue ~= nil) ) then
|
||||||
|
color=string.char(_POST.red, _POST.green, _POST.blue)
|
||||||
|
end
|
||||||
|
file.write("color=string.char(" .. string.byte(color,1) .. "," .. string.byte(color, 2) .. "," .. string.byte(color, 3) .. ")\n print(\"Config from " .. sec .. "\")\n")
|
||||||
file.close()
|
file.close()
|
||||||
sec=nil
|
sec=nil
|
||||||
file.remove(configFile)
|
file.remove(configFile)
|
||||||
|
Loading…
Reference in New Issue
Block a user