2017-01-03 14:07:23 +01:00
|
|
|
uart.setup(0, 115200, 8, 0, 1, 1 )
|
2016-12-14 18:37:56 +01:00
|
|
|
print("Autostart in 5 seconds...")
|
2016-06-19 17:04:30 +02:00
|
|
|
|
2016-07-03 18:41:32 +02:00
|
|
|
ws2812.init() -- WS2812 LEDs initialized on GPIO2
|
2017-10-27 18:05:53 +02:00
|
|
|
MAXLEDS=110
|
2016-06-19 17:04:30 +02:00
|
|
|
counter1=0
|
2016-07-03 18:41:32 +02:00
|
|
|
ws2812.write(string.char(0,0,0):rep(114))
|
2021-01-31 20:41:03 +01:00
|
|
|
local bootledtimer = tmr.create()
|
2021-02-05 20:58:15 +01:00
|
|
|
bootledtimer:register(500, tmr.ALARM_AUTO, function (t)
|
2016-06-19 17:04:30 +02:00
|
|
|
counter1=counter1+1
|
2017-12-29 21:47:23 +01:00
|
|
|
spaceLeds = math.max(MAXLEDS - (counter1*2), 0)
|
|
|
|
ws2812.write(string.char(128,0,0):rep(counter1) .. string.char(0,0,0):rep(spaceLeds) .. string.char(0,0,64):rep(counter1))
|
2021-02-05 21:50:02 +01:00
|
|
|
if ((counter1*2) > 114) then
|
|
|
|
t:unregister()
|
|
|
|
end
|
2016-06-19 17:04:30 +02:00
|
|
|
end)
|
2021-01-31 20:41:03 +01:00
|
|
|
bootledtimer:start()
|
2016-06-19 17:04:30 +02:00
|
|
|
|
2019-04-18 20:28:57 +02:00
|
|
|
local blacklistfile="init.lua config.lua config.lua.new webpage.html"
|
2016-06-19 17:04:30 +02:00
|
|
|
function recompileAll()
|
2021-02-05 21:32:46 +01:00
|
|
|
-- 3, discard Local, Upvalue and line-number debug info
|
|
|
|
node.stripdebug(3)
|
2016-06-19 17:04:30 +02:00
|
|
|
-- compile all files
|
|
|
|
l = file.list();
|
|
|
|
for k,_ in pairs(l) do
|
|
|
|
if (string.find(k, ".lc", -3)) then
|
|
|
|
print ("Skipping " .. k)
|
|
|
|
elseif (string.find(blacklistfile, k) == nil) then
|
2016-12-30 13:39:22 +01:00
|
|
|
-- Only look at lua files
|
|
|
|
if (string.find(k, ".lua") ~= nil) then
|
|
|
|
print("Compiling and deleting " .. k)
|
|
|
|
node.compile(k)
|
|
|
|
-- remove the lua file
|
|
|
|
file.remove(k)
|
2021-02-05 20:38:31 +01:00
|
|
|
node.restart()
|
2016-12-30 13:39:22 +01:00
|
|
|
else
|
|
|
|
print("No code: " .. k)
|
|
|
|
end
|
2016-06-19 17:04:30 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function mydofile(mod)
|
|
|
|
if (file.open(mod .. ".lua")) then
|
|
|
|
dofile( mod .. ".lua")
|
2021-01-14 21:55:51 +01:00
|
|
|
elseif (file.open(mod .. ".lc")) then
|
2016-06-19 17:04:30 +02:00
|
|
|
dofile(mod .. ".lc")
|
2021-01-31 20:45:59 +01:00
|
|
|
elseif (file.open(mod)) then
|
|
|
|
dofile(mod)
|
2021-01-14 21:55:51 +01:00
|
|
|
else
|
|
|
|
print("Error: " .. mod)
|
2016-06-19 17:04:30 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-02-05 20:38:31 +01:00
|
|
|
initTimer = tmr.create()
|
2021-01-31 20:22:32 +01:00
|
|
|
initTimer:register(5000, tmr.ALARM_SINGLE, function (t)
|
2021-01-31 20:41:03 +01:00
|
|
|
bootledtimer:unregister()
|
2021-02-05 20:58:15 +01:00
|
|
|
t:unregister()
|
|
|
|
collectgarbage()
|
2019-04-18 20:28:57 +02:00
|
|
|
if (
|
|
|
|
(file.open("main.lua")) or
|
|
|
|
(file.open("timecore.lua")) or
|
|
|
|
(file.open("wordclock.lua")) or
|
2021-02-05 20:38:31 +01:00
|
|
|
(file.open("displayword.lua")) or
|
2021-02-05 21:50:02 +01:00
|
|
|
(file.open("websrv_diet.lua")) or
|
2021-01-23 18:10:53 +01:00
|
|
|
(file.open("mqtt.lua")) or
|
|
|
|
(file.open("ds18b20.lua")) or
|
2020-03-04 22:24:13 +01:00
|
|
|
(file.open("telnet.lua"))
|
2019-04-18 20:28:57 +02:00
|
|
|
) then
|
2019-04-18 22:51:09 +02:00
|
|
|
c = string.char(0,128,0)
|
|
|
|
w = string.char(0,0,0)
|
|
|
|
ws2812.write(w:rep(4) .. c .. w:rep(15) .. c .. w:rep(9) .. c .. w:rep(30) .. c .. w:rep(41) .. c )
|
2016-06-19 17:04:30 +02:00
|
|
|
recompileAll()
|
|
|
|
print("Rebooting ...")
|
|
|
|
-- reboot repairs everything
|
|
|
|
node.restart()
|
2021-02-05 20:58:15 +01:00
|
|
|
else
|
2021-02-05 20:38:31 +01:00
|
|
|
if ( file.open("config.lua") ) then
|
|
|
|
--- Normal operation
|
|
|
|
print("Starting main")
|
|
|
|
dofile("main.lc")
|
|
|
|
wifi.setmode(wifi.STATION)
|
|
|
|
dofile("config.lua")
|
|
|
|
normalOperation()
|
|
|
|
else
|
2021-02-05 21:32:46 +01:00
|
|
|
mydofile("websrv_diet")
|
2021-02-05 20:38:31 +01:00
|
|
|
-- Logic for inital setup
|
|
|
|
startSetupMode()
|
|
|
|
end
|
2016-06-19 17:04:30 +02:00
|
|
|
end
|
|
|
|
end)
|
2021-01-31 20:22:32 +01:00
|
|
|
initTimer:start()
|