Saving WiFi credentials in the EEPROM

mattia22500
Posts: 5
Joined: Sun Feb 11, 2018 9:24 pm

Saving WiFi credentials in the EEPROM

Postby mattia22500 » Mon Feb 19, 2018 10:33 pm

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!

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Saving WiFi credentials in the EEPROM

Postby kolban » 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.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

mattia22500
Posts: 5
Joined: Sun Feb 11, 2018 9:24 pm

Re: Saving WiFi credentials in the EEPROM

Postby mattia22500 » Tue Feb 20, 2018 1:52 pm

Thank you! And great job for the documentation!

GeorgeFlorian1
Posts: 160
Joined: Thu Jan 31, 2019 2:32 pm

Re: Saving WiFi credentials in the EEPROM

Postby GeorgeFlorian1 » Fri Feb 15, 2019 2:32 pm

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.

acsreedharreddy
Posts: 2
Joined: Sat Nov 10, 2018 7:28 am

Re: Saving WiFi credentials in the EEPROM

Postby acsreedharreddy » Fri Feb 22, 2019 6:39 am

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?

wts1985
Posts: 3
Joined: Wed Apr 07, 2021 9:55 am

Re: Saving WiFi credentials in the EEPROM

Postby wts1985 » Tue Jul 27, 2021 3:46 am

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.

Who is online

Users browsing this forum: Google [Bot] and 154 guests