Compare commits

..

No commits in common. "master" and "ollo" have entirely different histories.
master ... ollo

12 changed files with 356 additions and 185 deletions

268
diet/webserver_diet.lua Normal file
View File

@ -0,0 +1,268 @@
local o="config.lua"
local n=false
local t=0
function sendPage(o,e,i)
collectgarbage()
print("Sending "..e.." "..t.."B already; "..node.heap().."B in heap")
o:on("sent",function(a)
if(t==0)then
a:close()
print("Page sent")
collectgarbage()
n=false
else
collectgarbage()
sendPage(a,e,i)
end
end)
if file.open(e,"r")then
local e=""
if(t<=0)then
e=e.."HTTP/1.1 200 OK\r\n"
e=e.."Content-Type: text/html\r\n"
e=e.."Connection: close\r\n"
e=e.."Date: Thu, 29 Dec 2016 20:18:20 GMT\r\n"
e=e.."\r\n\r\n"
end
file.seek("set",t)
local a=file.readline()
while(a~=nil)do
if(a:find("$")~=nil)then
if(i~=nil)then
for e,t in pairs(i)
do
a=string.gsub(a,e,t)
end
end
end
t=t+string.len(a)
e=e..a
if((string.len(e)>=500)or(node.heap()<2000))then
a=nil
o:send(e)
print("Sent part of "..t.."B")
return
else
a=file.readline()
end
end
t=0
if(string.len(e)>0)then
o:send(e)
print("Sent rest")
end
end
end
function fillDynamicMap()
replaceMap={}
ssid,_=wifi.sta.getconfig()
if(ssid==nil)then return replaceMap end
if(sntpserverhostname==nil)then sntpserverhostname="ptbtime1.ptb.de"end
if(timezoneoffset==nil)then timezoneoffset=1 end
if(color==nil)then color=string.char(0,0,250)end
if(color1==nil)then color1=color end
if(color2==nil)then color2=color end
if(color3==nil)then color3=color end
if(color4==nil)then color4=color end
if(colorBg==nil)then colorBg=string.char(0,0,0)end
local t="#"..string.format("%02x",string.byte(color,2))..string.format("%02x",string.byte(color,1))..string.format("%02x",string.byte(color,3))
local n="#"..string.format("%02x",string.byte(color1,2))..string.format("%02x",string.byte(color1,1))..string.format("%02x",string.byte(color1,3))
local e="#"..string.format("%02x",string.byte(color2,2))..string.format("%02x",string.byte(color2,1))..string.format("%02x",string.byte(color2,3))
local i="#"..string.format("%02x",string.byte(color3,2))..string.format("%02x",string.byte(color3,1))..string.format("%02x",string.byte(color3,3))
local o="#"..string.format("%02x",string.byte(color4,2))..string.format("%02x",string.byte(color4,1))..string.format("%02x",string.byte(color4,3))
local a="#"..string.format("%02x",string.byte(colorBg,2))..string.format("%02x",string.byte(colorBg,1))..string.format("%02x",string.byte(colorBg,3))
replaceMap["$SSID"]=ssid
replaceMap["$SNTPSERVER"]=sntpserverhostname
replaceMap["$TIMEOFFSET"]=timezoneoffset
replaceMap["$THREEQUATER"]=(threequater and"checked"or"")
replaceMap["$ADDITIONAL_LINE"]=""
replaceMap["$HEXCOLORFG"]=t
replaceMap["$HEXCOLOR1"]=n
replaceMap["$HEXCOLOR2"]=e
replaceMap["$HEXCOLOR3"]=i
replaceMap["$HEXCOLOR4"]=o
replaceMap["$HEXCOLORBG"]=a
replaceMap["$INV46"]=((inv46~=nil and inv46=="on")and"checked"or"")
replaceMap["$AUTODIM"]=((dim~=nil and dim=="on")and"checked"or"")
return replaceMap
end
function startWebServer()
srv=net.createServer(net.TCP)
srv:listen(80,function(i)
i:on("receive",function(t,e)
if(n)then
print("HTTP sending... be patient!")
return
end
if(e:find("GET /")~=nil)then
n=true
if(color==nil)then
color=string.char(0,128,0)
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
print("Sending webpage.html ("..tostring(node.heap()).."B free) ...")
replaceMap=fillDynamicMap()
sendPage(t,"webpage.html",replaceMap)
end
else if(e:find("POST /")~=nil)then
_,postdatastart=e:find("\r\n\r\n")
if postdatastart==nil then postdatastart=1 end
local a=string.sub(e,postdatastart+1)
local e={}
for t,a in string.gmatch(a,"(%w+)=([^&]+)&*")do
e[t]=a
end
if(e.action~=nil and e.action=="Reboot")then
node.restart()
return
end
if((e.ssid~=nil)and(e.sntpserver~=nil)and(e.timezoneoffset~=nil))then
print("New config!")
if(e.password==nil)then
_,password,_,_=wifi.sta.getconfig()
print("Restoring password : "..password)
e.password=password
password=nil
end
file.remove(o..".new")
sec,_=rtctime.get()
file.open(o..".new","w+")
file.write("-- Config\n".."station_cfg={}\nstation_cfg.ssid=\""..e.ssid.."\"\nstation_cfg.pwd=\""..e.password.."\"\nstation_cfg.save=false\nwifi.sta.config(station_cfg)\n")
file.write("sntpserverhostname=\""..e.sntpserver.."\"\n".."timezoneoffset=\""..e.timezoneoffset.."\"\n".."inv46=\""..tostring(e.inv46).."\"\n".."dim=\""..tostring(e.dim).."\"\n")
if(e.fcolor~=nil)then
print("Got fcolor: "..e.fcolor)
local e=string.sub(e.fcolor,4)
local t=tonumber(string.sub(e,1,2),16)
local a=tonumber(string.sub(e,3,4),16)
local e=tonumber(string.sub(e,5,6),16)
file.write("color=string.char("..a..","..t..","..e..")\n")
color=string.char(a,t,e)
end
if(e.colorMin1~=nil)then
local e=string.sub(e.colorMin1,4)
local t=tonumber(string.sub(e,1,2),16)
local a=tonumber(string.sub(e,3,4),16)
local e=tonumber(string.sub(e,5,6),16)
file.write("color1=string.char("..a..","..t..","..e..")\n")
color1=string.char(a,t,e)
end
if(e.colorMin2~=nil)then
local e=string.sub(e.colorMin2,4)
local a=tonumber(string.sub(e,1,2),16)
local t=tonumber(string.sub(e,3,4),16)
local e=tonumber(string.sub(e,5,6),16)
file.write("color2=string.char("..t..","..a..","..e..")\n")
color2=string.char(t,a,e)
end
if(e.colorMin3~=nil)then
local e=string.sub(e.colorMin3,4)
local t=tonumber(string.sub(e,1,2),16)
local a=tonumber(string.sub(e,3,4),16)
local e=tonumber(string.sub(e,5,6),16)
file.write("color3=string.char("..a..","..t..","..e..")\n")
color3=string.char(a,t,e)
end
if(e.colorMin4~=nil)then
local e=string.sub(e.colorMin4,4)
local t=tonumber(string.sub(e,1,2),16)
local a=tonumber(string.sub(e,3,4),16)
local e=tonumber(string.sub(e,5,6),16)
file.write("color4=string.char("..a..","..t..","..e..")\n")
color4=string.char(a,t,e)
end
if(e.bcolor~=nil)then
local e=string.sub(e.bcolor,4)
local t=tonumber(string.sub(e,1,2),16)
local a=tonumber(string.sub(e,3,4),16)
local e=tonumber(string.sub(e,5,6),16)
file.write("colorBg=string.char("..a..","..t..","..e..")\n")
colorBg=string.char(a,t,e)
end
if(getTime~=nil)then
time=getTime(sec,timezoneoffset)
file.write("print(\"Config from "..time.year.."-"..time.month.."-"..time.day.." "..time.hour..":"..time.minute..":"..time.second.."\")\n")
end
if(e.threequater~=nil)then
file.write("threequater=true\n")
threequater=true
else
file.write("threequater=nil\n")
threequater=nil
end
file.close()
collectgarbage()
sec=nil
file.remove(o)
print("Rename config")
if(file.rename(o..".new",o))then
print("Successfully")
local e=tmr.create()
e:register(50,tmr.ALARM_SINGLE,function(e)
replaceMap=fillDynamicMap()
replaceMap["$ADDITIONAL_LINE"]="<h2><font color=\"green\">New configuration saved</font></h2>"
print("Send success to client")
sendPage(t,"webpage.html",replaceMap)
e:unregister()
end)
e:start()
else
local e=tmr.create()
e:register(50,tmr.ALARM_SINGLE,function(e)
replaceMap=fillDynamicMap()
replaceMap["$ADDITIONAL_LINE"]="<h2><font color=\"red\">ERROR</font></h2>"
sendPage(t,"webpage.html",replaceMap)
e:unregister()
end)
e:start()
end
else
replaceMap=fillDynamicMap()
replaceMap["$ADDITIONAL_LINE"]="<h2><font color=\"orange\">Not all parameters set</font></h2>"
sendPage(t,"webpage.html",replaceMap)
end
else
print("Hello via telnet")
global_c=t
function s_output(e)
if(global_c~=nil)
then global_c:send(e)
end
end
node.output(s_output,0)
global_c:on("receive",function(t,e)
node.input(e)
end)
global_c:on("disconnection",function(e)
node.output(nil)
global_c=nil
end)
print("Welcome to Word Clock")
end
end
end)
i:on("disconnection",function(e)
print("Goodbye")
node.output(nil)
collectgarbage()
t=0
end)
end)
end
collectgarbage()
wifi.setmode(wifi.SOFTAP)
cfg={}
cfg.ssid="wordclock"
cfg.pwd="wordclock"
wifi.ap.config(cfg)
local t=string.char(0,128,0)
local e=string.char(0,0,0)
local a=e:rep(6)..t..e:rep(7)..t:rep(3)..e:rep(44)..t:rep(3)..e:rep(50)
ws2812.write(a)
t=nil
e=nil
a=nil
print("Waiting in access point >wordclock< for Clients")
print("Please visit 192.168.4.1")
startWebServer()
collectgarbage()

