Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
eb703a1165 | ||
|
8001a8e1d4 | ||
|
bf61184217 | ||
|
a13d74e005 | ||
|
d6cc8f73cc | ||
|
a2df4e3137 | ||
|
6160e00e17 | ||
|
f440ccf684 | ||
|
1755c9ef5a | ||
|
a755a1e5b3 | ||
|
017aef74f6 | ||
|
689ef10922 | ||
|
ad9beccadc | ||
|
db3a1e5e20 | ||
|
35a802009b |
22
init.lua
22
init.lua
@ -17,6 +17,7 @@ end)
|
|||||||
bootledtimer:start()
|
bootledtimer:start()
|
||||||
|
|
||||||
function mydofile(mod)
|
function mydofile(mod)
|
||||||
|
print("load:" .. mod)
|
||||||
if (file.open(mod .. ".lua")) then
|
if (file.open(mod .. ".lua")) then
|
||||||
dofile( mod .. ".lua")
|
dofile( mod .. ".lua")
|
||||||
elseif (file.open(mod .. "_diet.lua")) then
|
elseif (file.open(mod .. "_diet.lua")) then
|
||||||
@ -36,7 +37,7 @@ initTimer:register(5000, tmr.ALARM_SINGLE, function (t)
|
|||||||
initTimer:unregister()
|
initTimer:unregister()
|
||||||
initTimer=nil
|
initTimer=nil
|
||||||
bootledtimer=nil
|
bootledtimer=nil
|
||||||
local modlist = { "timecore" , "displayword", "ds18b20", "mqtt", "main" }
|
local modlist = { "timecore" , "displayword", "ds18b20", "mqtt", "main", "webserver" }
|
||||||
for i,mod in pairs(modlist) do
|
for i,mod in pairs(modlist) do
|
||||||
if (file.open(mod .. "_diet.lua")) then
|
if (file.open(mod .. "_diet.lua")) then
|
||||||
file.remove(mod .. "_diet.lc")
|
file.remove(mod .. "_diet.lc")
|
||||||
@ -59,6 +60,25 @@ initTimer:register(5000, tmr.ALARM_SINGLE, function (t)
|
|||||||
normalOperation()
|
normalOperation()
|
||||||
else
|
else
|
||||||
-- Logic for inital setup
|
-- Logic for inital setup
|
||||||
|
collectgarbage()
|
||||||
|
wifi.setmode(wifi.SOFTAP)
|
||||||
|
cfg={}
|
||||||
|
cfg.ssid="wordclock"
|
||||||
|
cfg.pwd="wordclock"
|
||||||
|
wifi.ap.config(cfg)
|
||||||
|
|
||||||
|
-- Write the buffer to the LEDs
|
||||||
|
local color=string.char(0,128,0)
|
||||||
|
local white=string.char(0,0,0)
|
||||||
|
local ledBuf= white:rep(6) .. color .. white:rep(7) .. color:rep(3) .. white:rep(44) .. color:rep(3) .. white:rep(50)
|
||||||
|
ws2812.write(ledBuf)
|
||||||
|
color=nil
|
||||||
|
white=nil
|
||||||
|
ledBuf=nil
|
||||||
|
|
||||||
|
print("Waiting in access point >wordclock< for Clients")
|
||||||
|
print("Please visit 192.168.4.1")
|
||||||
|
-- start the webserver module
|
||||||
mydofile("webserver")
|
mydofile("webserver")
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
30
main.lua
30
main.lua
@ -8,6 +8,7 @@ rgbBuffer = ws2812.newBuffer(114, 3)
|
|||||||
|
|
||||||
function syncTimeFromInternet()
|
function syncTimeFromInternet()
|
||||||
if (syncRunning == nil) then
|
if (syncRunning == nil) then
|
||||||
|
print("NTP: " .. tostring(sntpserverhostname))
|
||||||
syncRunning=true
|
syncRunning=true
|
||||||
sntp.sync(sntpserverhostname,
|
sntp.sync(sntpserverhostname,
|
||||||
function(sec,usec,server)
|
function(sec,usec,server)
|
||||||
@ -55,7 +56,6 @@ function displayTime()
|
|||||||
package.loaded["wordclock_diet"]=nil
|
package.loaded["wordclock_diet"]=nil
|
||||||
|
|
||||||
collectgarbage()
|
collectgarbage()
|
||||||
print("wc: " .. tostring(node.heap()))
|
|
||||||
local dw = require("displayword_diet")
|
local dw = require("displayword_diet")
|
||||||
if (dw ~= nil) then
|
if (dw ~= nil) then
|
||||||
--if lines 4 to 6 are inverted due to hardware-fuckup, unfuck it here
|
--if lines 4 to 6 are inverted due to hardware-fuckup, unfuck it here
|
||||||
@ -109,6 +109,7 @@ function normalOperation()
|
|||||||
rgbBuffer:set(55, color) -- P
|
rgbBuffer:set(55, color) -- P
|
||||||
end
|
end
|
||||||
elseif (setupCounter > 3) then
|
elseif (setupCounter > 3) then
|
||||||
|
if (web == nil) then
|
||||||
-- Here the WLAN is found, and something is done
|
-- Here the WLAN is found, and something is done
|
||||||
mydofile("mqtt")
|
mydofile("mqtt")
|
||||||
rgbBuffer:fill(0,0,0) -- disable all LEDs
|
rgbBuffer:fill(0,0,0) -- disable all LEDs
|
||||||
@ -124,13 +125,20 @@ function normalOperation()
|
|||||||
print("NO Mqtt found")
|
print("NO Mqtt found")
|
||||||
mydofile("telnet")
|
mydofile("telnet")
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
print("webserver prepared")
|
||||||
|
end
|
||||||
setupCounter=setupCounter-1
|
setupCounter=setupCounter-1
|
||||||
elseif (setupCounter > 2) then
|
elseif (setupCounter > 2) then
|
||||||
|
if (web == nil) then
|
||||||
if (startTelnetServer ~= nil) then
|
if (startTelnetServer ~= nil) then
|
||||||
startTelnetServer()
|
startTelnetServer()
|
||||||
else
|
else
|
||||||
displayTime()
|
displayTime()
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
print("webserver supplant telnet")
|
||||||
|
end
|
||||||
setupCounter=setupCounter-1
|
setupCounter=setupCounter-1
|
||||||
elseif ( (alive % 120) == 0) then
|
elseif ( (alive % 120) == 0) then
|
||||||
-- sync the time every 5 minutes
|
-- sync the time every 5 minutes
|
||||||
@ -141,6 +149,11 @@ function normalOperation()
|
|||||||
heapusage=nil
|
heapusage=nil
|
||||||
alive = alive + 1
|
alive = alive + 1
|
||||||
else
|
else
|
||||||
|
if (colorBg ~= nil) then
|
||||||
|
rgbBuffer:fill(string.byte(colorBg,1), string.byte(colorBg,2), string.byte(colorBg,3)) -- disable all LEDs
|
||||||
|
else
|
||||||
|
rgbBuffer:fill(0,0,0) -- disable all LEDs
|
||||||
|
end
|
||||||
displayTime()
|
displayTime()
|
||||||
alive = alive + 1
|
alive = alive + 1
|
||||||
end
|
end
|
||||||
@ -225,17 +238,30 @@ gpio.mode(3, gpio.INPUT)
|
|||||||
local btnCounter=0
|
local btnCounter=0
|
||||||
-- Start the time Thread handling the button
|
-- Start the time Thread handling the button
|
||||||
local btntimer = tmr.create()
|
local btntimer = tmr.create()
|
||||||
btntimer:register(5000, tmr.ALARM_AUTO, function (t)
|
btntimer:register(500, tmr.ALARM_AUTO, function (t)
|
||||||
if (gpio.read(3) == 0) then
|
if (gpio.read(3) == 0) then
|
||||||
|
-- stop the main loop
|
||||||
|
if (mlt ~= nil) then
|
||||||
mlt:unregister()
|
mlt:unregister()
|
||||||
|
mlt = nil
|
||||||
|
end
|
||||||
print("Button pressed " .. tostring(btnCounter))
|
print("Button pressed " .. tostring(btnCounter))
|
||||||
btnCounter = btnCounter + 5
|
btnCounter = btnCounter + 5
|
||||||
|
|
||||||
|
if ((web ~= nil) and (btnCounter < 50)) then
|
||||||
for i=1,btnCounter do rgbBuffer:set(i, 128, 0, 0) end
|
for i=1,btnCounter do rgbBuffer:set(i, 128, 0, 0) end
|
||||||
|
else
|
||||||
|
for i=1,btnCounter do rgbBuffer:set(i, 0, 128, 0) end
|
||||||
|
end
|
||||||
ws2812.write(rgbBuffer)
|
ws2812.write(rgbBuffer)
|
||||||
if (btnCounter >= 110) then
|
if (btnCounter >= 110) then
|
||||||
file.remove("config.lua")
|
file.remove("config.lua")
|
||||||
file.remove("config.lc")
|
file.remove("config.lc")
|
||||||
node.restart()
|
node.restart()
|
||||||
|
elseif (btnCounter == 10) then
|
||||||
|
collectgarbage()
|
||||||
|
mydofile("webserver")
|
||||||
|
-- start the webserver module
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
#
|
#
|
||||||
# ESP8266 & ESP32 family ROM Bootloader Utility
|
# ESP8266 & ESP32 family ROM Bootloader Utility
|
||||||
# Copyright (C) 2014-2016 Fredrik Ahlberg, Angus Gratton, Espressif Systems (Shanghai) PTE LTD, other contributors as noted.
|
# Copyright (C) 2014-2016 Fredrik Ahlberg, Angus Gratton, Espressif Systems (Shanghai) PTE LTD, other contributors as noted.
|
||||||
|
@ -48,6 +48,10 @@ if [ "$FILES" != "config.lua" ]; then
|
|||||||
echo "Compress $f ..."
|
echo "Compress $f ..."
|
||||||
out=$(echo "$f" | sed 's/.lua/_diet.lua/g')
|
out=$(echo "$f" | sed 's/.lua/_diet.lua/g')
|
||||||
$DIET ../$f -o ../diet/$out
|
$DIET ../$f -o ../diet/$out
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "Failed to generate file"
|
||||||
|
exit $?
|
||||||
|
fi
|
||||||
OUTFILES="$OUTFILES diet/$out"
|
OUTFILES="$OUTFILES diet/$out"
|
||||||
else
|
else
|
||||||
OUTFILES="$OUTFILES $f"
|
OUTFILES="$OUTFILES $f"
|
||||||
|
@ -47,7 +47,14 @@ 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.</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.</td></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</td></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</td></tr>
|
||||||
<tr><th>Foreground Color</th><td><input type="color" name="fcolor" value="$HEXCOLORFG"></td><td>LED Color for all minutes, divisible by five</td></tr>
|
<tr><th>General Foreground Color</th><td><input type="color" name="fcolor" value="$HEXCOLORFG"></td><td>LED Color for all minutes, divisible by five</td></tr>
|
||||||
|
<tr><th>Foreground Color Minute1</th><td><input type="color" name="mcolor1" value="$HEXCOLOR1"></td><td>LED Color for first single minute</td></tr>
|
||||||
|
<tr><th>Foreground Color Minute2</th><td><input type="color" name="mcolor2" value="$HEXCOLOR2"></td><td>LED Color for second single minute</td></tr>
|
||||||
|
<tr><th>Foreground Color Minute3</th><td><input type="color" name="mcolor3" value="$HEXCOLOR3"></td><td>LED Color for third single minute</td></tr>
|
||||||
|
<tr><th>Foreground Color Minute4</th><td><input type="color" name="mcolor4" value="$HEXCOLOR4"></td><td>LED Color for fourth single minute</td></tr>
|
||||||
|
<tr><th>Threequarter</th><td><input type="checkbox" name="threequarter" $THREEQUATER></td><td>3/4 instead of 1/4 before</td></tr>
|
||||||
|
<tr><th>Adjust brightness</th><td><input type="checkbox" name="dim" $AUTODIM></td><td>Dim brightness automatically</td></tr>
|
||||||
|
<input type="hidden" value="true" name="web" /><!-- Activate Webserver only -->
|
||||||
<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>
|
<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>
|
||||||
<tr><td colspan="3"><div align="center"><input type="submit" name="action" value="Reboot"></div></td></tr>
|
<tr><td colspan="3"><div align="center"><input type="submit" name="action" value="Reboot"></div></td></tr>
|
||||||
</table>
|
</table>
|
||||||
|
137
webserver.lua
137
webserver.lua
@ -2,9 +2,28 @@
|
|||||||
local configFile="config.lua"
|
local configFile="config.lua"
|
||||||
local httpSending=false
|
local httpSending=false
|
||||||
local sentBytes=0
|
local sentBytes=0
|
||||||
|
|
||||||
|
-- Source https://stackoverflow.com/questions/28916182/parse-parameters-out-of-url-in-lua#28921280
|
||||||
|
function urldecode(s)
|
||||||
|
s = s:gsub('+', ' ')
|
||||||
|
:gsub('%%(%x%x)', function(h)
|
||||||
|
return string.char(tonumber(h, 16))
|
||||||
|
end)
|
||||||
|
return s
|
||||||
|
end
|
||||||
|
|
||||||
function sendPage(conn, nameOfFile, replaceMap)
|
function sendPage(conn, nameOfFile, replaceMap)
|
||||||
collectgarbage()
|
collectgarbage()
|
||||||
print("Sending " .. nameOfFile .. " " .. sentBytes .. "B already; " .. node.heap() .. "B in heap")
|
print("Sending " .. nameOfFile .. " " .. sentBytes .. "B already; " .. node.heap() .. "B in heap")
|
||||||
|
if (sentBytes == 0) then
|
||||||
|
-- print status status
|
||||||
|
local statusColor=string.char(0,128,0)
|
||||||
|
if ((inv46 ~= nil) and (inv46 == "on")) then
|
||||||
|
ws2812.write(string.char(0,0,0):rep(55) .. statusColor:rep(2) .. string.char(0,0,0):rep(5) .. statusColor .. string.char(0,0,0):rep(49))
|
||||||
|
else
|
||||||
|
ws2812.write(string.char(0,0,0):rep(57) .. statusColor .. string.char(0,0,0):rep(5) .. statusColor:rep(2) .. string.char(0,0,0):rep(49))
|
||||||
|
end
|
||||||
|
end
|
||||||
conn:on("sent", function(conn)
|
conn:on("sent", function(conn)
|
||||||
if (sentBytes == 0) then
|
if (sentBytes == 0) then
|
||||||
conn:close()
|
conn:close()
|
||||||
@ -32,6 +51,9 @@ function sendPage(conn, nameOfFile, replaceMap)
|
|||||||
local line = file.readline()
|
local line = file.readline()
|
||||||
|
|
||||||
while (line ~= nil) do
|
while (line ~= nil) do
|
||||||
|
-- increase the amount of sent bytes
|
||||||
|
sentBytes=sentBytes+string.len(line)
|
||||||
|
|
||||||
-- all placeholder begin with a $, so search for it in the current line
|
-- all placeholder begin with a $, so search for it in the current line
|
||||||
if (line:find("$") ~= nil) then
|
if (line:find("$") ~= nil) then
|
||||||
-- Replace the placeholder with the dynamic content
|
-- Replace the placeholder with the dynamic content
|
||||||
@ -43,10 +65,6 @@ function sendPage(conn, nameOfFile, replaceMap)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- increase the amount of sent bytes
|
|
||||||
sentBytes=sentBytes+string.len(line)
|
|
||||||
|
|
||||||
buf = buf .. line
|
buf = buf .. line
|
||||||
|
|
||||||
-- Sent after 500 bytes data
|
-- Sent after 500 bytes data
|
||||||
@ -67,6 +85,13 @@ function sendPage(conn, nameOfFile, replaceMap)
|
|||||||
if (string.len(buf) > 0) then
|
if (string.len(buf) > 0) then
|
||||||
conn:send(buf)
|
conn:send(buf)
|
||||||
print("Sent rest")
|
print("Sent rest")
|
||||||
|
-- print status status
|
||||||
|
local statusColor=string.char(128,0,0)
|
||||||
|
if ((inv46 ~= nil) and (inv46 == "on")) then
|
||||||
|
ws2812.write(string.char(0,0,0):rep(55) .. statusColor:rep(2) .. string.char(0,0,0):rep(5) .. statusColor .. string.char(0,0,0):rep(49))
|
||||||
|
else
|
||||||
|
ws2812.write(string.char(0,0,0):rep(57) .. statusColor .. string.char(0,0,0):rep(5) .. statusColor:rep(2) .. string.char(0,0,0):rep(49))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -107,6 +132,14 @@ function fillDynamicMap()
|
|||||||
return replaceMap
|
return replaceMap
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function readHex(source, variable)
|
||||||
|
local hexColor=string.sub(source, 4)
|
||||||
|
local red = tonumber(string.sub(hexColor, 1, 2), 16)
|
||||||
|
local green = tonumber(string.sub(hexColor, 3, 4), 16)
|
||||||
|
local blue = tonumber(string.sub(hexColor, 5, 6), 16)
|
||||||
|
file.write(variable.."=string.char(" .. green .. "," .. red .. "," .. blue .. ")\n")
|
||||||
|
end
|
||||||
|
|
||||||
function startWebServer()
|
function startWebServer()
|
||||||
srv=net.createServer(net.TCP)
|
srv=net.createServer(net.TCP)
|
||||||
srv:listen(80,function(conn)
|
srv:listen(80,function(conn)
|
||||||
@ -120,9 +153,9 @@ function startWebServer()
|
|||||||
if (color == nil) then
|
if (color == nil) then
|
||||||
color=string.char(0,128,0)
|
color=string.char(0,128,0)
|
||||||
end
|
end
|
||||||
ws2812.write(string.char(0,0,0):rep(56) .. color:rep(2) .. string.char(0,0,0):rep(4) .. color:rep(2) .. string.char(0,0,0):rep(48))
|
|
||||||
if (sendPage ~= nil) then
|
if (sendPage ~= nil) then
|
||||||
print("Sending webpage.html (" .. tostring(node.heap()) .. "B free) ...")
|
print("Sending webpage.html (" .. tostring(node.heap()) .. "B free) ...")
|
||||||
|
mydofile("config")
|
||||||
-- Load the sendPagewebcontent
|
-- Load the sendPagewebcontent
|
||||||
replaceMap=fillDynamicMap()
|
replaceMap=fillDynamicMap()
|
||||||
sendPage(conn, "webpage.html", replaceMap)
|
sendPage(conn, "webpage.html", replaceMap)
|
||||||
@ -156,68 +189,47 @@ function startWebServer()
|
|||||||
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" .. "station_cfg={}\nstation_cfg.ssid=\"" .. _POST.ssid .. "\"\nstation_cfg.pwd=\"" .. _POST.password .. "\"\nstation_cfg.save=false\nwifi.sta.config(station_cfg)\n")
|
file.write("-- Config\n" .. "station_cfg={}\nstation_cfg.ssid='" .. urldecode(_POST.ssid) .. "'\nstation_cfg.pwd='" .. urldecode(_POST.password) .. "'\nstation_cfg.save=false\nwifi.sta.config(station_cfg)\n")
|
||||||
file.write("sntpserverhostname=\"" .. _POST.sntpserver .. "\"\n" .. "timezoneoffset=\"" .. _POST.timezoneoffset .. "\"\n".. "inv46=\"" .. tostring(_POST.inv46) .. "\"\n" .. "dim=\"" .. tostring(_POST.dim) .. "\"\n")
|
file.write("sntpserverhostname=\"" .. _POST.sntpserver .. "\"\n" .. "timezoneoffset=\"" .. _POST.timezoneoffset .. "\"\n".. "inv46=nil\n")
|
||||||
|
|
||||||
if ( _POST.fcolor ~= nil) then
|
if ( _POST.fcolor ~= nil) then
|
||||||
-- color=string.char(_POST.green, _POST.red, _POST.blue)
|
-- color=string.char(_POST.green, _POST.red, _POST.blue)
|
||||||
print ("Got fcolor: " .. _POST.fcolor)
|
print ("Got fcolor: " .. _POST.fcolor)
|
||||||
local hexColor=string.sub(_POST.fcolor, 4)
|
readHex(_POST.fcolor, "color")
|
||||||
local red = tonumber(string.sub(hexColor, 1, 2), 16)
|
|
||||||
local green = tonumber(string.sub(hexColor, 3, 4), 16)
|
|
||||||
local blue = tonumber(string.sub(hexColor, 5, 6), 16)
|
|
||||||
file.write("color=string.char(" .. green .. "," .. red .. "," .. blue .. ")\n")
|
|
||||||
-- fill the current values
|
|
||||||
color=string.char(green, red, blue)
|
|
||||||
end
|
end
|
||||||
if ( _POST.colorMin1 ~= nil) then
|
if ( _POST.mcolor1 ~= nil) then
|
||||||
local hexColor=string.sub(_POST.colorMin1, 4)
|
readHex(_POST.mcolor1, "color1")
|
||||||
local red = tonumber(string.sub(hexColor, 1, 2), 16)
|
|
||||||
local green = tonumber(string.sub(hexColor, 3, 4), 16)
|
|
||||||
local blue = tonumber(string.sub(hexColor, 5, 6), 16)
|
|
||||||
file.write("color1=string.char(" .. green .. "," .. red .. "," .. blue .. ")\n")
|
|
||||||
-- fill the current values
|
|
||||||
color1=string.char(green, red, blue)
|
|
||||||
end
|
end
|
||||||
if ( _POST.colorMin2 ~= nil) then
|
if ( _POST.mcolor2 ~= nil) then
|
||||||
local hexColor=string.sub(_POST.colorMin2, 4)
|
readHex(_POST.mcolor2, "color2")
|
||||||
local red = tonumber(string.sub(hexColor, 1, 2), 16)
|
|
||||||
local green = tonumber(string.sub(hexColor, 3, 4), 16)
|
|
||||||
local blue = tonumber(string.sub(hexColor, 5, 6), 16)
|
|
||||||
file.write("color2=string.char(" .. green .. "," .. red .. "," .. blue .. ")\n")
|
|
||||||
-- fill the current values
|
|
||||||
color2=string.char(green, red, blue)
|
|
||||||
end
|
end
|
||||||
if ( _POST.colorMin3 ~= nil) then
|
if ( _POST.mcolor3 ~= nil) then
|
||||||
local hexColor=string.sub(_POST.colorMin3, 4)
|
readHex(_POST.mcolor3, "color3")
|
||||||
local red = tonumber(string.sub(hexColor, 1, 2), 16)
|
|
||||||
local green = tonumber(string.sub(hexColor, 3, 4), 16)
|
|
||||||
local blue = tonumber(string.sub(hexColor, 5, 6), 16)
|
|
||||||
file.write("color3=string.char(" .. green .. "," .. red .. "," .. blue .. ")\n")
|
|
||||||
-- fill the current values
|
|
||||||
color3=string.char(green, red, blue)
|
|
||||||
end
|
end
|
||||||
if ( _POST.colorMin4 ~= nil) then
|
if ( _POST.mcolor4 ~= nil) then
|
||||||
local hexColor=string.sub(_POST.colorMin4, 4)
|
readHex(_POST.mcolor4, "color4")
|
||||||
local red = tonumber(string.sub(hexColor, 1, 2), 16)
|
|
||||||
local green = tonumber(string.sub(hexColor, 3, 4), 16)
|
|
||||||
local blue = tonumber(string.sub(hexColor, 5, 6), 16)
|
|
||||||
file.write("color4=string.char(" .. green .. "," .. red .. "," .. blue .. ")\n")
|
|
||||||
-- fill the current values
|
|
||||||
color4=string.char(green, red, blue)
|
|
||||||
end
|
end
|
||||||
if ( _POST.bcolor ~= nil) then
|
if ( _POST.bcolor ~= nil) then
|
||||||
local hexColor=string.sub(_POST.bcolor, 4)
|
local hexColor=string.sub(_POST.bcolor, 4)
|
||||||
local red = tonumber(string.sub(hexColor, 1, 2), 16)
|
readHex(_POST.bcolor, "colorBg")
|
||||||
local green = tonumber(string.sub(hexColor, 3, 4), 16)
|
|
||||||
local blue = tonumber(string.sub(hexColor, 5, 6), 16)
|
|
||||||
file.write("colorBg=string.char(" .. green .. "," .. red .. "," .. blue .. ")\n")
|
|
||||||
-- fill the current values
|
|
||||||
colorBg=string.char(green, red, blue)
|
|
||||||
end
|
end
|
||||||
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
|
||||||
|
if (_POST.web ~= nil) then
|
||||||
|
file.write("web=true\n")
|
||||||
|
-- fill the current values
|
||||||
|
web=true
|
||||||
|
else
|
||||||
|
file.write("web=nil\n") -- use webserver instead of mqtt or telnet
|
||||||
|
-- fill the current values
|
||||||
|
web=nil
|
||||||
|
end
|
||||||
|
if (_POST.dim ~= nil) then
|
||||||
|
file.write("dim=\"" .. tostring(_POST.dim) .. "\"\n")
|
||||||
|
else
|
||||||
|
file.write("dim=nil\n") -- unset dimming functionality
|
||||||
end
|
end
|
||||||
if (_POST.threequater ~= nil) then
|
if (_POST.threequater ~= nil) then
|
||||||
file.write("threequater=true\n")
|
file.write("threequater=true\n")
|
||||||
@ -237,6 +249,7 @@ function startWebServer()
|
|||||||
print("Successfully")
|
print("Successfully")
|
||||||
local mytimer = tmr.create()
|
local mytimer = tmr.create()
|
||||||
mytimer:register(50, tmr.ALARM_SINGLE, function (t)
|
mytimer:register(50, tmr.ALARM_SINGLE, function (t)
|
||||||
|
mydofile("config")
|
||||||
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")
|
||||||
@ -291,25 +304,5 @@ function startWebServer()
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- start the webserver module
|
|
||||||
collectgarbage()
|
|
||||||
wifi.setmode(wifi.SOFTAP)
|
|
||||||
cfg={}
|
|
||||||
cfg.ssid="wordclock"
|
|
||||||
cfg.pwd="wordclock"
|
|
||||||
wifi.ap.config(cfg)
|
|
||||||
|
|
||||||
-- Write the buffer to the LEDs
|
|
||||||
local color=string.char(0,128,0)
|
|
||||||
local white=string.char(0,0,0)
|
|
||||||
local ledBuf= white:rep(6) .. color .. white:rep(7) .. color:rep(3) .. white:rep(44) .. color:rep(3) .. white:rep(50)
|
|
||||||
ws2812.write(ledBuf)
|
|
||||||
color=nil
|
|
||||||
white=nil
|
|
||||||
ledBuf=nil
|
|
||||||
|
|
||||||
print("Waiting in access point >wordclock< for Clients")
|
|
||||||
print("Please visit 192.168.4.1")
|
|
||||||
startWebServer()
|
startWebServer()
|
||||||
collectgarbage()
|
collectgarbage()
|
Loading…
Reference in New Issue
Block a user