I’m trying to add WiFi credentials directly through code. However looking at the documentation I am unsure of how to actually use setCredentials(). I know this is a very elementary question and I feel dumb for not figuring it out myself. I feel like WiFi.setCredentials() is an internal function however when I try to use it it is acting like I have to write the function. Any help is appreciated.
Yup, that’s how you’d do that.
If this set of credentials is the only one to be stored, you could check for WiFi.hasCredentials() and only do the setting thing if that returns false (this’d only work in non-AUTOMATIC modes or in STARTUP() before the forced Listening Mode gets triggered)
Or you set an EEPROM flag to indicate your credentials had been set already.
// for hidden and offline networks on the Photon, the security cipher is also needed
// Cipher options are WLAN_CIPHER_AES, WLAN_CIPHER_TKIP and WLAN_CIPHER_AES_TKIP
WiFi.setCredentials("SSID", "PASSWORD", WPA2, WLAN_CIPHER_AES));
While the required WLAN cipher can be assessed by “listening” to a present network, this is not possible for a non-present, so you have to provide that info beforehand.