Does <network.wlan>.connect() with no args performs a write operation to the flash?
Posted: Thu Sep 26, 2019 11:48 pm
Hi, I've been working on some remote room temperature sensing with a battery powered ESP8266.
So, I've already read all the related topics about storing Wi-Fi credentials and Flash wearing out.
My question is, does issuing <network.wlan>.connect() without the ssid and password performs a write to the Flash?
Because, messing around with the deepsleep() function and soft_resets makes the Wi-Fi interface not active from boot, and performing and <network.wlan>.active(True), which also performs a write operation, doesn't make the device automagically connect to the stored credentials in Flash.
Until I perform <network.wlan>.connect() with no args, either from the REPL or main script.
But, creating the network object in the main.py script and doing <network.wlan>.active(True), with no .connect(), connects the ESP to the WI-FI router.
NOTE:
Creating an network object without the STA or AP arguments returns the object with my previous configuration (in this case STATION mode)
So, I've already read all the related topics about storing Wi-Fi credentials and Flash wearing out.
My question is, does issuing <network.wlan>.connect() without the ssid and password performs a write to the Flash?
Because, messing around with the deepsleep() function and soft_resets makes the Wi-Fi interface not active from boot, and performing and <network.wlan>.active(True), which also performs a write operation, doesn't make the device automagically connect to the stored credentials in Flash.
Until I perform <network.wlan>.connect() with no args, either from the REPL or main script.
But, creating the network object in the main.py script and doing <network.wlan>.active(True), with no .connect(), connects the ESP to the WI-FI router.
Code: Select all
#---------------------------------------------boot.py----------------------------------------------------------------------------------------------------------------
import esp
#import webrepl
import gc
import machine
import network
esp.osdebug(None)
if machine.reset_cause() == machine.DEEPSLEEP_RESET:
print('\nwoke from a deep sleep')
else:
print('\npower on or hard reset')
# configure RTC.ALARM0 to be able to wake the device
rtc = machine.RTC()
rtc.irq(trigger=rtc.ALARM0, wake=machine.DEEPSLEEP)
# configure WI-FI
sta = network.WLAN(network.STA_IF)
sta_active() ### This returns False
sta_active(True)
#sta.connect()?????
gc.collect()
Code: Select all
#---------------------------------------------main.py----------------------------------------------------------------------------------------------------------------
# Network Interface
station = network.WLAN(network.STA_IF) ### Flash write #1
ap = network.WLAN(network.AP_IF) ### Flash write #2
station.active(False) ### Flash write #3
ap.active(False) ### Flash write #4
# station.connect("XXXXX", "XXXXXXX")
while station.isconnected() == False:
pass
print('Connection successful')
station.ifconfig(('XXX.XXX.X.X', 'XXX.XXX.XXX.X', 'XXX.XXX.X.XXX', 'XXX.XXX.XXX.XX')) #Just to keep everything static
#All my related MQTT black magic goes here
#...
#...
#...
rtc.alarm(rtc.ALARM0, 300000) #Trigger RTC alarm after 5 minutes
machine.deepsleep()
#-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Creating an network object without the STA or AP arguments returns the object with my previous configuration (in this case STATION mode)
