Argon clearCredentials not working as expected?

Executing this code fails to clear credentials even though it indicates they were cleared:

    if(WiFi.clearCredentials()){
        Serial.println("ALL Wifi credentials have been removed!");
    }else{
        Serial.println("Could not clear credentials!");
    }
    WiFiAccessPoint ap[5];
    int found = WiFi.getCredentials(ap, 5);
    Serial.println("Credentials stored for:");
    for (int i = 0; i < found; i++) {
        Serial.println(ap[i].ssid);
    }

The getCredentials for loop lists all the credentials that were there prior to the clearCredentials command. Is there something I’m missing?

This is a current known issue which is going to be resolved in one of the next releases in 1.2.x line.

As a temporary workaround, ensure that WiFi is disconnected before attempting to clear the credentials:

WiFi.disconnect();
WiFi.clearCredentials();
1 Like

Hello,

Just to check, this code up here did not clear the credentials when I tried…
I fix it by turning the wifi off and stops the execution for 5seconds …that works while the issue is fixed, but is there a “cleaner” way?

WiFi.off();						
delay(5000);				
WiFi.clearCredentials();			// Clear previously stored credentials to proper work
WiFi.on();

@EPC, you need to turn the WiFi ON before you can clear the credentials.

1 Like

Hello,

Thanks for your answer. Actually it works with the code I typed up here and did not work before, when I turned the wifi ON before clearing the credentials…

I have just checked again. This works:

				WiFi.off();
				delay(5000);
				WiFi.on();
				ok = WiFi.clearCredentials();			// clear credentials	

This code, also works:

				WiFi.off();
				delay(5000);
				ok = WiFi.clearCredentials();			// clear credentials	

But this does not:

				WiFi.off();
				WiFi.on();
				ok = WiFi.clearCredentials();			// clear credentials	

Neither this:

WiFi.on();
//some other instructions...
WiFi.disconnect();
ok = WiFi.clearCredentials();			// clear credentials	

So it seems to be related to the delay when turning on or off and not that much with the wifi on…is that possible?
Is there a way to make it work without the delay?

Are you using SYSTEM_THREAD(ENABLED)? If so, WiFi.on() and WiFi.off() are asynchronous, so I’d guess the version without the delay fails because the disconnect from WiFi.off() has not completed yet.

Yes, the problem might be around there because the cyan LED does not stop breathing after wifi off… but I am not using SYSTEM_THREAD.

However I am using SEMI_AUTOMATIC mode. then i connect to the wifi in the setup and this clear credentials is inside loop. and then connect to a different wifi ssid.

In 1.4.4 Argon clearCredentials() always seems to return false even though it successfully clears the credentials.