Lonely webserver is running

This commit is contained in:
Ollo 2021-02-05 20:38:31 +01:00
parent 6193618d1b
commit 54095e7c20
3 changed files with 40 additions and 40 deletions

View File

@ -27,6 +27,7 @@ function recompileAll()
node.compile(k) node.compile(k)
-- remove the lua file -- remove the lua file
file.remove(k) file.remove(k)
node.restart()
else else
print("No code: " .. k) print("No code: " .. k)
end end
@ -46,7 +47,7 @@ function mydofile(mod)
end end
end end
local initTimer = tmr.create() initTimer = tmr.create()
initTimer:register(5000, tmr.ALARM_SINGLE, function (t) initTimer:register(5000, tmr.ALARM_SINGLE, function (t)
bootledtimer:unregister() bootledtimer:unregister()
if ( if (
@ -66,8 +67,18 @@ initTimer:register(5000, tmr.ALARM_SINGLE, function (t)
-- reboot repairs everything -- reboot repairs everything
node.restart() node.restart()
elseif (file.open("main.lc")) then elseif (file.open("main.lc")) then
if ( file.open("config.lua") ) then
--- Normal operation
print("Starting main") print("Starting main")
dofile("main.lc") dofile("main.lc")
wifi.setmode(wifi.STATION)
dofile("config.lua")
normalOperation()
else
mydofile("webserver")
-- Logic for inital setup
startSetupMode()
end
else else
print("No Main file found") print("No Main file found")
end end

View File

@ -3,32 +3,6 @@
local looptimer = tmr.create() local looptimer = tmr.create()
displayword = {} displayword = {}
function startSetupMode()
-- start the webserver module
mydofile("webserver")
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()
end
function syncTimeFromInternet() function syncTimeFromInternet()
if (syncRunning == nil) then if (syncRunning == nil) then
syncRunning=true syncRunning=true
@ -207,15 +181,6 @@ end
-------------------main program ----------------------------- -------------------main program -----------------------------
ws2812.init() -- WS2812 LEDs initialized on GPIO2 ws2812.init() -- WS2812 LEDs initialized on GPIO2
if ( file.open("config.lua") ) then
--- Normal operation
wifi.setmode(wifi.STATION)
mydofile("config")
normalOperation()
else
-- Logic for inital setup
startSetupMode()
end
----------- button --------- ----------- button ---------
gpio.mode(3, gpio.INPUT) gpio.mode(3, gpio.INPUT)
local btnCounter=0 local btnCounter=0

View File

@ -327,4 +327,28 @@ function startWebServer()
end) end)
end end
--FileView done.
function startSetupMode()
-- 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()
end