Head scratching CC3000 hang-up issues.

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
lax_ste
 
Posts: 17
Joined: Thu Oct 25, 2012 12:32 pm

Head scratching CC3000 hang-up issues.

Post by lax_ste »

I originally posted this in the "Other Adafruit products" forum but realized that this is probably a better location to ask this question:

I have a bit of a puzzle brewing with the (awesome) Adafruit CC3000 breakout board. I was originally working with it paired with an Arduino UNO while trying to get the Xively http://learn.adafruit.com/adafruit-cc30 ... and-xively example up, running and stable. I had no compile issues and everything started off working well. I rather quickly found that shortly, but not as predictably soon, as the serial (via USB) is disconnected the Arduino seems to hang/freeze.

I was reading what I could find that seemed on topic, hoping not to have to trouble anyone else with my problem, and thought that perhaps I was running out of SRAM. Believing that may be the problem, I swapped out the Arduino UNO with a PJRC Teensy 3. There are two reasons I did this, one being the capabilities of the Teensy 3 (faster, larger flash program size, more interrupts etc) the other is the roughly 6.5 times SRAM available. Unfortunately the problem persists: It will run well indefinitely (hours at least) while connected to USB/serial; if it is separately powered, when the USB is disconnected, it will continue to put sensor readings to Xively for anywhere from 10 mins to 2 hours; if started straight from external power it will run for between 5 mins and an hour.

With the Teensy 3, the compile output is:

Binary sketch size: 28,388 bytes (of a 131,072 byte maximum)
Estimated memory use: 3,944 bytes (of a 16,384 byte maximum)

With an UNO, the output is:

Binary sketch size: 24,072 bytes (of a 32,256 byte maximum)

There's a good chance I've got something messed up somewhere although I've followed the example exactly as presented in the tutorial (coincidentally I'm looking to monitor temperature and humidity along with a number of other things, but I started with the example as is; all I've changed in the main code is the WLAN_SSID, WLAN_PASS, API_KEY & feedID). To get the DHT11 working with the TEENSY 3 I had to modify a delay in DHT.cpp as suggested and verified on the PJRC forum. This involved changing line ~120 from delayMicroseconds(1) to delayMicroseconds(4). http://forum.pjrc.com/threads/16806-T3- ... 0no%20time.

I realize this question is sort of wordy and long-winded; just wanted to make sure I put in all the pertinent details.

Many thanks in advance!

Please let me know if there is any other info I can provide that could help resolve this problem.

<edit>

I have now seen it hang while connected to USB / Serial with a monitor window open here's the output (I've removed the SSID, API Key, the Feed ID and the Request ID; I can add them but I don't think they are causing the problem as it does work some of the time):

(Normal serial returns are before this)
Started AP/SSID scan


Connecting to (SSID removed)...Waiting to connect...Connected!
Request DHCP
api.xively.com -> 216.52.233.120Data length128

PUT /v2/feeds/(Feed removed).json HTTP/1.0
Host: api.xively.com
X-ApiKey: (API Key removed)
Content-Length: 128
Connection: close

{"version":"1.0.0","datastreams" : [ {"id" : "Temperature","current_value" : "64"},{"id" : "Humidity","current_value" : "35"}]}


Connect to 216.52.233.120:80
Connected!
-------------------------------------
HTTP/1.1 200 OK
Date: Tue, 26 Nov 2013 03:32:02 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 0
Connection: close
X-Request-Id: (ID Removed)
Cache-Control: max-age=0
Vary: Accept-Encoding

-------------------------------------


Disconnecting
Started AP/SSID scan


Connecting to Brackass...Waiting to connect...Connected!
Request DHCP
api.xively.com -> Couldn't resolve!
Couldn't resolve!
Couldn't resolve!
Couldn't resolve!
Couldn't resolve!
Couldn't resolve!
Couldn't resolve!
Couldn't resolve!
Couldn't resolve!
(and this continues endlessly)
I hope this is not something to do with the CC3000 as I really like it so far (except for the obvious) and have 2 more shipping to me this week.

</edit>



lax.ste

User avatar
Franklin97355
 
Posts: 23910
Joined: Mon Apr 21, 2008 2:33 pm

