Remove "Auth" option from WiFi.setCredentials()?

Yes, I know the topic title got everyone’s attention :smiley:. Basically, with my research on the forum, I’ve noticed that both the Core and Photon know the encryption method on each and every network that they can see.
With that being the case, I submit that the “Auth” property on WiFi.setCredentials() is unnecessary–it can be auto-filled by the firmware, which already knows the encryption method. Yes, I’m aware that it is optional, but it appears to then default to assuming WPA2 encryption. The example from the docs:

// Connects to a network ---->secured with WPA2 credentials<----
WiFi.setCredentials(SSID, PASSWORD);
WiFi.setCredentials("My_Router", "mypasswordishuge");

Ditto in the Particle Dev IDE–there should not be an option to change the encryption method on the “Setup device’s WiFi” feature. (P.S. The lockout shade bug on this feature is still there in the latest version of Particle Dev.)

It seems to me that if the Photon/Core can’t determine the encryption level on the network, it probably can’t connect to it, either! Correct me if I’m mistaken about this.

How about if you are setting up credentials when the AP is not present. That will not work in such event.

1 Like

NIce idea! Just a few kinks to work through - the device only knows the encryption if it first scans the networks (which takes too long to do on each connection), and - here’s the rub - then this works only if the network is broadcasting it’s SSID, which not everyone does.

So we can’t remove the parameter for all cases. But we could add a AUTO value for use in cases where it would work.

This instructs the device to scan for the SSID to determine the security type. In part this is what the photon already does - scans the networks, since the WiFi security details should also include cipher (AES/TKIP) and these details aren’t present in the setCredentials call.

To the final call could look like

WiFi.setCredentials(ssid, password, AUTO);

The device checks the security setting, and if it’s AUTO, scans the networks to determine the actual security, which is then saved, avoiding the need to scan next time.

@mdma That works. I assume that the Core/Photon already stores the encryption type with the credentials for connecting, which makes perfect sense. Anything wrong with just leaving “Auth” blank for “AUTO”?

@HardWater: True. But it’s a good assumption that sooner or later, the Core/Photon will encounter the network that it’s connecting to, and could then identify the encryption method. AFAIK, neither Particle Dev nor the Spark app will let you connect the Core to a non-existent AP, for obvious reasons of SmartConfig. If I understand correctly, that’s only possible through WiFi.setCredentials().

Yes but you can set credentials via the USB cable there are lots of possibilities out there and I don’t know that it makes a good path to limit them needlessly.

@HardWater. You’re right. I :thumbsup: an “AUTO” setting…there’s nothing quite as frustrating as not finding the option you were looking for…

(…well, that can be taken both ways. Anyway.)

1 Like