I'm working on a small product idea with my spark core, and setting up a serial interface for the customer to set up their product onto their wifi:
String newssid = wifissid(3); String newpw = wifipw(3); WiFi.setCredentials(newssid, newpw);
As you can see, I created 2 functions that over a serial connection to a pc returns the ssid and the password. I have already managed to get the setCredentials to work when I set the credentials in the code:
but when I run it with the strings, as above, it doesn't want to compile. the error given is:
serial_wifi_cred_change_3.cpp:49:39: error: no matching function for call to 'WiFiClass::setCredentials(String&, String&)' }
serial_wifi_cred_change_3.cpp:49:39: note: candidates are: In file included from ../inc/spark_wiring.h:37:0, from ../inc/application.h:29, from serial_wifi_cred_change_3.cpp:2: ../inc/spark_wiring_wifi.h:61:21: note: static void WiFiClass::setCredentials(const char*) static void setCredentials(const char ssid); ^ ../inc/spark_wiring_wifi.h:61:21: note: candidate expects 1 argument, 2 provided ../inc/spark_wiring_wifi.h:62:21: note: static void WiFiClass::setCredentials(const char, const char*) static void setCredentials(const char *ssid, const char password); ^ ../inc/spark_wiring_wifi.h:62:21: note: no known conversion for argument 1 from 'String' to 'const char' ../inc/spark_wiring_wifi.h:63:21: note: static void WiFiClass::setCredentials(const char*, const char*, long unsigned int) static void setCredentials(const char *ssid, const char *password, unsigned long security); ^
I don't know the answer.. but I am solving a similar problem to you using a smartconfig system from texas instruments? Smartconfig is used to pass wifi details to the core in the spark app, and TexasInstruments provide a sample app that you can modify.
The error states it doesn't want a string but rather a pointer to const char array. It looks like the documentation on the site is misleading.
Christian Loris is right.
setCredentials expects SSID and password to be
char * type. Your code should look like this:
String newssid = "foo"; String newpw = "bar"; char newssidBuf[newssid.length()]; char newpwBuf[newpw.length()]; newssid.toCharArray(newssidBuf, newssid.length()); newpw.toCharArray(newpwBuf, newpw.length()); WiFi.setCredentials(newssidBuf, newpwBuf);