Fixed splitting of webpage into several packages

This commit is contained in:
Ollo 2022-12-09 22:56:07 +01:00
parent ad9beccadc
commit 689ef10922

View File

@ -32,6 +32,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 +46,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
@ -131,7 +130,7 @@ 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)) 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.lua") mydofile("config")
-- Load the sendPagewebcontent -- Load the sendPagewebcontent
replaceMap=fillDynamicMap() replaceMap=fillDynamicMap()
sendPage(conn, "webpage.html", replaceMap) sendPage(conn, "webpage.html", replaceMap)
@ -220,6 +219,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")