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

Conversation

blobule
Copy link
Contributor

@blobule blobule commented Feb 2, 2021

Fixes no specific issue,

  • This PR is for the dev branch rather than for the release branch.
  • This PR is compliant with the other contributing guidelines as well (if not, please describe why).
  • I have thoroughly tested my contribution.
  • The code changes are reflected in the documentation at docs/*.

Following a suggestion in #3374 , this is an example for a init.lua that uses a wifi portal to configure wifi if needed.
I put it inside lua_examples, but I don't know how and where to refer to this in the docs. Suggestions?

Also, I wonder if it would be interesting to provide complete examples for some common IOT setups:

  • robust mqtt to light up a LED remotely
  • robust mqtt sensor reading (temperature) every 10 minutes, with deep sleep in between
  • robust mqtt IOT identification using Homie
  • ...
    ( Here robust means that it will survive power outage, network outage, etc, and always restart properly. )
    Such examples could make it much simpler to setup IOT by providing a good template.
    Juste wondering if this is something that would be considered useful.

@pjsg
Copy link
Member

pjsg commented Feb 2, 2021

As a stylistic point, I'd make t a local and then you don't need to set it to nil in order to free it.

In my code, I always start the enduser_setup -- it exits once the connection is up -- no matter whether the user configured it, or whether a previously set SSID was found.

@marcelstoer marcelstoer changed the base branch from release to dev February 2, 2021 15:25
@marcelstoer
Copy link
Member

marcelstoer commented Feb 2, 2021

  • This PR is for the dev branch rather than for the release branch.

Now it is - I just changed the base branch.

Also, please fix the CI build issues: https://travis-ci.org/github/nodemcu/nodemcu-firmware/jobs/757193097

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

@marcelstoer marcelstoer Feb 12, 2021

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?

@marcelstoer marcelstoer added this to the Next release milestone Feb 2, 2021
@blobule
Copy link
Contributor Author

blobule commented Feb 3, 2021

To answer, @pjsg, we can't make t a local since it must be possible to type t:stop() during the initial 10 seconds delay. Anything local will disappear as soon as init.lua is done executing, so t must stay global. This is why luacheck fails, even if this is the correct code, IMO. I don' t see any way around this.

Unfortunately, enduser_setup will always create a wifi access points even when wifi station is already configured. The acces point will be gone in less than 10 seconds, but still I consider this less than ideal. So I prefer to check wifi status before any call to enduser_setup. Maybe enduser_setup should check wifi before setting up the access point?

@jmd13391
Copy link

jmd13391 commented Feb 3, 2021

@blobule "I don't see any way around this" -- Use a tmr. ;-)

@marcelstoer marcelstoer removed this from the Next release milestone Nov 19, 2021
@HHHartmann
Copy link
Member

You can disable checks in luacheck by adding a comment. See the luacheck documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants