nodemcu-firmware icon indicating copy to clipboard operation
nodemcu-firmware copied to clipboard

Add support for open networks to enduser_setup

Open blobule opened this issue 4 years ago • 5 comments

Fixes #3374.

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

I fixed the bug, making sure an open network (without password) is handled correctly. I tested it and it works perfectly.

blobule avatar Jan 31 '21 16:01 blobule

I compiled nodemcu for the first time to fix this bug, and it was a great experience. Congratulation for such a nice compiling setup. I've been using nodemcu for years, but this is a first for me. I hope this PR is satisfactory.

Should we add in the docs of enduser_setup a complete example of an adequate boot process (init.lua)? Something like this...

print("Wating 10 seconds. Use t:stop() to cancel the init process...")
t=tmr.create()
t:alarm(10000,tmr.ALARM_SINGLE,function ()
	if wifi.sta.getip() then
		print("Wifi activated",wifi.sta.getip())
		dofile("go.lua")
	else
		print("No Wifi. Starting portal...")
		enduser_setup.start(
		  "Nodemcu setup",
		  function()
			wifi.sta.autoconnect(1)
			print("Wifi activated",wifi.sta.getip())
			dofile("go.lua")
		  end,
		  function(err, str)
		    print("enduser_setup: Err #" .. err .. ": " .. str)
		    -- schedule reboot?
		  end
		)
	end
end)

It would be nice to have such an example chunk for init.lua

blobule avatar Jan 31 '21 16:01 blobule

I compiled nodemcu for the first time to fix this bug, and it was a great experience. Congratulation for such a nice compiling setup.

Wellcome to the club!

Should we add in the docs of enduser_setup a complete example of an adequate boot process (init.lua)? Something like this...

print("Wating 10 seconds. Use t:stop() to cancel the init process...")
t=tmr.create()
t:alarm(10000,tmr.ALARM_SINGLE,function ()
	if wifi.sta.getip() then
		print("Wifi activated",wifi.sta.getip())
		dofile("go.lua")
	else
		print("No Wifi. Starting portal...")
		enduser_setup.start(
		  "Nodemcu setup",
		  function()
			wifi.sta.autoconnect(1)
			print("Wifi activated",wifi.sta.getip())
			dofile("go.lua")
		  end,
		  function(err, str)
		    print("enduser_setup: Err #" .. err .. ": " .. str)
		    -- schedule reboot?
		  end
		)
	end
end)

It would be nice to have such an example chunk for init.lua

The lua_examples folder would be a nice place for that. Maybe write a comment about what go.lua is (I can guess, but just to be clear) Also set t=nil at the end Maybe have some emphasis on waiting for Wifi too.

I think a different PR would be good for that.

HHHartmann avatar Feb 01 '21 20:02 HHHartmann

The lua_examples folder would be a nice place for that.... I think a different PR would be good for that.

Yes, and then link to it from the docs.

marcelstoer avatar Feb 02 '21 15:02 marcelstoer

Oh, it's already here: #3395

marcelstoer avatar Feb 02 '21 15:02 marcelstoer

@blobule could you please address Gregor's comments?

marcelstoer avatar Mar 12 '21 11:03 marcelstoer