Does <network.wlan>.connect() with no args performs a write operation to the flash?

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
JoeCharlieH
Posts: 8
Joined: Thu Dec 27, 2018 10:59 pm

Does <network.wlan>.connect() with no args performs a write operation to the flash?

Post by JoeCharlieH » 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.

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()
#-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
NOTE:
Creating an network object without the STA or AP arguments returns the object with my previous configuration (in this case STATION mode) :lol:

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Does <network.wlan>.connect() with no args performs a write operation to the flash?

Post by jimmo » Sun Sep 29, 2019 10:47 am

Hi,

I think the only way to be 100% is to hook up a logic analyser to the spiflash and verify whether a write is happening.

However, my understanding is that wifi_station_set_config is what writes to the flash, and MicroPython's connect method only calls this if you specify any arguments to connect(). Look at ports/esp8266/modnetwork.c

Post Reply