Lost Photon after setting credentials

I expect to use my Photon application from two different WiFi networks. So I added to the setup() code of the app the setting of the credentials for the two WiFi networks, let’s call then WiFiA and WiFiB. I have been using WiFiA for my testing (WiFiB is not visible from the location of WiFiA) and after the app was running as expected, it was time to add the code to set both credentials:
As per the documentation, this adds the network credentials to the list of up to 5 WiFi networks that can be held in the Photon. The list is used the next time the Photon is reset.

After I reset the Photon, it never connected to the cloud again. I assume since it was WiFiB which I programmed last, it was the first in the list of networks to attempt to connect to. Upon a reset the Photon continued to blink fast Green while looking for WiFiB which is not accessible from the location of the Photon. I expected the Photon to back off and successfully connect to WiFiA which was also in the list of SSIDs but it never got out of the flashing Green mode and I am assuming that it was stuck on WiFiB and never tried WiFiA which it had been using for several days.

Now that it could not connect to WiFiA, I was unable to flash a new version of the application. The Photo was not connected to the cloud. I attempted to go into Safe Mode but that also left me with the flashing Green LED. I could not fix this using CLI either for the same reason. I ended up having to use the DFU Utility to reload the firmware, then erase the list of SSIDs using the setup button, then using the Particle IOS app to program a good set of credentials. I had tried using the CLI command “particle setup wifi” and selected the good network but it still would not connect. It was only after using the IOS app that I got back to the cloud.

I am afraid to run the test again where I set both sets of credentials until I get some feedback from the community. Is there a known problem with the Photon when multiple SSIDs are in its list of networks? Does the Photon have a known problem of connecting to another network in its list if the first network in the list does not respond? To me it appeared that I was stuck on a SSID which was not available from the current location of the Photon.

It’s a good idea to use Setup mode to configure the WiFi credentials since that will work in all modes (including safe mode, should your application firmware have a bug that prevents it getting on the cloud.)

Here’s how to get out of the problem you’re in:

  • launch the photon in safe mode
  • hold the setup button for 3 seconds and configure WiFi using particle cli
  • reset, and re-enter safe mode
  • the device should now connect to the cloud.

I’ll investigate using WiFI set credentials and will report back with any findings.

@mdma - It would appear that there is a problem with WiFi.setCredentials(“mySSID”,“myPassword”,WPA2) in v0.4.4. I removed the setting of the credentials for WiFiB and just left the setting for WiFiA which is the network I have been testing with. Following a reset, when the new credentials were put into effect (and should have been the same as what I have been using all along), the Photon failed to connect to the cloud. It just kept fast blinking green. I had to use safe mode and the IOS app to restore the SSID/Password/WPA2 info that were the parameters of the setCredentials(). I removed the setCredentials() from my app altogether, and after a reset I had no problem reconnecting to the cloud. So it looks like I only had the problem with I used setCreditials() in my app.

For the credentials to work using the 3 parameter version of setCredentials, the AP must be available for the device to scan.

I’ve made a PR here that allows the application to pass the Security Cipher to setCredentials() so that it can work with hidden and offline networks also. (Once the cipher is known, scanning the network is no longer required.)

WiFi.setCredentials("ssid", strlen("ssid"), "password", strlen("password"), WPA2, WLAN_CIPHER_AES);

If you’re able to build locally, flash system-part2 and rebuild your app with this extended call.

If you’re certain that the AP can be scanned when you’re calling set credentials, please file an issue and provide steps/code to reproduce. Thanks! :smile:

The reason for setting up multiple credentials can certainly be that you intend to use the device in any of multiple locations. So it is pretty certainly that one or more of the credentials are for a network that is not available when the credentials are set. The documentation did not point out the requirement to have the AP available at the time.

It would probably be better if instead of this call variant specified, you just add a 4th parameter to the existing WiFi.setCredentials() as WLAN_CIPHER_AES. Certainly cleaner than have to specify strlen()'s which are already being determined in the 3 parameter call.

So you are also implying that my app should have worked when I only set the credentials for WiFiA which I have been successfully using all along. I will have to re-run my test, as I did have a failure to connect to the cloud following the setting of that credential.

@mdma - As a temporary solution for a one time setup, can I just the IOS app to configure the Photon to use WiFiA then bring the device to the other network and use the IOS app to configure it to WiFiB? Will it then remember both WiFiA and WiFB and I will be able to bring the device in range of either network and have it automatically connect to whichever one it sees?