Re: Head scratching CC3000 hang-up issues.

Post by Franklin97355 »

api.xively.com -> Couldn't resolve!
Looks like your DNS can't resolve the link to xively. You might try finding and putting in the IP address.

User avatar
lax_ste
 
Posts: 17
Joined: Thu Oct 25, 2012 12:32 pm

Re: Head scratching CC3000 hang-up issues.

Post by lax_ste »

Hi franklin,

Thank you for the feedback; I've noticed that this is where it hangs up, but the previous "cycle" of the loop it worked just fine:
Started AP/SSID scan


Connecting to (SSID removed)...Waiting to connect...Connected!
Request DHCP
api.xively.com -> 216.52.233.120Data length128

PUT /v2/feeds/(Feed removed).json HTTP/1.0
Host: api.xively.com
X-ApiKey: (API Key removed)
Content-Length: 128
Connection: close

{"version":"1.0.0","datastreams" : [ {"id" : "Temperature","current_value" : "64"},{"id" : "Humidity","current_value" : "35"}]}


Connect to 216.52.233.120:80
Connected!
-------------------------------------
HTTP/1.1 200 OK
Date: Tue, 26 Nov 2013 03:32:02 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 0
Connection: close
X-Request-Id: (ID Removed)
Cache-Control: max-age=0
Vary: Accept-Encoding

-------------------------------------


Disconnecting
then it tried the exact same thing and output this:
Started AP/SSID scan


Connecting to SSID...Waiting to connect...Connected!
Request DHCP
api.xively.com -> Couldn't resolve!
Couldn't resolve!
Couldn't resolve!
Couldn't resolve!
Couldn't resolve!
Couldn't resolve!
Couldn't resolve!
Couldn't resolve!
Couldn't resolve!
(and this continues endlessly)
Perhaps I'm assuming a bit more than I should, but I would have though that if there was a failure of part of the loop or function (ie resolving the ip) it should post the error, finish the loop and then start over at the beginning. I guess I'll have a look at the libraries to see if there's a way to add a time-out for certain (perhaps problem) areas of the functions.

