CC3000 Breakout: XIVELY Stop Works randomly? SOLVED!

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.
Locked
PierlugiRovere
 
Posts: 15
Joined: Tue Jul 08, 2014 8:40 am

CC3000 Breakout: XIVELY Stop Works randomly? SOLVED!

Post by PierlugiRovere »

In a fuction (that i call it every 2 minutes), i make a connection to Xively server with this command:

Code: Select all

CC3000Client = cc3000.connectTCP(cc3000.IP2U32(216,52,233,120), 80);
After, i send the data thru this line

Code: Select all

CC3000Client.println("blablabla");
and i close the connection with

Code: Select all

CC3000Client.close();
should i use

Code: Select all

cc3000.disconnect()
after (on the bottom of my function) or isn't necessary?

Now i don't disconnect the CC3000, but sometimes (after 15 min, or 1 or 3 or 8 hours randomly) Arduino freezes.
Last edited by PierlugiRovere on Sun Jul 27, 2014 1:59 pm, edited 3 times in total.

PierlugiRovere
 
Posts: 15
Joined: Tue Jul 08, 2014 8:40 am

Re: CC3000 Breakout: Best practices?

Post by PierlugiRovere »

I'm using Arduino Uno, CC3000 breakout board (v 1.28) e some sensors (dth11, MQ-7 Carbon Monoxide, and i receive now the BMP180).
My sketch is quite simple: wait for 2 minutes, read sensors, put them into my Xively Account.

The functión for sending data is:

Code: Select all

ReturnType SendDataToXively()
{
    DHTData DTHDataSend = GetDataFromDHT11();
    MQ7Data MQ7DataSend = GetDataFromMQ7();
    //Serial.print(F("QUALITA' DATI:"));
    //Serial.print(DTHDataSend.blnGoodData);
    //Serial.println(MQ7DataSend.blnGoodData);
    if (DTHDataSend.blnGoodData && MQ7DataSend.blnGoodData)
    {
      if (!cc3000.checkConnected())
        cc3000.connectToAP("FloRoBaWifi", "R0ver3B4ud1n0", WLAN_SEC_WPA2); 
      //Serial.println(F("CONNESSO A WIFI"));
      int intCount=0;
      //Serial.println(F("WIFI Connected!"));
      while (!cc3000.checkDHCP() && !(intCount>40))
      {
        delay(1000);  
        intCount++;    
      } 
      if (intCount>=40)
        return NoResponseFromDHCP;  
      //Serial.println(F("INDIRIZZO DHCP ACQUISITO"));       
      String data = "";
      data = data + "\n" + "{\"version\":\"1.0.0\",\"datastreams\" : [ {\"id\" : \"Kitchen-Temperature\",\"current_value\" : \"" + String(DTHDataSend.intTemp) + "\"},{\"id\" : \"Kitchen-Humidity\",\"current_value\" : \"" + String(DTHDataSend.intHum) + "\"},{\"id\" : \"Kitchen-CarbonMonoxide\",\"current_value\" : \"" + String(MQ7DataSend.intCO) + "\"}]}";
      
      CC3000Client = cc3000.connectTCP(cc3000.IP2U32(216,52,233,120), 80);
     
      if (CC3000Client.connected())
      {   
        //Serial.println(F("CLIENT CONNESSO"));
        CC3000Client.println(F("PUT /v2/feeds/1257980085.json HTTP/1.0"));
        CC3000Client.println(F("Host: api.xively.com"));
        CC3000Client.println(F("X-ApiKey: MyAPI"));
        CC3000Client.println("Content-Length: " + String(data.length()));
        CC3000Client.print(F("Connection: close"));
        CC3000Client.println();
        CC3000Client.print(data);
        CC3000Client.println();
        intCount=0;
        
         // while (CC3000Client.connected())
         // {
          //  while (CC3000Client.available())
           // {
            //  char c = CC3000Client.read();
             // Serial.print(c);
           // }
          //}   
        //Serial.println(F("SCRITTURA TERMINATA"));  
        while (!CC3000Client.available() && intCount<60) //devo aspettare fino a quando non ho la risposta del server, altrimenti non funziona!
        {
          delay (1000); 
          //Serial.println(F("ASPETTO"));    
          intCount++;
        }
        //Serial.println(F("PAGINA RECUPERATA. OK"));
        if (intCount>=60) 
          return NoXivelyResponse;
        
        CC3000Client.close(); 
        
        lngLastTimeUpdatedXively = lngScanTime;
        //Serial.print(F("FREE RAM:"));
        //Serial.println(freeRam());
        return AllDone; 
      }
      else
        return NoResponseOfClient;
    }
    else
      return BadDataFromSensors;
}

