Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exemple of init.lua with wifi portal #3395

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 34 additions & 0 deletions lua_examples/init.lua
@@ -0,0 +1,34 @@
-- init.lua example, with wifi portal
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should IMO go into a sub directory like e.g. lua_examples/eus/init.lua

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that this init.lua is "eus" specific. I have no problem moving it to eus. However, maybe we could group all examples of init.lua together... one with eus, one for waking up after deep sleep, other situations.... All I know is that when we need those examples, they are scattered around the docs, so a directory "starting up" might also work. Its up to you, I'll follow your suggeations and update the PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we could group all examples of init.lua together

Good idea! Do you have a naming proposal? A directory called init_lua and then files like e.g. eus-init.lua?

https://nodemcu.readthedocs.io/en/latest/upload/#initlua -> move from docs to a file in that new folder, add reference to existing docs chapter.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blobule still interested in following up on this?

--
-- 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)