I will try and track this down but in the meantime I'm open to any and all suggestion to get this to work reliably; the final project I'm working towards need to be able to run 24/7 without supervision or human oversight for multiple days and possibly weeks. I cannot risk code that fails in a fault condition (I would rather have it, in this particular case, run such that if there's an issue with some of the CC3000 i/o or network connections the loop and the rest of the "program" will continue to run without human intervention)

One of my other thoughts was to use a Trinket with a latching MOSFET to act as a watchdog and determine if it's been too long waiting for the network i/o to complete and have that trigger a reset of the Arduino (or Teensy 3).

Thanks Again!

lax.ste

User avatar
djix123
 
Posts: 28
Joined: Mon Aug 26, 2013 7:58 pm

Re: Head scratching CC3000 hang-up issues.

Post by djix123 »

Hi

I've been having very similar problems with the same Xively / CC3000 example / tutorial.

I think I've largely managed to 'solve' the problem via somewhat of a brute force approach by (i) dynamically creating the Adafruit_CC3300 class, then destroying / re-instantiating the class after a number of loop iterations (I settled on 10 loops); and (ii) by wrapping every method call on the Adafruit_CC3300 with a watchdog timeout.

Doing this has allowed me to keep the Xively example running for days without any hang-ups.

I patched the Adafruit_CC3300 class as follows:

Code: Select all

diff --git a/Adafruit_CC3000.cpp b/Adafruit_CC3000.cpp
index e652d14..861c83f 100644
--- a/Adafruit_CC3000.cpp
+++ b/Adafruit_CC3000.cpp
@@ -23,6 +23,8 @@
 #include "Adafruit_CC3000.h"
 #include "ccspi.h"
 
+#include <avr/wdt.h>
+
 #include "utility/cc3000_common.h"
 #include "utility/evnt_handler.h"
 #include "utility/hci.h"
@@ -1006,10 +1008,16 @@ bool Adafruit_CC3000::connectToAP(const char *ssid, const char *key, uint8_t sec
     /* MEME: not sure why this is absolutely required but the cc3k freaks
        if you dont. maybe bootup delay? */
     // Setup a 4 second SSID scan
+    wdt_enable(WDTO_8S);
     scanSSIDs(4000);
+    wdt_disable();
+      
     // Wait for results
     delay(4500);
+    
+    wdt_enable(WDTO_8S);
     scanSSIDs(0);
+    wdt_disable();
     
     /* Attempt to connect to an access point */
     if (CC3KPrinter != 0) {
-- 
1.7.11.1
since the ConnectToAP() method has a long delay in it.

For other method calls I just wrapped the call with the watchdog timer in my own code.

My guess is that by wrapping the calls with the watchdog timer there is no advantage to dynamically creating the Adafruit_CC3300 class, but I did that first and haven't reverted my code to confirm.

Regards
djix123

User avatar
lax_ste
 
Posts: 17
Joined: Thu Oct 25, 2012 12:32 pm

Re: Head scratching CC3000 hang-up issues.

Post by lax_ste »

Thanks djix123,

If there any chance you could post your code / modifications in whole (libraries, if you've changed them, and you main routine) so that I can try to replicate your stability with this board. Since I've been working with it the reliability has been all over the map; sometimes it'll work for 12 hrs or longer but usually less than 30 mins.

It would be much appreciated.

Thank you again!

Lax.ste

User avatar
djix123
 
Posts: 28
Joined: Mon Aug 26, 2013 7:58 pm

Re: Head scratching CC3000 hang-up issues.

Post by djix123 »

Hi

I won't post my full code as I've modified the example quite a bit - in particular I've made the loop() function more readable by creating separate functions for each stage. That said, hopefully what follows should be enough:

In the Arduino sketch I add the include for the watchdog timer at the beginning:

Code: Select all

#include <avr/wdt.h>
change the Adafruit_CC3300 class declaration (as below) and add a reset counter:

Code: Select all

Adafruit_CC3000 *cc3000 = 0;
int dhcpResetCount = 0;
I then declare separate functions for connecting and disconnecting to the wifi access point (in my code there are also functions for reading the temperature, formatting the Xively string etc ... - but essentially they are the same as the Xively original code factored into separate functions).

Code: Select all

void connectToWifi(void) {
  cc3000 = new Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT, SPI_CLOCK_DIV2);

  wdt_enable(WDTO_8S);
  if (!cc3000->begin())
  {
    Serial.println(F("Couldn't begin()! Check your wiring?"));
    while(1);
  }
  wdt_disable();
  
  // Connect to WiFi network
  cc3000->connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY);
  Serial.println(F("Connected!"));
  
  /* Wait for DHCP to complete */
  wdt_enable(WDTO_8S);
  Serial.println(F("Request DHCP"));
  while (!cc3000->checkDHCP())
  {
    delay(100);
  }
  wdt_disable();
}

void disconnectFromWifi(void) {
  Serial.println(F("\n\nDisconnecting"));
  
  wdt_enable(WDTO_8S);  
  cc3000->disconnect();
  cc3000->stop();
  wdt_disable();
  
  delete cc3000;
  
  delay(5000);
}
then in the main loop() function:

Code: Select all

void loop() {

  /* .... */

  if(dhcpResetCount == 0) {
    Serial.println(F("Connecting to Wifi ..."));
    connectToWifi();
    getWebsiteAddress();
  }

  /* Do temperature reading, send to Xively etc ... */

  if(dhcpResetCount == 10) {
    Serial.println(F("Disconnecting from Wifi ..."));
    disconnectFromWifi();
    dhcpResetCount = 0;
  }

  /* .... */
All my other calls to cc3300 methods are wrapped in watchdog timer calls (as per the connect / disconnect functions above).

The only change to the CC3300 library I made I posted above. Open the Adafruit_CC3300.cpp file, add the watchdog timer include at the beginning, and then search for the connectToAP() method and wrap the two calls to scanSSIDs with watchdog timer calls.

Hope this helps
djix123

User avatar
lax_ste
 
Posts: 17
Joined: Thu Oct 25, 2012 12:32 pm

Re: Head scratching CC3000 hang-up issues.

Post by lax_ste »

Thank you, I'll take a run at it in the next day or so and let you know how it turned out.

User avatar
pkourany
 
Posts: 51
Joined: Wed Nov 27, 2013 12:57 pm

Re: Head scratching CC3000 hang-up issues.

Post by pkourany »

Folks,

This is exactly the same problem I posted about (CC3000 ip lookup issue (getHostbyName)) in this forum. On my UNO/CC3000 test, I ended up getting the same results - the first lookup is good then all subsequent lookups can't resolve (or return the same IP but it should be different).

This suggests a bug in the library or a problem with the CC3000 firmware. I like how you get around the problem by destroying and then re--instantiating the CC3000 class but this seems more of a kludge then a fix.

I am trying to bring up this issue with TI or Adafruit if possible but I don't know how common it is since no-one is responding to my post.

User avatar
djix123
 
Posts: 28
Joined: Mon Aug 26, 2013 7:58 pm

Re: Head scratching CC3000 hang-up issues.

Post by djix123 »

Agreed, not a very elegant way of solving the problem - at some point I'll try and get to the bottom of it properly.

There has been some updates to the CC3000 Adafruit library in the last couple of days, so together with the latest firmware I wonder if that improves the behavior.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Head scratching CC3000 hang-up issues.

Post by adafruit_support_mike »

Never shy away from ugly solutions that work. ;-)

It's almost always easier to make a working system elegant than it is to make an elegant idea work.

User avatar
pkourany
 
Posts: 51
Joined: Wed Nov 27, 2013 12:57 pm

Re: Head scratching CC3000 hang-up issues.

Post by pkourany »

I reflashed my Adafruit CC3000 with the latest firmware 1.24 (which it already had) and I tried SendTweet with the latest Adafruit libraries (downloaded moments ago from github) and I get the same problem:

OK
Connecting to network...Started AP/SSID scan

Connecting to dlink123...Waiting to connect...OK
Requesting address from DHCP server...OK
IP Addr: 192.168.0.199
Netmask: 255.255.255.0
Gateway: 192.168.0.1
DHCPsrv: 192.168.0.1
DNSserv: 192.168.0.1
Locating time server...found
Connecting to time server...
Connect to 24.215.0.24:123
connected!
Issuing request...OK
Awaiting response...success!
Locating Twitter server...OK
Connecting to server...

Connect to 24.215.0.24:80
OK
Issuing HTTP request...OK
Awaiting response...error (invalid Twitter credentials?)
Waiting ~1 hour...


Notice the lookup for the time server works at port 123 but the second lookup returns the same IP which the sketch then accesses at port 80, which of course will fail. Argh!!!

User avatar
pburgess
 
Posts: 4161
Joined: Sun Oct 26, 2008 2:29 am

Re: Head scratching CC3000 hang-up issues.

Post by pburgess »

Tested here. I'm getting different addresses for the time and Twitter servers.

What make/model of access point are you using? Hoping to establish a pattern to more easily debug this. Any chance you could hop on a friend's WiFi or something, see if there's any change?

User avatar
pkourany
 
Posts: 51
Joined: Wed Nov 27, 2013 12:57 pm

Re: Head scratching CC3000 hang-up issues.

Post by pkourany »

The tests were done with using a DLINK DIR-655 router. I played with several settings with no changes. After your suggestion I used my Android's WiFi tethering feature and, as I feared, it worked!

So the question is, why does it NOT work with the DIR-655? If I do nslookups on Windows, they work just fine.

User avatar
lax_ste
 
Posts: 17
Joined: Thu Oct 25, 2012 12:32 pm

Re: Head scratching CC3000 hang-up issues.

Post by lax_ste »

Ok, now this is getting really strange because I was having all of my problems connecting to a generic router from Verizon (I was housitting for friends) an when I got home yesterday and had it connecting to my DIR-655 and it worked fine, first attempt. It will still occasionally fail on the first attempt to do a DNS lookup but never hangs.

User avatar
pkourany
 
Posts: 51
Joined: Wed Nov 27, 2013 12:57 pm

Re: Head scratching CC3000 hang-up issues.

Post by pkourany »

Any chance you can post your DIR-655 settings (screenshots?)? I have hardware version A2 and firmware version 1.37NA.

Thanks!

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Arduino products from Adafruit”