Wfi Getting and Clearing Credentials via CLI

Is there a CLI method for:

  1. Getting to see the saved APs and cipher modes, similar to the Wifi.getCredentials() in code?
  2. Clearing Credential Cache
  3. A way to see which AP the device is connected to without anything in code to help with this (such as Serial.println() etc.)

Do credentials get saved even if connection was not successful?
When I try Wifi.getCredentials() in code it seems to hang at this method, or blocks for a really long time, so long that I haven’t waited long enough to see.

  1. No (would pose some security risk)
  2. Not that I know of - but holding SETUP for 10+ sec will do that
  3. Nope

Credentials do get saved even for non-present networks if the enc cipher could be obtained.

What status was your device in when you called WiFi.getCredentials()?

I had the getCredentials() code being called in the setup() function, with a Serial.println() in a loop for all saved credentials. The loop never executed.

No (would pose some security risk)

Not if one required to be logged in, no?

Not that I know of - but holding SETUP for 10+ sec will do that
Aah, thanks, I should try that?

What is going on is that I set up an AP, which it can’t connect to so it connects to another AP (from cache) and I assume it connected to the new one. That got me in a fix because I assumed I was using the new AP :smile:

@ScruffR

I am hopping on this thread to save opening a new one! It is related I promise!

Is there any circumstance where WiFi.clearCredentials() can return true yet not have cleared all credentials? I.e. the wifi network currently connected to is not cleared.Should the wifi module be off before issuing a wifi.clearCredentials?

Is there a way to clear only certain credentials from the cache/store? A bit like - 'Forget this network" on an iPhone.

Thanks

Armor

I’d say you at least should WiFi.disconnect() - but I’m rather positive that even the currently connected WiFi would be cleared, but I don’t think you’d get disconnected.
Have you tried a reset after you called WiFi.clearCredentials() and did it still reconnect?
And no, there is no way to only remove a single set of credentials.

1 Like

You’re correct. From my experience with clearCredentials(), all credentials are cleared including the current one.

2 Likes

Thanks for getting back on these points - I don’t want to throw a reset as the clear credentials is in an admin menu to manage wifi connections! I will include the wifi.disconnect() before the wifi.clearcredentials() just to be safe.

Without being able to selectively forget networks it is a bit clumsy for an end-user to move a device from one network to another, especially if the device is in an area with many WAPs available but you only want to connect to one specific one - I guess I could setCredentials for a stored WAP with the password blank - unless you know otherwise? (Or you don’t understand what I am getting at!)

Thanks - I would be interested if you could share your experience in getting devices to wifi connect for the first time and thereafter after a reset. I am finding that some devices take a lot of tries to connect and in the same location/circuit others are very fast or instant.

I have the same experience. That is the amount of time a device takes to connect changes (sometimes a long time and sometimes almost instant). This doesn’t seem to have any bearing on:

  1. The number of cached credentials
  2. Resetting credentials
  3. Which network the device was connected to the last time

If I am connected to a WAP, then check if those credentials are stored, clear all the credentials (and get wifi disconnected automatically) and then scan for available networks and select and enter the credentials for the same same WAP (or any other available) followed by WiFi.connect(WIFI_CONNECT_SKIP_LISTEN); it stays listening / flashing blue. Any idea why this is the happening and what should I do to get it back connected. Turning the photon off /hard reset works - but I don’t want to this.

What SYSTEM_MODE() are you using?
Are you using SYSTEM_THREAD(ENABLED)?

If you are in AUTOMATIC mode, I’d guess that you’ll directly fall into Listening Mode and don’t even get to your WiFi.connect(WIFI_CONNECT_SKIP_LISTEN);.
To avoid this, either use a non-AUTOMATIC mode or explicitly/“manually” disconnect before clearing credentials.

Something else you could/should do is to add a delay (or a Particle.process()) between WiFi.setCredentials() and WiFi.connect() - and maybe also a WiFi.off()/WiFi.on() combo.

@ScruffR
I always the following, I should have said:
SYSTEM_MODE(SEMI_AUTOMATIC);
SYSTEM_THREAD(ENABLED);

As you said WiFi.clearCredentials() does not clear the currently connected WAP unless I put WiFi.disconnect() before it.

I haven’t had a chance to check out the whether toggling wifi.off/wifi.on then wifi.connect solves the always listening problem.

Small update: I have another command to allow a user to disconnect from the current connected WAP. I have a dynamic indicator on the device screen and to my surprise when I call WiFi.disconnect() it briefly goes off and then within a couple of seconds reconnects to wifi and particle cloud. Should I be turning off the radio module WiFi.off()? Or is this happening because I am not doing Particle.disconnect() before the WiFi.disconnect()?