When does "wifi_on_boot" happen?
I'm fiddling with a kind of "smart provisioning"...
- Setting my LoPy1 to AP mode
- Having a tiny web server, showing of a page with the surrounding wifi networks
- A simple form for giving the wanted ssid and password
Then I save the ssid and password:
pycom.wifi_ssid_sta(set_ssid) pycom.wifi_pwd_sta(set_pwd) pycom.wifi_mode_on_boot(WLAN.STA) pycom.wifi_on_boot(True)
and reset the device with machine.reset().
In my boot.py I check if wifi_on_boot is True and set the depending main file with machine.main('main_wifi.py').
In main_wifi.py I simply do
from network import WLAN import time import machine wlan = WLAN() time.sleep(2) try: while not wlan.isconnected(): time.sleep_ms(50) print(wlan.ifconfig()) rtc = RTC() rtc.ntp_sync("de.pool.ntp.org", 3600) print(rtc.now()) except: print("reboot in 5s") time.sleep(5) machine.reset() pycom.rgbled(0x00FF00) print("Everything is running fine")
But it will never connect. It allways runs into a timeout and reboots. SSID and Password are set correct. Is this only working with Pybytes?
I run on the latest firmware but with deactivated Pybytes support.
which you are able to change on the fly if needed. For OEM modules, there's only one option as there's only one antenna port
That is a good point! I'll add it to the FW to-do list.
Though I do not see any issues arise from the parameter missing directly. By default, the on-board antenna is selected for development modules, which you are able to change on the fly if needed. For OEM modules, there's only one option as there's only one antenna port
@Gijs Good to know that it happens bevor boot.py is executed.
Therefor, I'm missing a parameter:
pycom.wifi_mode_on_boot(mode, antenna). If the wifi is set before the boot.py is executed, it should also be possible, to set the right antenna, isn't it?
To clarify, the
pycom.wifi_on_boot()sets the wifi settings even before the
boot.py. You can use the accompanying functions from the API (https://docs.pycom.io/firmwareapi/pycom/pycom/#boot-methods) to set the SSID, AP or STA mode, and the password. Next to that, the method is only activated after resetting the module (meaning you will not see the behaviour directly after changing the settings, but only after a reset)
Ok, I can answer my questions by myself now ;-)
Everything works now like expected. I just reset my home AP, after I recognized, that my mobile is also not connecting to my wifi network.
Sometimes things are so stupid... ;-)