From b3283d8dccad0060fd6bb59a8ac12f8911884614 Mon Sep 17 00:00:00 2001 From: ollo Date: Fri, 27 Oct 2017 18:04:08 +0200 Subject: [PATCH 01/11] Boot sequence from both ends --- init.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/init.lua b/init.lua index 370e0c8..74d28a2 100644 --- a/init.lua +++ b/init.lua @@ -2,12 +2,12 @@ uart.setup(0, 115200, 8, 0, 1, 1 ) print("Autostart in 5 seconds...") ws2812.init() -- WS2812 LEDs initialized on GPIO2 - +MAXLEDS=110 counter1=0 ws2812.write(string.char(0,0,0):rep(114)) tmr.alarm(2, 85, 1, function() counter1=counter1+1 - ws2812.write(string.char(128,0,0):rep(counter1)) + ws2812.write(string.char(128,0,0):rep(counter1) .. string.char(0,0,0):rep(MAXLEDS - (counter1*2)) .. string.char(0,0,64):rep(counter1)) end) local blacklistfile="init.lua config.lua config.lua.new" From df1952ca04743156843326b4406887fb0939aa25 Mon Sep 17 00:00:00 2001 From: ollo Date: Sat, 23 Mar 2019 00:29:18 +0100 Subject: [PATCH 02/11] Tweaking arround --- webserver.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/webserver.lua b/webserver.lua index 8568412..9f18198 100644 --- a/webserver.lua +++ b/webserver.lua @@ -47,8 +47,8 @@ function sendPage(conn, nameOfFile, replaceMap) end buf = buf .. line - -- Sent after 1k data - if (string.len(buf) >= 700) then + -- Sent after 500 bytes data + if ( (string.len(buf) >= 500) or (node.heap() < 2000) ) then line=nil conn:send(buf) print("Sent part of " .. sentBytes .. "B") @@ -128,9 +128,10 @@ function startWebServer() if (payload:find("GET /") ~= nil) then --here is code for handling http request from a web-browser + collectgarbage() if (sendPage ~= nil) then - print("Sending webpage.html ...") + print("Sending webpage.html (" .. tostring(node.heap()) .. "B free) ...") -- Load the sendPagewebcontent replaceMap=fillDynamicMap() sendPage(conn, "webpage.html", replaceMap) From 4155d0018e5c6f38dfb2c347328a7b7f9f44e41c Mon Sep 17 00:00:00 2001 From: ollo Date: Sat, 23 Mar 2019 13:54:29 +0100 Subject: [PATCH 03/11] added: halb einS --- wordclock.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wordclock.lua b/wordclock.lua index c537ad1..f95b4c0 100755 --- a/wordclock.lua +++ b/wordclock.lua @@ -105,7 +105,7 @@ function display_timestat(hours, minutes, longmode) end if (hours == 1) then - if (ret.it == 1) then + if ((ret.it == 1) and (ret.half == 0) ) then ret.one=1 else ret.oneLong=1 From 7052c4c25af4c9c6ef314949939a86b7e3e40f5c Mon Sep 17 00:00:00 2001 From: ollo Date: Fri, 29 Mar 2019 18:35:07 +0100 Subject: [PATCH 04/11] Moved length calculation after manipulation --- webserver.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/webserver.lua b/webserver.lua index 9f18198..c5d9070 100644 --- a/webserver.lua +++ b/webserver.lua @@ -32,8 +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 @@ -45,6 +43,9 @@ function sendPage(conn, nameOfFile, replaceMap) end end end + -- increase the amount of sent bytes + sentBytes=sentBytes+string.len(line) + buf = buf .. line -- Sent after 500 bytes data From 784a75241c3c43f9d28b07748f3a52dca2a27876 Mon Sep 17 00:00:00 2001 From: ollo Date: Wed, 3 Apr 2019 20:23:07 +0200 Subject: [PATCH 05/11] Only one request at a time --- webserver.lua | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/webserver.lua b/webserver.lua index c5d9070..3b2915a 100644 --- a/webserver.lua +++ b/webserver.lua @@ -1,7 +1,7 @@ --TODO: - configFile="config.lua" +httpSending=false sentBytes=0 function sendPage(conn, nameOfFile, replaceMap) collectgarbage() @@ -11,8 +11,9 @@ function sendPage(conn, nameOfFile, replaceMap) conn:close() print("Page sent") collectgarbage() + httpSending=false else - print("Next") + collectgarbage() sendPage(conn, nameOfFile, replaceMap) end end) @@ -32,7 +33,6 @@ function sendPage(conn, nameOfFile, replaceMap) local line = file.readline() while (line ~= nil) do - -- 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 @@ -43,6 +43,8 @@ function sendPage(conn, nameOfFile, replaceMap) end end end + + -- increase the amount of sent bytes sentBytes=sentBytes+string.len(line) @@ -126,8 +128,14 @@ function startWebServer() srv=net.createServer(net.TCP) srv:listen(80,function(conn) conn:on("receive", function(conn,payload) + if (httpSending) then + print("HTTP sending... be patient!") + return + end + if (payload:find("GET /") ~= nil) then + httpSending=true --here is code for handling http request from a web-browser collectgarbage() @@ -167,8 +175,8 @@ function startWebServer() file.remove(configFile .. ".new") sec, _ = rtctime.get() 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("sntpserverhostname=\"" .. _POST.sntpserver .. "\"\n" .. "timezoneoffset=\"" .. _POST.timezoneoffset .. "\"\n".. "inv46=\"" .. tostring(_POST.inv46) .. "\"\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") if ( _POST.fcolor ~= nil) then -- color=string.char(_POST.green, _POST.red, _POST.blue) @@ -297,3 +305,4 @@ function startWebServer() end) end +--FileView done. From c3b94e0adeb785c4a34168d8df661296463c54a6 Mon Sep 17 00:00:00 2001 From: ollo Date: Wed, 3 Apr 2019 21:08:27 +0200 Subject: [PATCH 06/11] Stop all timer, when someone connected --- webserver.lua | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/webserver.lua b/webserver.lua index 3b2915a..261742f 100644 --- a/webserver.lua +++ b/webserver.lua @@ -138,7 +138,21 @@ function startWebServer() httpSending=true --here is code for handling http request from a web-browser collectgarbage() + -- Stop all + tmr.stop(0) + tmr.stop(1) + tmr.stop(2) + tmr.stop(3) + tmr.stop(4) + tmr.stop(5) + -- Start Time after 1 minute + tmr.alarm(6, 60000, 0 ,function() + -- Start the time Thread + tmr.alarm(1, 20000, 1 ,function() + displayTime() + end) + end) if (sendPage ~= nil) then print("Sending webpage.html (" .. tostring(node.heap()) .. "B free) ...") -- Load the sendPagewebcontent @@ -298,7 +312,7 @@ function startWebServer() conn:on("disconnection", function(c) print("Goodbye") node.output(nil) -- un-register the redirect output function, output goes to serial - + collectgarbage() --reset amount of sent bytes, as we reached the end sentBytes=0 end) From e03ecf97b68507780ea5a5ad95f3646360c6a70e Mon Sep 17 00:00:00 2001 From: ollo Date: Wed, 10 Apr 2019 21:23:15 +0200 Subject: [PATCH 07/11] Added colored output, if the website was requested --- webserver.lua | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/webserver.lua b/webserver.lua index 261742f..1575109 100644 --- a/webserver.lua +++ b/webserver.lua @@ -139,13 +139,9 @@ function startWebServer() --here is code for handling http request from a web-browser collectgarbage() -- Stop all - tmr.stop(0) - tmr.stop(1) - tmr.stop(2) - tmr.stop(3) - tmr.stop(4) - tmr.stop(5) - + for i=0,5 do tmr.stop(i) 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)) -- Start Time after 1 minute tmr.alarm(6, 60000, 0 ,function() -- Start the time Thread From 883adb671ca0854bce9942659d5e2ff08179a259 Mon Sep 17 00:00:00 2001 From: calculator Date: Tue, 16 Apr 2019 19:20:01 +0200 Subject: [PATCH 08/11] Unload all files --- webserver.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/webserver.lua b/webserver.lua index 1575109..2aad4cf 100644 --- a/webserver.lua +++ b/webserver.lua @@ -140,13 +140,17 @@ function startWebServer() collectgarbage() -- Stop all for i=0,5 do tmr.stop(i) end - + -- unload all other modules + package.loaded['displayword.lc']=nil + package.loaded['main.lc']=nil + package.loaded['wordclock']=nil + collectgarbage() 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)) -- Start Time after 1 minute tmr.alarm(6, 60000, 0 ,function() -- Start the time Thread tmr.alarm(1, 20000, 1 ,function() - displayTime() + dofile("main.lc") end) end) if (sendPage ~= nil) then From b4e8eec9bf2cbb3c8841a0a8ecd9d1bb510ee115 Mon Sep 17 00:00:00 2001 From: ollo Date: Wed, 17 Apr 2019 20:13:25 +0200 Subject: [PATCH 09/11] Unload all functions, not necessary for the webserver --- webserver.lua | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/webserver.lua b/webserver.lua index 2aad4cf..bf3f542 100644 --- a/webserver.lua +++ b/webserver.lua @@ -135,31 +135,45 @@ function startWebServer() if (payload:find("GET /") ~= nil) then - httpSending=true - --here is code for handling http request from a web-browser + httpSending=true + --here is code for handling http request from a web-browser collectgarbage() -- Stop all for i=0,5 do tmr.stop(i) end - -- unload all other modules - package.loaded['displayword.lc']=nil - package.loaded['main.lc']=nil - package.loaded['wordclock']=nil + -- unload all other functions + -- grep function *.lua | grep -v webserver | cut -f 2 -d ':' | grep "^function" | sed "s/function //g" | grep -o "^[a-zA-Z0-9\_]*" + updateColor = nil + drawLEDs = nil + round = nil + generateLEDs = nil + startSetupMode = nil + syncTimeFromInternet = nil + displayTime = nil + normalOperation = nil + isSummerTime = nil + getUTCtime = nil + getTime = nil + display_timestat = nil + display_countcharacters_de = nil + display_countwords_de = nil collectgarbage() 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)) -- Start Time after 1 minute - tmr.alarm(6, 60000, 0 ,function() + tmr.alarm(5, 60000, 0 ,function() -- Start the time Thread tmr.alarm(1, 20000, 1 ,function() dofile("main.lc") end) end) - if (sendPage ~= nil) then - print("Sending webpage.html (" .. tostring(node.heap()) .. "B free) ...") - -- Load the sendPagewebcontent - replaceMap=fillDynamicMap() - sendPage(conn, "webpage.html", replaceMap) - end - + -- send response after 100ms + tmr.alarm(5, 100, 0 ,function() + if (sendPage ~= nil) then + print("Sending webpage.html (" .. tostring(node.heap()) .. "B free) ...") + -- Load the sendPagewebcontent + replaceMap=fillDynamicMap() + sendPage(conn, "webpage.html", replaceMap) + end + end) else if (payload:find("POST /") ~=nil) then --code for handling the POST-request (updating settings) _, postdatastart = payload:find("\r\n\r\n") From 287d1eef42847960eb88cefe1f3b63c207db1abc Mon Sep 17 00:00:00 2001 From: ollo Date: Wed, 17 Apr 2019 20:23:46 +0200 Subject: [PATCH 10/11] Fixed webpage --- webpage.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webpage.html b/webpage.html index fad40f7..2ba586a 100644 --- a/webpage.html +++ b/webpage.html @@ -45,8 +45,8 @@ Please note that all settings are mandatory

- - + + From 6def7cbc10ad09511416f3884840551fdeae264d Mon Sep 17 00:00:00 2001 From: ollo Date: Wed, 17 Apr 2019 20:39:54 +0200 Subject: [PATCH 11/11] 1 minute after a request via the webserver the time is displayed again --- webserver.lua | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/webserver.lua b/webserver.lua index bf3f542..5d2478e 100644 --- a/webserver.lua +++ b/webserver.lua @@ -141,15 +141,11 @@ function startWebServer() -- Stop all for i=0,5 do tmr.stop(i) end -- unload all other functions - -- grep function *.lua | grep -v webserver | cut -f 2 -d ':' | grep "^function" | sed "s/function //g" | grep -o "^[a-zA-Z0-9\_]*" + -- grep function *.lua | grep -v webserver | grep -v init.lua | grep -v main.lua | cut -f 2 -d ':' | grep "^function" | sed "s/function //g" | grep -o "^[a-zA-Z0-9\_]*" updateColor = nil drawLEDs = nil round = nil generateLEDs = nil - startSetupMode = nil - syncTimeFromInternet = nil - displayTime = nil - normalOperation = nil isSummerTime = nil getUTCtime = nil getTime = nil @@ -160,13 +156,20 @@ function startWebServer() 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)) -- Start Time after 1 minute tmr.alarm(5, 60000, 0 ,function() - -- Start the time Thread + dependModules = { "timecore" , "wordclock", "displayword" } + for _,mod in pairs(dependModules) do + print("Loading " .. mod) + mydofile(mod) + end + -- Start the time Thread + displayTime() + -- Start the time Thread tmr.alarm(1, 20000, 1 ,function() - dofile("main.lc") + displayTime() end) end) -- send response after 100ms - tmr.alarm(5, 100, 0 ,function() + tmr.alarm(4, 100, 0 ,function() if (sendPage ~= nil) then print("Sending webpage.html (" .. tostring(node.heap()) .. "B free) ...") -- Load the sendPagewebcontent
WIFI-SSIDSSID of the wireless network
WIFI-PasswordPassword of the wireless network
SNTP ServerServer to sync the time with. Only one ntp server is allowed.
Offset to UTC timeDefine the offset to UTC time in hours. For example +1 hour for Germany
SNTP ServerServer to sync the time with. Only one ntp server is allowed.
Offset to UTC timeDefine the offset to UTC time in hours. For example +1 hour for Germany
Foreground ColorLED Color for all minutes, divisible by five
Background ColorBackground LED Color
1. Minute ColorFirst minute after