View File

@ -369,4 +369,4 @@ M = {
countChars = countChars
}
end
return M
dw = M

View File

@ -17,7 +17,6 @@ end)
bootledtimer:start()
function mydofile(mod)
print("load:" .. mod)
if (file.open(mod .. ".lua")) then
dofile( mod .. ".lua")
elseif (file.open(mod .. "_diet.lua")) then
@ -37,7 +36,7 @@ initTimer:register(5000, tmr.ALARM_SINGLE, function (t)
initTimer:unregister()
initTimer=nil
bootledtimer=nil
local modlist = { "timecore" , "displayword", "ds18b20", "mqtt", "main", "webserver" }
local modlist = { "timecore" , "displayword", "ds18b20", "mqtt", "main" }
for i,mod in pairs(modlist) do
if (file.open(mod .. "_diet.lua")) then
file.remove(mod .. "_diet.lc")
@ -60,25 +59,6 @@ initTimer:register(5000, tmr.ALARM_SINGLE, function (t)
normalOperation()
else
-- 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")
end
end)

View File

@ -8,7 +8,6 @@ rgbBuffer = ws2812.newBuffer(114, 3)
function syncTimeFromInternet()
if (syncRunning == nil) then
print("NTP: " .. tostring(sntpserverhostname))
syncRunning=true
sntp.sync(sntpserverhostname,
function(sec,usec,server)
@ -29,17 +28,14 @@ function displayTime()
if (timezoneoffset == nil) then
timezoneoffset=0
end
local tc = require("timecore_diet")
mydofile("timecore")
if (tc == nil) then
return
end
local time = tc.getTime(sec, timezoneoffset)
tc = nil
timecore_diet=nil
package.loaded["timecore_diet"]=nil
collectgarbage()
local wc = require("wordclock_diet")
mydofile("wordclock")
if (wc ~= nil) then
words = wc.timestat(time.hour, time.minute)
if ((dim ~= nil) and (dim == "on")) then
@ -52,11 +48,9 @@ function displayTime()
end
end
wc = nil
wordclock_diet=nil
package.loaded["wordclock_diet"]=nil
collectgarbage()
local dw = require("displayword_diet")
print("wc: " .. tostring(node.heap()))
mydofile("displayword")
if (dw ~= nil) then
--if lines 4 to 6 are inverted due to hardware-fuckup, unfuck it here
local invertRows=false
@ -67,9 +61,6 @@ function displayTime()
dw.generateLEDs(rgbBuffer, words, colorBg, color, color1, color2, color3, color4, invertRows, c)
end
dw = nil
displayword_diet=nil
package.loaded["displayword_diet"]=nil
collectgarbage()
-- cleanup
@ -109,7 +100,6 @@ function normalOperation()
rgbBuffer:set(55, color) -- P
end
elseif (setupCounter > 3) then
if (web == nil) then
-- Here the WLAN is found, and something is done
mydofile("mqtt")
rgbBuffer:fill(0,0,0) -- disable all LEDs
@ -125,20 +115,13 @@ function normalOperation()
print("NO Mqtt found")
mydofile("telnet")
end
else
print("webserver prepared")
end
setupCounter=setupCounter-1
elseif (setupCounter > 2) then
if (web == nil) then
if (startTelnetServer ~= nil) then
startTelnetServer()
else
displayTime()
end
else
print("webserver supplant telnet")
end
setupCounter=setupCounter-1
elseif ( (alive % 120) == 0) then
-- sync the time every 5 minutes
@ -149,11 +132,6 @@ function normalOperation()
heapusage=nil
alive = alive + 1
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()
alive = alive + 1
end
@ -238,30 +216,17 @@ gpio.mode(3, gpio.INPUT)
local btnCounter=0
-- Start the time Thread handling the button
local btntimer = tmr.create()
btntimer:register(500, tmr.ALARM_AUTO, function (t)
btntimer:register(5000, tmr.ALARM_AUTO, function (t)
if (gpio.read(3) == 0) then
-- stop the main loop
if (mlt ~= nil) then
mlt:unregister()
mlt = nil
end
mlt:unregister()
print("Button pressed " .. tostring(btnCounter))
btnCounter = btnCounter + 5
if ((web ~= nil) and (btnCounter < 50)) then
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
for i=1,btnCounter do rgbBuffer:set(i, 128, 0, 0) end
ws2812.write(rgbBuffer)
if (btnCounter >= 110) then
file.remove("config.lua")
file.remove("config.lc")
node.restart()
elseif (btnCounter == 10) then
collectgarbage()
mydofile("webserver")
-- start the webserver module
end
end
end)

View File

@ -125,38 +125,7 @@ function registerMqtt()
print("MQTT " .. topic .. ":" .. data)
if (topic == (mqttPrefix .. "/cmd/single")) then
handleSingleCommand(client, topic, data)
elseif (topic == (mqttPrefix .. "/cmd/num/val")) then
if (( data == "" ) or (data == nil)) then
tw=nil
print("MQTT | wordclock failed")
else
-- generate the temperatur to display, once as it will not change
local dispTemp = tonumber(data)
collectgarbage()
if (dispTemp > 0) then
local wc = require("wordclock_diet")
if (wc ~= nil) then
tw = wc.showText(dw, rgbBuffer, invertRows, dispTemp)
print("MQTT | generated words for: " .. tostring(dispTemp))
else
print("MQTT | wordclock failed")
end
wc = nil
wordclock_diet=nil
package.loaded["wordclock_diet"]=nil
else
tw=nil
end
end
elseif (topic == (mqttPrefix .. "/cmd/num/col")) then
-- Set number of the color to display
if (( data ~= "" ) and (data ~= nil)) then
tcol = parseBgColor(data, "num/col")
else
tcol = nil
print("MQTT | Hide number")
end
else
else
-- Handle here the /cmd/# sublevel
if (string.match(topic, "telnet$")) then
client:publish(mqttPrefix .. "/telnet", tostring(wifi.sta.getip()), 0, 0)

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/env python
#
# ESP8266 & ESP32 family ROM Bootloader Utility
# Copyright (C) 2014-2016 Fredrik Ahlberg, Angus Gratton, Espressif Systems (Shanghai) PTE LTD, other contributors as noted.

View File

@ -75,13 +75,6 @@ public class WS2812Simulation implements LuaSimulation {
// Copy all files into the temporary folder
for (File f : sourceFolder.listFiles()) {
Files.copy(f.toPath(), new File(tempDir.getAbsolutePath() + File.separator + f.getName()).toPath());
// create a diet one
if (f.isFile() &&
(f.getName().endsWith(".lua") &&
(!f.getName().equals("config.lua")))) {
String dietName = f.getName().replace(".lua", "_diet.lc");
Files.copy(f.toPath(), new File(tempDir.getAbsolutePath() + File.separator + dietName).toPath());
}
}
espFile.setWorkingDirectory(tempDir);

View File

@ -146,4 +146,4 @@ M = {
getTime = getTime
}
end
return M
tc = M

View File

@ -48,10 +48,6 @@ if [ "$FILES" != "config.lua" ]; then
echo "Compress $f ..."
out=$(echo "$f" | sed 's/.lua/_diet.lua/g')
$DIET ../$f -o ../diet/$out
if [ $? -ne 0 ]; then
echo "Failed to generate file"
exit $?
fi
OUTFILES="$OUTFILES diet/$out"
else
OUTFILES="$OUTFILES $f"

View File

@ -47,14 +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>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>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><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><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>
</table>

View File

@ -2,28 +2,9 @@
local configFile="config.lua"
local httpSending=false
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)
collectgarbage()
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)
if (sentBytes == 0) then
conn:close()
@ -51,9 +32,6 @@ function sendPage(conn, nameOfFile, replaceMap)
local line = file.readline()
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
if (line:find("$") ~= nil) then
-- Replace the placeholder with the dynamic content
@ -65,6 +43,10 @@ function sendPage(conn, nameOfFile, replaceMap)
end
end
-- increase the amount of sent bytes
sentBytes=sentBytes+string.len(line)
buf = buf .. line
-- Sent after 500 bytes data
@ -85,13 +67,6 @@ function sendPage(conn, nameOfFile, replaceMap)
if (string.len(buf) > 0) then
conn:send(buf)
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
@ -132,14 +107,6 @@ function fillDynamicMap()
return replaceMap
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()
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
@ -153,9 +120,9 @@ function startWebServer()
if (color == nil) then
color=string.char(0,128,0)
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
print("Sending webpage.html (" .. tostring(node.heap()) .. "B free) ...")
mydofile("config")
-- Load the sendPagewebcontent
replaceMap=fillDynamicMap()
sendPage(conn, "webpage.html", replaceMap)
@ -189,47 +156,68 @@ function startWebServer()
file.remove(configFile .. ".new")
sec, _ = rtctime.get()
file.open(configFile.. ".new", "w+")
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=nil\n")
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("sntpserverhostname=\"" .. _POST.sntpserver .. "\"\n" .. "timezoneoffset=\"" .. _POST.timezoneoffset .. "\"\n".. "inv46=\"" .. tostring(_POST.inv46) .. "\"\n" .. "dim=\"" .. tostring(_POST.dim) .. "\"\n")
if ( _POST.fcolor ~= nil) then
-- color=string.char(_POST.green, _POST.red, _POST.blue)
print ("Got fcolor: " .. _POST.fcolor)
readHex(_POST.fcolor, "color")
local hexColor=string.sub(_POST.fcolor, 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("color=string.char(" .. green .. "," .. red .. "," .. blue .. ")\n")
-- fill the current values
color=string.char(green, red, blue)
end
if ( _POST.mcolor1 ~= nil) then
readHex(_POST.mcolor1, "color1")
if ( _POST.colorMin1 ~= nil) then
local hexColor=string.sub(_POST.colorMin1, 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("color1=string.char(" .. green .. "," .. red .. "," .. blue .. ")\n")
-- fill the current values
color1=string.char(green, red, blue)
end
if ( _POST.mcolor2 ~= nil) then
readHex(_POST.mcolor2, "color2")
if ( _POST.colorMin2 ~= nil) then
local hexColor=string.sub(_POST.colorMin2, 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("color2=string.char(" .. green .. "," .. red .. "," .. blue .. ")\n")
-- fill the current values
color2=string.char(green, red, blue)
end
if ( _POST.mcolor3 ~= nil) then
readHex(_POST.mcolor3, "color3")
if ( _POST.colorMin3 ~= nil) then
local hexColor=string.sub(_POST.colorMin3, 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("color3=string.char(" .. green .. "," .. red .. "," .. blue .. ")\n")
-- fill the current values
color3=string.char(green, red, blue)
end
if ( _POST.mcolor4 ~= nil) then
readHex(_POST.mcolor4, "color4")
if ( _POST.colorMin4 ~= nil) then
local hexColor=string.sub(_POST.colorMin4, 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("color4=string.char(" .. green .. "," .. red .. "," .. blue .. ")\n")
-- fill the current values
color4=string.char(green, red, blue)
end
if ( _POST.bcolor ~= nil) then
local hexColor=string.sub(_POST.bcolor, 4)
readHex(_POST.bcolor, "colorBg")
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("colorBg=string.char(" .. green .. "," .. red .. "," .. blue .. ")\n")
-- fill the current values
colorBg=string.char(green, red, blue)
end
if (getTime ~= nil) then
time = getTime(sec, timezoneoffset)
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
if (_POST.threequater ~= nil) then
file.write("threequater=true\n")
@ -249,7 +237,6 @@ function startWebServer()
print("Successfully")
local mytimer = tmr.create()
mytimer:register(50, tmr.ALARM_SINGLE, function (t)
mydofile("config")
replaceMap=fillDynamicMap()
replaceMap["$ADDITIONAL_LINE"]="<h2><font color=\"green\">New configuration saved</font></h2>"
print("Send success to client")
@ -304,5 +291,25 @@ function startWebServer()
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()
collectgarbage()

View File

@ -192,4 +192,4 @@ M = {
showText = showText
}
end
return M
wc = M