Hi guys!
I had gotten the same Unbound's problem when i worked with Adafruit CC3000 wifi breakout and Arduino UNO R3 but
i found out solution for this problem. In fact, this is not a CC3000's problem, it's just that Adafruit's engineers do not show us the best way to use
Adafruit_CC3000::connectToAP api.
The
Adafruit_CC3000::connectToAP api, in the original,
has 4 parameters, you can see this in
"Adafruit_CC3000.cpp" file at following folder path:
C:\Users\<your_pc's_user_name>\Documents\Arduino\libraries\Adafruit_CC3000_Library-master
If you open this file up, you'll see that the
Adafruit_CC3000::connectToAP api's prototype is:
Code: Select all
bool Adafruit_CC3000::connectToAP(const char *ssid, const char *key, uint8_t secmode, uint8_t attempts)
But when you use this api in your sketch, you (and Adafruit's engineers) bind only 3 parameters to the api, those are the "ssid", the "key" and the "secmode" and the api still works! So, what is "attempts" parameter for and why does not it appear in “connectToAP” api of ”buildtest” sketch from Adafruit?
At first, what is this parameter for?
It’s the times that cc3000 will attempt to connect to an AP and this is the key of the problem that Unbound and I got (maybe you did).
By default, this parameter’s value is “0”, it means that cc3000 module will attempt to connect to an AP forever until it connects to the AP successfully – this is not good in almost cases.
Secondly, why does not “attempts” parameter appear in “connectToAP” api of ”buildtest” sketch from Adafruit?
The reason for this is, as I mentioned above, this parameter’s value is “0” by default so we don’t need to use it when we call the api (in fact, maybe sometimes we want to use it, but we don’t know how to do that :D ). This is done in the api’s prototype declaration in
“Adafruit_CC3000.h” file, which is in the same folder with "Adafruit_CC3000.cpp" file. In this file, connectToAP api’s prototype is declared as the following:
Code: Select all
bool connectToAP(const char *ssid, const char *key, uint8_t secmode, uint8_t attempts = 0);
As you can see,
by default, attempts = 0
So, at last, how to solve the problem?
All things we have to do are just
open “Adafruit_CC3000.h” file, change this line
Code: Select all
bool connectToAP(const char *ssid, const char *key, uint8_t secmode, uint8_t attempts = 0);
to
Code: Select all
bool connectToAP(const char *ssid, const char *key, uint8_t secmode, uint8_t attempts);
then save the file and use "connectToAP" api like this: cc3000.connectToAP(ssid, key, secmode, n); instead of connectToAP(ssid, key, secmode); in our sketch. “n” in the function cc3000.connectToAP(ssid, key, secmode, n) is the times that you want the cc3000 to attempt to connect to your AP, it can be 1, 2, 3, … or any value that you want.
As I tested, if n = 2, It takes about 46 seconds from the moment cc3000 starts connecting to the AP to the moment the api return “false” value if it cannot connect to the AP. If n = 3, it’s about 66 seconds and if n = 5, it’s about 115 seconds. You can try changing “n”’s value to find out which it’s value is suitable for your sketch :)
Sorry for any inconvenience because of my bad English!
Thanks & Best Regards,
LuatNT