-->
Page 1 of 3

Clear Stored WiFi Credentials

PostPosted: Tue Feb 16, 2016 11:26 am
by craigfoo
I'm developing on a Adafruit Feather HUZZAH with the Arduino and I ran a couple WiFi client examples to get started. I had to hard code my WiFi credentials and that worked fine. I used the WiFi.begin(ssid, password) function to get it working and it looks like it stored the WiFi credentials somewhere. How can I clear those credentials? Is there a tool out there that can format the ESP8266? I tried using the FS.h library and the SPIFFS.format() function but that doesn't clear the stored creds. Any thoughts?

Re: Clear Stored WiFi Credentials

PostPosted: Wed Feb 17, 2016 5:52 am
by Erni
You can use esptool to erase the flash

Code: Select allpython esptool.py -p com6 erase_flash

Re: Clear Stored WiFi Credentials

PostPosted: Wed Feb 17, 2016 8:47 am
by craigfoo
Thanks for the reply.

What if I wanted to implement a "factory reset" using a button? I want to programmatically erase all Wifi profiles that are saved in flash. I played around with the system_restore API and I think it's working but there might be a better way.

Re: Clear Stored WiFi Credentials

PostPosted: Wed Feb 17, 2016 1:48 pm
by gaber
If you want to factory erase based upon a button push -- and the factory erase function clears out the SSID values, then it looks like you need to write a little function that will clear the following address on most hardware: 0x7E000 -- around 128 bytes looks like the values you want to clear. On my flash, it is all FF's before a valid SSID is stored there. If that is not your address you want to find the right area. But anyway, you can check if its correct by reading from that area using esptool. No need to delete the entire flash if you want to nuke those settings.

You can investigate more by doing this before and after changing your wifi settings:

./esptool.py read_flash 0x7E000 128 wifisettings.bin

Then read the file using your favorite hex editor like xxd or whatever.
xxd wifisettings.bin

It is all FF's before saving an SSID:
Code: Select allmylinuxbox$ xxd wifisettings.bin
00000000: ffff ffff ffff ffff ffff ffff ffff ffff  ................
00000010: ffff ffff ffff ffff ffff ffff ffff ffff  ................
00000020: ffff ffff ffff ffff ffff ffff ffff ffff  ................
00000030: ffff ffff ffff ffff ffff ffff ffff ffff  ................
00000040: ffff ffff ffff ffff ffff ffff ffff ffff  ................
00000050: ffff ffff ffff ffff ffff ffff ffff ffff  ................
00000060: ffff ffff ffff ffff ffff ffff ffff ffff  ................
00000070: ffff ffff ffff ffff ffff ffff ffff ffff  ................


Then after saving an SSID and password that is successfully connected to:
Code: Select allmylinuxbox$ xxd wifisettings.bin
00000000: ffff ffff ffff ffff 01ff ffff 0a00 0000  ................
00000010: 4d59 5f53 5349 445f 3132 00ff ffff ffff  MY_SSID_12......
00000020: ffff ffff ffff ffff ffff ffff ffff ffff  ................
00000030: ffff ffff ffff 0131 3233 3435 3637 3839  .......123456789
00000040: 3031 00ff ffff ffff ffff ffff ffff ffff  01..............
00000050: ffff ffff ffff ffff ffff ffff ffff ffff  ................
00000060: ffff ffff ffff ffff ffff ffff ffff ffff  ................
00000070: ffff ffff ffff ff00 ffff ffff ffff ffff  ................


So if all you want to do is nuke that area of flash, then you can do this -- should work:

spi_flash_erase_sector(0x7E);

See this example code if you want to get more fancy with reading/writing values from the spi_flash
https://github.com/igrr/atproto/blob/ma ... ig_store.c

-Gabe