Global function for erasing wifi data

Hey, i’m doing desktop lamp and need to add button to erase all wifi data, but can’t get it to work.

I already tried this code in usermod.cpp (called it in userLoop after millis() > 30000):

        #define EEPSIZE 2560
        //erase wifi name and pass from EEPROM
        EEPROM.begin(EEPSIZE);
        for (int i = 0; i < 95; i++)
        {
          EEPROM.write(i, 0);
        }
        EEPROM.end();

        WiFi.disconnect(true);
        ESP.restart();

but after restart it still connects to previous network. Is there anything I can do in usermod.cpp to achieve it?

That is supported natively and initiated by holding down the button for >6 seconds. :wink:

I forgot to mension that my board is esp01 and it doesn’t have builtin button, if that’s what you meant by ‘button’. Anyway it’s still weird that erasing EEPROM and ESP wifi data don’t do the job.

I thought maybe it’s just reset pin, but after i connected button to it and pressed for 6 seconds it’s the same problem as above. Restart → AP turns on for maybe 1 second-> and esp connects back to old network.

Button by default is gpio0 which is no RESET but PROG button for ESP8266 chips.

I’m not sure if it’s because of me, but button on this pin isn’t doing anything.

I just solved my issue via code - which is better for me. When i’m not calling ESP.restart() on the end, Access Point starts and I can change network.

Thanks for your help!

WLED stores all data in LittleFS file system. EEPROM is not used.

That would explain why it wasn’t working.

But why is it even using EEPROM for when it’s not needed, for example in wled_eeprom.cpp


  readStringFromEEPROM(  0, clientSSID, 32);
  readStringFromEEPROM( 32, clientPass, 64);
  readStringFromEEPROM( 96,      cmDNS, 32);
  readStringFromEEPROM(128,     apSSID, 32);
  readStringFromEEPROM(160,     apPass, 64);

edit: Erasing data from LittleFS works perfectly, after restarts it is no longer connecting to previous network, thank you for pointing that :slightly_smiling_face:

Okay it seems like a backup, if for some reason cfg.json don’t exist

Legacy.