I have a couple of projects using the CC3000 and Arduino Micros. I'm using the Adafruit CC3000 library. The loop() function has code to detect and recover from a disconnect, which works properly. From time to time the code hangs somewhere in the CC3000 library, but that's effectively dealt with by using a watchdog timer. A more insidious problem is that the program appears to be operating properly, but the CC3000 becomes non-responsive - my router shows it as unreachable, as does a CLI ping from my laptop. I suspect a firmware problem, where the library function to check connectivity reports all is well, but in fact it is not. The library function looks for HCI_EVNT_WLAN_UNSOL_CONNECT and HCI_EVNT_WLAN_UNSOL_DISCONNECT events, no special logic. It appears the CC3000 fails to report a disconnect or other problem to the application. I'm running firmware v1.14. Here's the code:
/*************************************************** * SMS Alarm * * Send an SMS text message when various alarm conditions * ae sensed, including opening the door of my mailbox and * detecting water on the basement floor with a pair of * contacts placed just above the floor connected to an * analog input pin and ground. The input pin is pulled up * with a high value resistor (~470K) to +5V. * Uses Amazon's SNS to generate and send SMS notifications. * * Dependencies: * - Adafruit CC3000 Library * github.com/.../Adafruit_CC3000_Library * - RTClib Library * github.com/.../RTClib * * License: * * This example is copyright (c) 2014 Barry Rutkin (barry.rutkin@verizon.net) * and is released under an open source MIT license. See details at: * opensource.org/.../MIT ---- * * This code was adapted from Adafruit CC3000 library example * code which has the following license: * * Designed specifically to work with the Adafruit WiFi products: * ----> www.adafruit.com/.../1469 * * Adafruit invests time and resources providing this open source code, * please support Adafruit and open-source hardware by purchasing * products from Adafruit! * * Written by Limor Fried & Kevin Townsend for Adafruit Industries. * BSD license, all text above must be included in any redistribution * * SHA1 hash and signing code adapted from Peter Knight's library * available at github.com/.../Cryptosuite ****************************************************/ //#define DEBUG // Print everything #include <Adafruit_CC3000.h> #include <ccspi.h> #include <SPI.h> #include <Wire.h> #include <RTClib.h> #include "sha1.h" #include <avr/wdt.h> // for watchdog timer // CC3000 configuration #define ADAFRUIT_CC3000_IRQ 3 // MUST be an interrupt pin! #define ADAFRUIT_CC3000_VBAT 5 // VBAT and CS can be any two pins #define ADAFRUIT_CC3000_CS 10 // Use hardware SPI for the remaining pins // On an UNO, SCK = 13, MISO = 12, and MOSI = 11 Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT, SPI_CLOCK_DIV2); // Wireless network configuration #define WLAN_SSID "MyNetwork" // cannot be longer than 32 characters! #define WLAN_PASS "myPassword" #define WLAN_SECURITY WLAN_SEC_WPA2 // Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2 #define WLAN_ATTEMPTS 3 // Number of times CC3000 wlll attempt to connect to WLAN // Amazon AWS configuration #define AWS_ACCESS_KEY "myAWSkey" // Put your AWS access key here. #define AWS_SECRET_ACCESS_KEY "mySecretAWSaccesKey" // Put your AWS secret access key here. #define AWS_REGION "us-east-1" // The region where your SNS topic lives. // See the table at: docs.aws.amazon.com/.../rande.html #define AWS_HOST "sns.us-east-1.amazonaws.com" // The host URL for the region where your SNS topic lives. // See the table at: docs.aws.amazon.com/.../rande.html // Amazon resource name (ARN) for the SNS topic to receive notifications. // Note: This ARN _MUST_ be URL encoded! See meyerweb.com/.../dencoder for an example URL encoder tool. #define SNS_TOPIC_ARN "the SNS topic unique resource id goes here" #define testPin 2 // Ground for normal operation, leave open for test mode #define mailbxPin 8 // Digital pin that is hooked up to the tilt switch. (N.O.) #define wetPin A1 // Analog pin that is hooked up to the water detector // pulled up to +5V through a 470K resistor // WLAN Status lamps #define redLED 12 // CC3000 not initialized (red) #define yellowLED 11 // Trying to connect to WLAN (yellow) #define greenLED 9 // WLAN connected (green) Breathes when connected and alive #define boardLED 13 // Got NTP time (on-board LED) #define testLED 6 // Testing and debugging LED #define WET_THRESH 768 // analog water detection value - about 3.75 volts, 1.4M #define SWITCH_CHECK_SECONDS 1 // How long to wait (in seconds) between switch state checks. #define PUBLISH_LIMIT_SECONDS 8UL * 3600 // How long to wait (in seconds) between mailbox publish calls (8 hrs) #define WET_PUBLISH_LIMIT_SECONDS 12UL * 3600 // How long to wait (in seconds) between flood alarm publish calls (12 hrs) #define TIMEOUT_MS 15000 // How long to wait (in milliseconds) for a server connection to respond (for both AWS and NTP calls). // How many n-second iterations of loop() needed to get desired NTP query interval #define LOOP_COUNT 4UL * 3600 / SWITCH_CHECK_SECONDS - 1 // 4 hours // The configuration below should not be changed. #define SHA1_HASH_LENGTH 20 unsigned long lastPolledTime = 0; // Last value retrieved from time server. unsigned long sketchTime = 0; // CPU milliseconds since last time server query. unsigned long lastSNSPublish = 0; // The last time an SNS message was published. unsigned long lastWetPublish = 0; // The last time an water alarm message was published unsigned long t = 0; unsigned long countdown = 0; unsigned long SwCheckTime = millis(); bool greenFlag; volatile int counter; // Count number of times ISR is called. #define countmax 7 // yields 56 second WDT timeout. // Timer expires after about 56 secs if // 8 sec interval is selected below. void setup(void) { pinMode(testPin, INPUT_PULLUP); // if open, no messages are generated, just blinks testLED pinMode(mailbxPin, INPUT_PULLUP); // LOW on this pin triggers mailbox message generation // WLAN status LEDs pinMode(redLED, OUTPUT); // CC3000 not initialized pinMode(yellowLED, OUTPUT); // Attempting to connect to WLAN pinMode(greenLED, OUTPUT); // Connected to WLAN. Also doubles as proof-of-life pinMode(boardLED, OUTPUT); // Got NTP time pinMode(testLED, OUTPUT); // Debugging and test LED #ifdef DEBUG // Set up the serial port connection. Serial.begin(115200); delay(5000); // Some time to get the monitor up Serial.println(F("SMS Alarm v1.1")); #endif