I don't know why, but sometimes the program stuck on this line.

Code: Select all

 while (!CC3000Client.available() && intCount<60)
From that moment, the Arduino freezes.

i tried to check the amount of free ram at the end of the all instructions and, when the function works, i receive a feedback of 395 Kb (never change).

i can't find this issue :(
the string "data" is too long? i don't know.
is there a way to send data lighter that this?
help!
Last edited by PierlugiRovere on Sun Jul 27, 2014 1:59 pm, edited 1 time in total.

PierlugiRovere
 
Posts: 15
Joined: Tue Jul 08, 2014 8:40 am

Re: CC3000 Breakout: Best practices?

Post by PierlugiRovere »

All sketch is here:

Code: Select all

#include "FloRoba.h"
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include "DHT.h"



Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,SPI_CLOCK_DIV2);
Adafruit_CC3000_Client CC3000Client;

DHT dhtSensor(intPinDthSensor, DHT11);

//------------------------------------------------------------------------SETUP---------------------------------------------------------------------------------------------------------------------------------------
void setup(void)
{
  //Serial.begin(115200);   
  if (!cc3000.begin())
    while(1);
    
  if (!cc3000.deleteProfiles())
    while(1);

}

//------------------------------------------------------------------------LOOP---------------------------------------------------------------------------------------------------------------------------------------
void loop(void)
{
  lngScanTime = millis();
  
  if (lngScanTime-lngLastTimeUpdatedXively>lngNextTimeToUpdateXively)
  {
    //Serial.println(F("E' ora"));
    switch (SendDataToXively())
    {
     case BadDataFromSensors:
       //Serial.println(F("PESSIMA LETTURA SENSORI"));
       break;
     case AllDone:
       //Serial.println(F("TUTTO OK- SCRITTURA ESEGUITA CORRETTAMENTE"));
       break;  
     default:
       //Serial.println(F("USCITO PER TIMEOUT"));
       CC3000Client.close();     
       cc3000.disconnect();
       cc3000.deleteProfiles();     
       break;     
    }
  }
}

//------------------------------------------------------------------------INVIO DATI---------------------------------------------------------------------------------------------------------------------------------------
ReturnType SendDataToXively()
{
    DHTData DTHDataSend = GetDataFromDHT11();
    MQ7Data MQ7DataSend = GetDataFromMQ7();
    //Serial.print(F("QUALITA' DATI:"));
    //Serial.print(DTHDataSend.blnGoodData);
    //Serial.println(MQ7DataSend.blnGoodData);
    if (DTHDataSend.blnGoodData && MQ7DataSend.blnGoodData)
    {
      if (!cc3000.checkConnected())
        cc3000.connectToAP("FloRoBaWifi", "R0ver3B4ud1n0", WLAN_SEC_WPA2); 
      //Serial.println(F("CONNESSO A WIFI"));
      int intCount=0;
      //Serial.println(F("WIFI Connected!"));
      while (!cc3000.checkDHCP() && !(intCount>40))
      {
        delay(1000);  
        intCount++;    
      } 
      if (intCount>=40)
        return NoResponseFromDHCP;  
      //Serial.println(F("INDIRIZZO DHCP ACQUISITO"));       
      String data = "";
      data = data + "\n" + "{\"version\":\"1.0.0\",\"datastreams\" : [ {\"id\" : \"Kitchen-Temperature\",\"current_value\" : \"" + String(DTHDataSend.intTemp) + "\"},{\"id\" : \"Kitchen-Humidity\",\"current_value\" : \"" + String(DTHDataSend.intHum) + "\"},{\"id\" : \"Kitchen-CarbonMonoxide\",\"current_value\" : \"" + String(MQ7DataSend.intCO) + "\"}]}";
      
      CC3000Client = cc3000.connectTCP(cc3000.IP2U32(216,52,233,120), 80);
     
      if (CC3000Client.connected())
      {   
        //Serial.println(F("CLIENT CONNESSO"));
        CC3000Client.println(F("PUT /v2/feeds/1257980085.json HTTP/1.0"));
        CC3000Client.println(F("Host: api.xively.com"));
        CC3000Client.println(F("X-ApiKey: rlty6tMExNoVd42olSO4wskwBObJmLnRe7P1DRJXd2CJIule"));
        CC3000Client.println("Content-Length: " + String(data.length()));
        CC3000Client.print(F("Connection: close"));
        CC3000Client.println();
        CC3000Client.print(data);
        CC3000Client.println();
        intCount=0;
        
         // while (CC3000Client.connected())
         // {
          //  while (CC3000Client.available())
           // {
            //  char c = CC3000Client.read();
             // Serial.print(c);
           // }
          //}   
        //Serial.println(F("SCRITTURA TERMINATA"));  
        while (!CC3000Client.available() && intCount<60) //devo aspettare fino a quando non ho la risposta del server, altrimenti non funziona!
        {
          delay (1000); 
          //Serial.println(F("ASPETTO"));    
          intCount++;
        }
        //Serial.println(F("PAGINA RECUPERATA. OK"));
        if (intCount>=60) 
          return NoXivelyResponse;
        
        CC3000Client.close(); 
        
        lngLastTimeUpdatedXively = lngScanTime;
        //Serial.print(F("FREE RAM:"));
        //Serial.println(freeRam());
        return AllDone; 
      }
      else
        return NoResponseOfClient;
    }
    else
      return BadDataFromSensors;
}

