Websever can be started at runtime

This commit is contained in:
Ollo 2022-12-09 22:32:40 +01:00
parent db3a1e5e20
commit ad9beccadc
3 changed files with 25 additions and 20 deletions

View File

@ -60,6 +60,25 @@ 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

@ -109,6 +109,7 @@ 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
@ -124,6 +125,10 @@ function normalOperation()
print("NO Mqtt found")
mydofile("telnet")
end
else
-- start the webserver module
mydofile("webserver")
end
setupCounter=setupCounter-1
elseif (setupCounter > 2) then
if (startTelnetServer ~= nil) then

View File

@ -131,6 +131,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))
if (sendPage ~= nil) then
print("Sending webpage.html (" .. tostring(node.heap()) .. "B free) ...")
mydofile("config.lua")
-- Load the sendPagewebcontent
replaceMap=fillDynamicMap()
sendPage(conn, "webpage.html", replaceMap)
@ -273,25 +274,5 @@ 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()