Skip to content

Commit 5847a03

Browse files
committed
Merge pull request adafruit#77 from bergcloud/master
Checked that the existing examples don't fail, and was able to verify the smart config create example works as expected (first time I could see this example work with my hardware, nice!). Integrating this change--thanks!
2 parents 6937856 + 0415693 commit 5847a03

File tree

5 files changed

+35
-19
lines changed

5 files changed

+35
-19
lines changed

Adafruit_CC3000.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,7 @@ class CC3000BitSet {
141141
}cc3000Bitset;
142142

143143
volatile long ulSocket;
144-
145-
char _deviceName[] = "CC3000";
146144
char _cc3000_prefix[] = { 'T', 'T', 'T' };
147-
const unsigned char _smartConfigKey[] = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
148-
0x38, 0x39, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35 };
149-
// AES key for smart config = "0123456789012345"
150-
151145
Print* CC3KPrinter; // user specified output stream for general messages and debug
152146

153147
/* *********************************************************************** */
@@ -245,7 +239,7 @@ Adafruit_CC3000::Adafruit_CC3000(uint8_t csPin, uint8_t irqPin, uint8_t vbatPin,
245239
clean connection
246240
*/
247241
/**************************************************************************/
248-
bool Adafruit_CC3000::begin(uint8_t patchReq, bool useSmartConfigData)
242+
bool Adafruit_CC3000::begin(uint8_t patchReq, bool useSmartConfigData, const char *_deviceName)
249243
{
250244
if (_initialised) return true;
251245

@@ -312,7 +306,7 @@ bool Adafruit_CC3000::begin(uint8_t patchReq, bool useSmartConfigData)
312306

313307
_initialised = true;
314308

315-
// Wait for re-connection is we're using SmartConfig data
309+
// Wait for re-connection if we're using SmartConfig data
316310
if (useSmartConfigData)
317311
{
318312
// Wait for a connection
@@ -754,8 +748,9 @@ uint8_t Adafruit_CC3000::getNextSSID(uint8_t *rssi, uint8_t *secMode, char *ssid
754748
*/
755749
/**************************************************************************/
756750
#ifndef CC3000_TINY_DRIVER
757-
bool Adafruit_CC3000::startSmartConfig(bool enableAES)
751+
bool Adafruit_CC3000::startSmartConfig(const char *_deviceName, const char *smartConfigKey)
758752
{
753+
bool enableAES = smartConfigKey != NULL;
759754
cc3000Bitset.clear();
760755

761756
uint32_t timeout = 0;
@@ -791,18 +786,20 @@ bool Adafruit_CC3000::startSmartConfig(bool enableAES)
791786
CHECK_SUCCESS(nvmem_create_entry(NVMEM_AES128_KEY_FILEID,16),
792787
"Failed create NVMEM entry", false);
793788

794-
// write AES key to NVMEM
795-
CHECK_SUCCESS(aes_write_key((unsigned char *)(&_smartConfigKey[0])),
796-
"Failed writing AES key", false);
797-
789+
if (enableAES)
790+
{
791+
// write AES key to NVMEM
792+
CHECK_SUCCESS(aes_write_key((unsigned char *)(smartConfigKey)),
793+
"Failed writing AES key", false);
794+
}
798795
//CC3KPrinter->println("Set prefix");
799796
// Wait until CC3000 is disconnected
800797
CHECK_SUCCESS(wlan_smart_config_set_prefix((char *)&_cc3000_prefix),
801798
"Failed setting the SmartConfig prefix", false);
802799

803800
//CC3KPrinter->println("Start config");
804801
// Start the SmartConfig start process
805-
CHECK_SUCCESS(wlan_smart_config_start(0),
802+
CHECK_SUCCESS(wlan_smart_config_start(enableAES),
806803
"Failed starting smart config", false);
807804

808805
// Wait for smart config process complete (event in CC3000_UsynchCallback)

Adafruit_CC3000.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class Adafruit_CC3000_Client : public Print {
116116
class Adafruit_CC3000 {
117117
public:
118118
Adafruit_CC3000(uint8_t csPin, uint8_t irqPin, uint8_t vbatPin, uint8_t spispeed = SPI_CLOCK_DIVIDER);
119-
bool begin(uint8_t patchReq = 0, bool useSmartConfigData = false);
119+
bool begin(uint8_t patchReq = 0, bool useSmartConfigData = false, const char *_deviceName = NULL);
120120
void reboot(uint8_t patchReq = 0);
121121
void stop(void);
122122
bool disconnect(void);
@@ -149,7 +149,7 @@ class Adafruit_CC3000 {
149149
uint8_t getNextSSID(uint8_t *rssi, uint8_t *secMode, char *ssidname);
150150

151151
bool listSSIDResults(void);
152-
bool startSmartConfig(bool enableAES);
152+
bool startSmartConfig(const char *_deviceName = NULL, const char *smartConfigKey = NULL);
153153

154154
bool getIPConfig(tNetappIpconfigRetArgs *ipConfig);
155155

examples/SmartConfigCreate/SmartConfigCreate.ino

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
#define ADAFRUIT_CC3000_VBAT 5
5151
#define ADAFRUIT_CC3000_CS 10
5252

53+
#define DEVICE_NAME "CC3000"
54+
5355
// Use hardware SPI for the remaining pins
5456
// On an UNO, SCK = 13, MISO = 12, and MOSI = 11
5557
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS,
@@ -92,7 +94,7 @@ void setup(void)
9294
/* Try to use the smart config app (no AES encryption), saving */
9395
/* the connection details if we succeed */
9496
Serial.println(F("Waiting for a SmartConfig connection (~60s) ..."));
95-
if (!cc3000.startSmartConfig(false))
97+
if (!cc3000.startSmartConfig(DEVICE_NAME))
9698
{
9799
Serial.println(F("SmartConfig failed"));
98100
while(1);
@@ -113,7 +115,7 @@ void setup(void)
113115
}
114116

115117
Serial.println(F("\nTo use these connection details be sure to use"));
116-
Serial.println(F("'.begin(false, true)' with your Adafruit_CC3000"));
118+
Serial.println(F("'.begin(false, true, DEVICE_NAME)' with your Adafruit_CC3000"));
117119
Serial.println(F("code instead of the default '.begin()' values!"));
118120

119121
/* You need to make sure to clean up after yourself or the CC3000 can freak out */

examples/SmartConfigReconnect/SmartConfigReconnect.ino

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
#define ADAFRUIT_CC3000_VBAT 5
5454
#define ADAFRUIT_CC3000_CS 10
5555

56+
#define DEVICE_NAME "CC3000"
57+
5658
// Use hardware SPI for the remaining pins
5759
// On an UNO, SCK = 13, MISO = 12, and MOSI = 11
5860
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS,
@@ -83,7 +85,7 @@ void setup(void)
8385
/* !!! app NOT to deleted previously stored connection details !!! */
8486
/* !!! and reconnected using the connection details in memory! !!! */
8587
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
86-
if (!cc3000.begin(false, true))
88+
if (!cc3000.begin(false, true, DEVICE_NAME))
8789
{
8890
Serial.println(F("Unable to re-connect!? Did you run the SmartConfigCreate"));
8991
Serial.println(F("sketch to store your connection details?"));

utility/socket.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define SEND_TIMEOUT_MS (30 * 1000)
2+
13
/*****************************************************************************
24
*
35
* socket.c - CC3000 Host Driver Implementation.
@@ -123,6 +125,11 @@ HostFlowControlConsumeBuff(int sd)
123125
{
124126
#ifndef SEND_NON_BLOCKING
125127
/* wait in busy loop */
128+
129+
#ifdef SEND_TIMEOUT_MS
130+
unsigned long startTime = millis();
131+
#endif
132+
126133
do
127134
{
128135
// In case last transmission failed then we will return the last failure
@@ -137,6 +144,14 @@ HostFlowControlConsumeBuff(int sd)
137144

138145
if(SOCKET_STATUS_ACTIVE != get_socket_active_status(sd))
139146
return -1;
147+
148+
#ifdef SEND_TIMEOUT_MS
149+
if ((millis() - startTime) > SEND_TIMEOUT_MS)
150+
{
151+
return -3; /* Timeout */
152+
}
153+
#endif
154+
140155
} while(0 == tSLInformation.usNumberOfFreeBuffers);
141156

142157
tSLInformation.usNumberOfFreeBuffers--;

0 commit comments

Comments
 (0)