//------------------------------------------------------------------------LETTURA DA SENSORE TEMPERATURA UMIDITA'---------------------------------------------------------------------------------------------------------------------------------------
DHTData GetDataFromDHT11()
{
  DHTData Result;
  
  Result.intTemp = dhtSensor.readTemperature();
  Result.intHum =  dhtSensor.readHumidity();
  
  if (isnan(Result.intTemp) || isnan(Result.intHum))
    Result.blnGoodData = false;
  else
    Result.blnGoodData = true;
    
  return Result;
}

//------------------------------------------------------------------------LETTURA DA SENSORE MONOSSIDO DI CARBONIO---------------------------------------------------------------------------------------------------------------------------------------
MQ7Data GetDataFromMQ7()
{
  MQ7Data Result;
  Result.intCO = map(analogRead(intPinMQ7Sensor),0,1023,0,1000);
  if (Result.intCO>0)
    Result.blnGoodData = true;
  else
    Result.blnGoodData = false;
    
  return Result;
}

//int freeRam () 
//{
 // extern int __heap_start, *__brkval; 
  //int v; 
  //return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval); 
//}

My personal "FloRoBa.h" file is this:

Code: Select all

#include "Arduino.h"
//---------------------impostazioni sensore DHT--------------------------
int intPinDthSensor = 9;
struct DHTData
{
  int intTemp;
  int intHum;
  boolean blnGoodData;
};

//---------------------impostazioni sensore MQ-7 --------------------------
int intPinMQ7Sensor = A0;
struct MQ7Data
{
  int intCO;
  boolean blnGoodData;
};

//------------------impostazioni scheda WIFI---------------------------------------------

// Define CC3000 chip pins
#define ADAFRUIT_CC3000_IRQ   3
#define ADAFRUIT_CC3000_VBAT  5
#define ADAFRUIT_CC3000_CS    10

//------------------impostazioni scheda WIFI---------------------------------------------
long lngNextTimeToUpdateXively = 120000;
long lngLastTimeUpdatedXively;

enum ReturnType
{
  BadDataFromSensors,
  NoResponseFromDHCP,
  NoResponseOfClient,
  NoXivelyResponse,
  AllDone
};

//--------------IMPOSTAZIONI GENERICHE----------
long lngScanTime;

PierlugiRovere
 
Posts: 15
Joined: Tue Jul 08, 2014 8:40 am

Re: CC3000 Breakout: Best practices? Arduino freeze randomly

Post by PierlugiRovere »

any idea? :(

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

Re: CC3000 Breakout: Best practices? Arduino freeze randomly

Post by adafruit_support_mike »

Try adding a call to 'cc3000.checkConnected()' before making the TCP connection.

Wireless networks are much more suspecible to noise and interference than wired networks, so losing the connection from time to time is normal. If you don't have a link-layer connection when you call for a TCP connection, the code will freeze.

Make sure you have the link-layer connection before calling code that assumes the connection exists, and disconnect/reconnect if you find the connection has dropped.

PierlugiRovere
 
Posts: 15
Joined: Tue Jul 08, 2014 8:40 am

Re: CC3000 Breakout: Best practices? Arduino freeze randomly

Post by PierlugiRovere »

this check is in the top of my function ;)

But now, i can say that the sketch is running from yesterday without any problem. (i've also put the 4th channel).
Now i'm logging sensors data every 2 minutes.

what is the solution?
my data string was too long!!! (i've tried to check ram, but it was ok.....)
Now i'm uploading a single data stream in sequence and every thins work!
i've also updated the CC3000 firmware.

if someone wants to try my sketch.... write here :)

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

Return to “Other Arduino products from Adafruit”