Moderator: igrr
python esptool.py -p com6 erase_flash
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.
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:
mylinuxbox$ 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:
mylinuxbox$ 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