exemple of init.lua

This commit is contained in:
Sebastien Roy 2021-02-02 00:16:59 -05:00
parent c212b30a03
commit 38c30127f3
1 changed files with 34 additions and 0 deletions

34
lua_examples/init.lua Normal file
View File

@ -0,0 +1,34 @@
-- init.lua example, with wifi portal
--
-- Waits 10 sec to allow stopping the boot process, and get wifi activated
-- When wifi not activated, setup a portal to select a network
-- In all cases, wifi ends up activated and the main task main.lua is executed
--
-- module needed: enduser_setup
print("Waiting 10sec... use t:stop() to cancel init.lua")
t=tmr.create()
t:alarm(10000,tmr.ALARM_SINGLE,function ()
t=nil -- free the timer
if wifi.sta.getip() then
print("Wifi activated",wifi.sta.getip())
dofile("main.lua")
else
print("No Wifi. Starting portal...")
enduser_setup.start(
"SuperBidule",
function()
wifi.sta.autoconnect(1)
print("Wifi activated",wifi.sta.getip())
dofile("main.lua")
end,
function(err, str)
print("enduser_setup: Err #" .. err .. ": " .. str)
end,
function(str)
print("Debug " .. str)
end
)
end
end)