@kfricke Thank you for your reaction. I will try to answer. I will start from the end...
So your guess would make half of the ESP SDK methods pointless.
I don't agree with this argument. I think that both groups of functions (DEFAULT and CURRENT) have different mission. DEFAULT set is for setting up the "initial conditions", under which the given application starts and works most of the time and which shall be set up by user during first run of program BOOT.PY. CURRENT set is for dynamic change of parameters within the program run and can be useful e.g. in MESH networks.
Just to make it clear, I would like to mention here that my comment to this discussion is related to the following information only:
a/ physical saving to flash memory is not applied if the information to be saved is the same as the information already saved in flash memory,
b/ I have been aware of the fact that in your application, as you described it, physical saving to flash memory is done because you change the parameters of function wlan.active(),
c/ at the same time I would like to mention that by using suitable strategy of the whole program application it will not be saved to flash memory more than once, even in case of first run of program BOOT.PY; other restarts of program only confirm stored parameters and that's why it's not physically saved to flash memory.
The philosophy of your approach is not optimal because you need to active the function wlan.connect(ssid,psw) anyway and it doesn't matter (with respect to energy of battery), if it happens during boot or some time later.
CODE: SELECT ALL
<interface>.connect(ssid, psk)
Explicitly writes the config to flash before connecting to the AP.
CODE: SELECT ALL
<interface>.active(state)
Does set the interface state and writes this to flash.
Your links to source code don't prove anything because it's been still valid that these functions will always execute the saving to flash memory only in case, if the information to save is changed. This bit of information is mentioned at each function in notes of ESP8266 Non-OS SDK API Reference.
From the above mentioned you can see that the requirement of API change is not as urgent at this moment as you present it. We can find suitable solution if you have a look from a different angle. To show how I really mean it, please see my program BOOT.PY as an inspiration which has proven in my applications and solves everything in the above described way.
Code: Select all
#aps_truseted.py ...
APS = {
"ssid_1":"psw_1",
"ssid_2":"psw_2",
....
"ssid_n":"psw_n"
}
# boot.py ... Create connection to trusted AP
from aps_trusted import APS
from network import WLAN, STA_IF, AP_IF
from esp import osdebug
from time import sleep_ms
def try_connection():
t = 10
while not wlan.isconnected() and t > 0:
print('.', end='')
sleep_ms(500)
t = t - 1
return wlan.isconnected();
osdebug(None)
ap=WLAN(AP_IF)
ap.active(False)
wlan = WLAN(STA_IF)
wlan.active(True)
print('connecting to last AP', end='')
print(try_connection())
if not wlan.isconnected():
## find all APs
ap_list = wlan.scan()
## sort APs by signal strength
ap_list.sort(key=lambda ap: ap[3], reverse=True)
## filter only trusted APs
ap_list = list(filter(lambda ap: ap[0].decode('UTF-8') in
APS.keys(), ap_list))
for ap in ap_list:
essid = ap[0].decode('UTF-8')
if not wlan.isconnected():
print('connecting to new AP', essid, end='')
wlan.connect(essid, APS[essid])
print(try_connection())
print('station configuration\n',wlan.ifconfig())
import gc
gc.collect()
I don't want to force anything to anybody, I have only tried to find a different angle and positive solution. I would be glad if my opinion will be understood well and if it inspires anyone.
Note:
I would like to suggest (to @pfalcon) not to activate default softAP but to make it during WEBREPL activation. I think it's useful because I can see a room full of attendees during a training with fresh flashed MicroPython who shall solve the task BLINK_LED, while there is the air full of RF smog with e.g. activated 10 APs..., which are useless at that moment. When the trained people reach WiFi topics, they will be able to activate necessary functions.