Unable to set WiFi credentials after calling WiFi.connect()

Is it possible to set WiFI credentials into WiFi controller using WiFi.setCredentials() after calling WiFi.connect(). I am unable to do this. I think while WiFi controller is trying to establish a connection, none of the WiFi.API’s work.

Is my finding correct?


I can assure you it works.
I’ve just tested this after WiFi.connect() and Particle.connect() and it works in both scenarios.
The only thing you might need to do is to wait for the desired condition (WiFi.ready() respectively Particle.connected()) to come true.

Also, if you are trying to setup a hidden/unavailable WPA/WPA2 network, you also need to provide the WLAN cipher in order to get the credentials to stick.


Hello @ScruffR,
Thanks for the reply. I am unable to set new WiFi credentials while the WiFi controller is attempting to try to connect to WiFi. Here is the sequence:

WiFi.setCredentials(“ssid1234rewq”, “password”);

//At this point if the device is unable to connect to the set WiFi, I want to save new credentials.

But calling setWiFi credentials while the WiFi controller is attempting to try a connection doesn’t work. I can’t even turn WiFi module off. None of the WiFi related API’s work when a WiFi controller is attempting to connect to a WiFi network.

But you are correct. Once the WiFi controller is connected to WiFi, you can call setWiFiCredentials and that works.


If you are running (default) SYSTEM_MODE(AUTOMATIC) your code won’t run until the device is connected to the cloud.

You can use a non-AUTOMATIC mode and/or SYSTEM_THREAD(ENABLED)

I am using semi-automatic with system thread enabled