From 38c30127f36e0b1a908e3669212fc5c1749e3d63 Mon Sep 17 00:00:00 2001 From: Sebastien Roy Date: Tue, 2 Feb 2021 00:16:59 -0500 Subject: [PATCH] exemple of init.lua --- lua_examples/init.lua | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 lua_examples/init.lua diff --git a/lua_examples/init.lua b/lua_examples/init.lua new file mode 100644 index 0000000000..cf890043d5 --- /dev/null +++ b/lua_examples/init.lua @@ -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) +