Search code examples
esp32

How do you erase ESP32 wifi Smartconfig credentials from flash?


I am using esp32 smartconfig to setup wifi credentials and it is working reliably. I want to be able to erase the credentials which are stored somewhere in flash from my arduino esp32 sketch.

The only way I have been able to erase the credentials (I'm not sure where they are stored) is to erase the entire flash using esptool.py from my Windows PC:

esptool.py --chip esp32 --port com8 erase_flash

I would like to just be able to erase the credentials from my sketch so a user without a pc would have this capability.

Thanks.


Solution

  • You haven't provided much details on your implementation, but if assuming the standard ESP-IDF implementation then the WiFi credentials are stored in Flash on the default NVS partition named "nvs" (overview). You can easily perform an erase cycle on the entire partition which will erase everything stored in your device.

    Alternatively you can hunt down the specific NVS keys used by the ESP WiFi component to store the credentials and erase only those. This is slightly risky as they haven't open-sourced the WiFi drivers and might change the implementation at any time. With that in mind, current ESP IDF 4.2 seems to store those keys in the default NVS partition under namespace "nvs.net80211". The relevant key names would appear to be "sta.authmode", "sta.ssid" and "sta.pswd".