Arduino CC3000 Wifi lagging

Hi all! So I have used a 3V and 5V circuit, I also went from 8Mhz Arduino to 16Mhz Arduino all with the same result. After a few connections, the system seems to stop working for about 20-30 seconds, and then I can post data again. Maybe there is something in my code stopping the CC3000 from working properly? I upgraded the firmware as well to make sure I am up to date.

I have an XBee receiving packets, then posting the packets online to Dweet.io.

#include <Adafruit_CC3000.h>
#include <SPI.h>
#include <XBee.h>
#include <SoftwareSerial.h>

XBee xbee = XBee();
XBeeResponse response = XBeeResponse();

ZBRxResponse rx = ZBRxResponse();
ModemStatusResponse msr = ModemStatusResponse();


#define ADAFRUIT_CC3000_IRQ   3
#define ADAFRUIT_CC3000_VBAT  5
#define ADAFRUIT_CC3000_CS    10

Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, 
ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT, SPI_CLOCK_DIV2);
                                         
#define WLAN_SSID       "SSID"
#define WLAN_PASS       ""
#define WLAN_SECURITY   WLAN_SEC_WPA2
#define thing_name  "SomeName"

char pay0;
char pay1;
uint32_t ip;


void setup(void)
{
  Serial.begin(9600);
  xbee.setSerial(Serial);

  if (!cc3000.begin())
  {
    while(1);
  }
  cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY);
  while (!cc3000.checkDHCP())
  {
    delay(100);
  }  
}

void loop(void)
{ 
  readXbee();
  delay(500);
  sendDweet();  
}

void sendDweet(){
  uint32_t ip = 0;
  while  (ip  ==  0)  {
    if  (!  cc3000.getHostByName("www.dweet.io", &ip))  {
         }
    delay(500);
  }  
  
  cc3000.printIPdotsRev(ip);  
  if(!cc3000.checkConnected()){while(1){}}
   
  Adafruit_CC3000_Client client = cc3000.connectTCP(ip, 80);
  if (client.connected()) {
       
    client.fastrprint(F("GET /dweet/for/"));
    client.print(thing_name);
    client.fastrprint(F("?LowHex="));
    client.print(rx.getRemoteAddress64().getMsb(), HEX);
    client.fastrprint(F("&HighHex="));
    client.print(rx.getRemoteAddress64().getLsb(), HEX);
    client.fastrprint(F("&Pay0="));
    client.print(pay0);
    client.fastrprint(F("&Pay1="));
    client.print(pay1);
    client.fastrprintln(F(" HTTP/1.1"));
    
    client.fastrprintln(F("Host: dweet.io"));
    client.fastrprintln(F("Connection: close"));
    client.fastrprintln(F(""));
  
  } else {   
    return;
  } 
}

void readXbee(){
 
  xbee.readPacket();
    
    if (xbee.getResponse().isAvailable()) {
               
      if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) {
             
        xbee.getResponse().getZBRxResponse(rx);
                             
         for (int i = 0; i < rx.getDataLength(); i++) {
         
          if (i == 0){
            pay0 = rx.getData()[i];
          }
          
          if (i == 1){            
            pay1 = rx.getData()[i];
         }
       }
      }
    }
   }

If this was my project I would add some Serial.print() statements so I could see where it's at when it gets stuck.

Why have you a delay between readXbee() and sendDweet() ?

Does the call to cc3000.getHostByName() fail some of the time ?

Your code does not seem to allow for the possibility of a valid readXbee() followed by a failed sendDweet. Neither does it seem to allow for a failed readXbee().

...R

Originally I had all the checks in serial.print format that the template code suggests and you are right. Most if not all the hangups were on getHostByName.

This is a real Beta build, I will add all the if/then case type scenario's later. In a perfect world there are no fail reads :wink: haha

brolly759:
Most if not all the hangups were on getHostByName.

I think you need to allow for web access to be very unpredictable.

...R

The problem is, while in this "unpredictable" state, I lose packets if they start coming in from xBee.

brolly759:
The problem is, while in this "unpredictable" state, I lose packets if they start coming in from xBee.

If the fault is somewhere in "the cloud" there is not much you can do about it.

Maybe you could store the packets and send them a little later - but you can't store much on an Arduino.

...R