Page 1 of 1
Saving WiFi credentials in the EEPROM
Posted: Mon Feb 19, 2018 10:33 pm
by mattia22500
Hi guys I just got an ESP32 and I was wondering how to save the wifi ssid and password in the EEPROM, so at every boot of the device I don't have to insert it from serial. Just correct me if my concept is wrong.
1) I could save each character of the SSID and PSW in the EEPROM:
e.g:
SSID = myRouter
EEPROM address 0 -> m
EEPROM address 1 -> y
EEPROM address 2 -> R
eccetera...
but how to define when the SSID is done?
2) Is there a way to do avoiding the EEPROM with AT commands? (I'm a newbie, I don't know what AT commands are or how to use them, I've just heard of them).
Thank you!
Re: Saving WiFi credentials in the EEPROM
Posted: Tue Feb 20, 2018 1:43 am
by kolban
There is a subsystem in the ESP32 ESP-IDF called "Non Volatile Storage" (NVS) which allows one to save arbitrary data in named locations. Once saved, they can be restored/read on a subsequent boot. This would be the easiest way to explicitly save and subsequently restore values. However, it is my understanding that there is a WiFi API provided by the ESP32 that saves the last used credentials (SSID and password) in flash automatically and will attempt to use them upon next boot.
Re: Saving WiFi credentials in the EEPROM
Posted: Tue Feb 20, 2018 1:52 pm
by mattia22500
Thank you! And great job for the documentation!
Re: Saving WiFi credentials in the EEPROM
Posted: Fri Feb 15, 2019 2:32 pm
by GeorgeFlorian1
kolban wrote: ↑Tue Feb 20, 2018 1:43 am
There is a subsystem in the ESP32 ESP-IDF called "Non Volatile Storage" (NVS) which allows one to save arbitrary data in named locations. Once saved, they can be restored/read on a subsequent boot. This would be the easiest way to explicitly save and subsequently restore values. However, it is my understanding that there is a WiFi API provided by the ESP32 that saves the last used credentials (SSID and password) in flash automatically and will attempt to use them upon next boot.
Where can I find the above mentioned "provided" WiFi API ? I am using Arduino IDE and a ESP WROOM 32.
Re: Saving WiFi credentials in the EEPROM
Posted: Fri Feb 22, 2019 6:39 am
by acsreedharreddy
kolban wrote: ↑Tue Feb 20, 2018 1:43 am
There is a subsystem in the ESP32 ESP-IDF called "Non Volatile Storage" (NVS) which allows one to save arbitrary data in named locations. Once saved, they can be restored/read on a subsequent boot. This would be the easiest way to explicitly save and subsequently restore values. However, it is my understanding that there is a WiFi API provided by the ESP32 that saves the last used credentials (SSID and password) in flash automatically and will attempt to use them upon next boot.
@kolban To store multiple wifi credentials we need to store them in the flash right?
Re: Saving WiFi credentials in the EEPROM
Posted: Tue Jul 27, 2021 3:46 am
by wts1985
It has been a while for this topic, to benefit developers who have the same question, here are what need to be done for ESP32 to store last used Wi-Fi credentials automatically:
- Set CONFIG_ESP32_WIFI_NVS_ENABLED to y
- Call esp_wifi_set_storage(WIFI_STORAGE_FLASH) <-- this is actually default value, just to confirm this function is not called with different parameter
Hope this helps.