ESP8266 WiFi Credentials auto saved to flash (ESP8266WiFi.h)
Posted: Sun May 01, 2022 1:17 am
I am looking for info to better understand how WiFi credentials are (or maybe not) automatically saved to flash. When referring to "EEPROM" I understand the 8266 doesn't actually have one, but simulates one with the flash memory using the EEPROM.h library and that the user interacts with a RAM copy and then can write the RAM copy back to flash.
This concern came about because I read a blog where "By default, the ESP8266 Arduino SDK saves its wifi configuration in flash memory." and "If your project is going to be restarting frequently (like going in and out of deep sleep often) I'd definitely use WiFi.persistent(false) to avoid wear on the flash." Most of my projects use deep sleep cycling to save battery power.
The Arduino Core documentation also makes similar statements about the auto save feature. "This is possible since ESP saves the credentials to the last used access point in flash (non-volatile) memory."
So two questions:
1. Does the SDK automatically save the WiFi credentials to flash?
2. Is wear out due to deep sleep cycles really a problem?
1. I created a simple script that successfully connected to my AP with explicitly listed SSID & PW. Then loaded a new sketch to try and connect without listing a SSID & PW, WiFi.begin(). Never connected. I also looked at the EEPROM/flash (first 128 bytes) to see if the SSID & PW were stored there. They were not. Maybe I looked in the wrong place.
2. I read somewhere else that there is no wear out problem with sleep cycles because the data is written to flash only if it changes, if you don't change the SSID and PW then there is no wear out. This seems to be an explicit feature of the EEPROM library, so I am not sure it applies in this case. I created another script that simply connected to my AP, went to sleep, then restarted and let it run for almost 200K cycles. As far as I can tell there was no flash wear out.
Am I missing something regarding the SDK auto save feature, or was the blog information bogus?
This concern came about because I read a blog where "By default, the ESP8266 Arduino SDK saves its wifi configuration in flash memory." and "If your project is going to be restarting frequently (like going in and out of deep sleep often) I'd definitely use WiFi.persistent(false) to avoid wear on the flash." Most of my projects use deep sleep cycling to save battery power.
The Arduino Core documentation also makes similar statements about the auto save feature. "This is possible since ESP saves the credentials to the last used access point in flash (non-volatile) memory."
So two questions:
1. Does the SDK automatically save the WiFi credentials to flash?
2. Is wear out due to deep sleep cycles really a problem?
1. I created a simple script that successfully connected to my AP with explicitly listed SSID & PW. Then loaded a new sketch to try and connect without listing a SSID & PW, WiFi.begin(). Never connected. I also looked at the EEPROM/flash (first 128 bytes) to see if the SSID & PW were stored there. They were not. Maybe I looked in the wrong place.
2. I read somewhere else that there is no wear out problem with sleep cycles because the data is written to flash only if it changes, if you don't change the SSID and PW then there is no wear out. This seems to be an explicit feature of the EEPROM library, so I am not sure it applies in this case. I created another script that simply connected to my AP, went to sleep, then restarted and let it run for almost 200K cycles. As far as I can tell there was no flash wear out.
Am I missing something regarding the SDK auto save feature, or was the blog information bogus?