pfalcon wrote:From a pure Micropython users point of view, I was first surprised to see that the wlan config is kind of persistent.
I said this in pull request, will repeat here again: How your desktop computer works? Do you re-enter AP password each time you power it on? How your phone works? You enter AP password each time you press power button? Then what you're actually surprised about? ESP8266 with MicroPython is a little personal computer, and works in a way comfortable to user, that's it.
That is very much true desktop computer, I agree, and it is true for embedded systems with an OS (lets say the RPi).
However, it is not what people expect from a microcontroller unit (at least if they have a electronic engineering background).
People expect that the uC goes to down to a very defined state whenever you hard reset it. They assume that all and everything from that point will follow the same path, which usually start with some init process. For that reasons, I had copied the wifi init stuff in my boot.py first, since I thought I have to initialise the wifi at boot. The same behaviour scheme you will find in many other microcontroller units even FPGAs and DSP require a dedicated initialisation step (e.g. load the bit-file from a flash memory into the FPGA).
Thus, your comparison might not be complete valid. What happens in the esp, is much more comparable to what happens in a PC during boot. Do you know any PC, which rewrites its bios chip several times during boot-up?
I can see why we have this behaviour. The esp was initially planned as a companion chip with a AT-based interface. People should and could expect that ones sending the credentials to the chip, it will be stored and available. That is, the chip inits itself independent of the state of the host controller and hence it can start to communicate with the wifi network "automagically".
Myself, as a developer, I'd prefer that ESP8266 credentials were not persistent. But as a user, I love that persistence feature very much, it's very practical! A lot of users is used to it, and a lot of those users won't read any of documentation updates, and there will be a blizzard of reports "My esp8266 doesn't remember my AP, help!!!111"
If this is such an heavy brain-breaking change, could we, for some time add a debug message to repl?
For the release before the change will happen:
"NOTE, IN THE FUTURE wifi credential storage is not persistent anymore, refer to
http://www.micropython.org/XXXX for more details"
From the release that introduce that change:
"NOTE, wifi credential storage is NOT persistent anymore, refer to
http://www.micropython.org/XXXX for more details"
That message could appear whenever the usually behaviour is expected. This is at least a method many command-line tools use to inform users that changes will happen / had been made and gives them time to adapt.
If we go with non-persistent as standard (also do not load from flash), the easiest solution would be to add two commands esp.write_wifi_flash() and esp.read_wifi_flash(), where no arguments for write would take whatever is set at that time, or optional allow to give the wifi credentials as argument (better names might be found).
Thus, the persistent behaviour like before would be then:
Code: Select all
import network
# enable station interface and connect to WiFi access point
nic = network.WLAN(network.STA_IF)
nic.active(True)
nic.connect(esp.read_wifi_flash())
which would nicely fit in boot.py