-->
Page 1 of 2

ESP8266 WiFi Credentials auto saved to flash (ESP8266WiFi.h)

PostPosted: Sun May 01, 2022 1:17 am
by s100
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?

Re: ESP8266 WiFi Credentials auto saved to flash (ESP8266WiF

PostPosted: Tue May 03, 2022 12:12 am
by JurajA
if it is always the same credentials, then it is not a problem (unless you call WiFi.disconnect() before WiFi.begin()).
If you have saved credentials you don't need to call WiFi.begin(). the esp8266 connects automatically. just test the WiFi.state() to wait for the connection.
If you want to use WiFi.begin() in the sketch, then disable saving of the credentials with setPesistent(false)

Re: ESP8266 WiFi Credentials auto saved to flash (ESP8266WiF

PostPosted: Tue May 03, 2022 9:20 am
by Inq720
s100 wrote: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. Yes and is configurable.
  2. Cycles that cause wear on flash only occurs when Erasing a flash sector. Reading does not. Writing does not either, but you can not overwrite a previously written area without first erasing. I've tested three ESP8266 ESP-01 models to destruction. They croaked between 400,000 and 900,000 Erases.

Re: ESP8266 WiFi Credentials auto saved to flash (ESP8266WiF

PostPosted: Thu May 12, 2022 9:16 pm
by s100
Thank you, that answers my major question. Rather than ask for a fish dinner on the details, is there some online documentation I could read that would dive deeper into this?