WiFi.setCredentials help

I want my core to connect the WiFI of a house that I have all the Credentials.
I tried add this line to the setup but it didn`t work:
WiFi.setCredentials(“My_Router”, “wepistheworst”, WEP);

Any advice about what should I do? what is the best way to set a core that it will connect without the CLI connect or the app connect?
Thank you in advanced. everybody in this community helps a lot!

Your only option left is via the USB and a Terminal program.

See: http://docs.spark.io/connect/#connecting-your-core-connect-over-usb

According to http://docs.spark.io/firmware/

Allows the user to set credentials for the Wi-Fi network from within the code. These credentials will be added to the CC3000’s memory, and the Core will automatically attempt to connect to this network in the future.
// Connects to an unsecured network.

// Connects to a network secured with WPA2 credentials.
WiFi.setCredentials(SSID, PASSWORD);
WiFi.setCredentials(“My_Router”, “mypasswordishuge”);

// Connects to a network with a specified authentication procedure.
// Options are WPA2, WPA, or WEP.
WiFi.setCredentials(SSID, PASSWORD, AUTH);
WiFi.setCredentials(“My_Router”, “wepistheworst”, WEP);

I have the core connected already but i want it to connect to a house on the first visit without connect the core to usb by using the setCredentials.

According to the output in the smartConfig serial, the spark team haven’t got WEP to work, even though it’s advertised as being supported by the CC3000.

I tried a little last week and couldn’t even get my DD-WRT router and Win7 machine to talk over WEP-encrypted wifi. I have a really old router somewhere so I’ll dig that up and have another go.

But in the meantime, is it possible to change the encryption type on your wifi network to WPA or WPA2?

I already have WPA2.

Great, then you’ll need to change the line WEP to WPA2 in this line of code:

I changed it already.

Hi, I have a same problem. I’ll try to set WIFI password using this code:

WiFi.setCredentials("myssid", "mypassword", WPA2);

But it not works :frowning: , when I do it over Spark APP or CLI then it works.
Does someone know how to get work this? I’m using router TP-Link WR1043ND.

Haven’t tested but the following needs to happen:

1.) User code must run once to add this new network to the CC3000 list.

2.) This will only be used in future. I.e. upon restart.

So if you have a core with no Wifi credentials (blinking blue), flashing this code will not work as the user code will not run.

Also, if you use the default behavior, the core must first connect to a network (SYSTEM_MODE(AUTOMATIC)) before the user code will run.

Which scenario are you in? :slight_smile:

1.) I tested it with a factory reset core with no Wifi credentials and the code running in MANUAL mode did not add the Wifi credential to the core.

2.) With 1 x Wifi profile in the core, using the function to add the Wifi credentials on my mobile hotspot worked fine and the core connected to it correctly.

Also, another thing i found out is that, WiFi.on() needs to be called first in Manual and Semi_automatic mode in order for setCredentials() to work if you are intending to add in WiFi credentials for the first time in a core without any credentials.

That’s also the same procedure required even with existing WiFi credentials. Any mode other than AUTOMATIC, requires WiFi.on() followed by WiFi.setCredentials() for this to work


Hi, I am using AUTOMATIC mode, so I assume that it supposed to work then, but it still doesn’t.

So to get this all clear , WEP ,WPA , WPA2 are constants ? Because they should have appeared on the
constants link in the Core Code(Firmware) area of the documentation . If they were strings then in the example WEP should have been between " " <— these

Hi @Cristof

They are #define in C similar to the constants in the doc, but they are not generally used–they are only used with WiFi.setCredentials(). I think it would be confusing to doc them next to HIGH and LOW which get used a lot more.

Here is the doc example which lists the legal values as WPA2, WPA, or WEP.

// Connects to a network with a specified authentication procedure.
// Options are WPA2, WPA, or WEP.
WiFi.setCredentials(SSID, PASSWORD, AUTH);
WiFi.setCredentials("My_Router", "wepistheworst", WEP);

Got it ! Thank you for your answer !

1 Like

Hi everyone,

I am also trying to set the credential from an sd_card. Spark reads SSID and Password from sd_card (I verified the sdcard initialization and everything).

This is what I am trying to do:
I first connect the spark to a network and flush the code with Semi-automatic mode, which will initially run the setup. In setup function I am trying to set the credential with new ssid and password, which is read from an sdcard. But afterwards it still tries to connect the previous connection.

What might be the reason?
Any help would be perfect.
Thanks in advance

Be sure to call Wifi.disconnect(), then WiFi.connect() after setting the credentials so the core re-connects to whatever wifi APs are available.

The spark core remembers 4 sets of wifi credentials, so the old credentials will still be there, and tried if the new ones given don’t work.

@mdma: is it preferable to revive old sort-of-on-topic threads as opposed to starting new ones?

It appears that WiFi.setCredentials() blocks for about 1.5 seconds…which seems to be a long time to just write them to the CC3000’s NVMEM. (AFAIK, that’s all that the call really appears to do.) setCredentials is declared void…but is there a way to quickly find out if the just-set credentials don’t work?

At present, the only way to know if the credentials don’t work is to try to connect to wifi.

We could add a system event that is posted when wifi connection fails or has a timeout.

@mdma: That would be really handy…but considered a should be considered a luxury, not a necessity!