CC3000 WIFI Shield - Problems, hanging and disconnects

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Svane
 
Posts: 3
Joined: Wed Jun 10, 2015 2:14 pm

CC3000 WIFI Shield - Problems, hanging and disconnects

Post by Svane »

Hi everyone.

I am trying to work with the CC3000 WIFI Shield, and have huge problems. There are two scenarios when i run this project.

When I run the project, the first loop usually goes fine, it connects to the server and sends the data. But the second time in the loop everything goes wrong. Sometimes it disconnects to the server and the if-statement fails, other times the project is hanging trying to send data to the server.

I really hope to get help, after using 3 days intensive on this error.

I have copied my code below.

Code: Select all


// Include required libraries
#include <Adafruit_CC3000.h>
#include <SPI.h>
#include <MemoryFree.h>;


// WiFi network
#define WLAN_SSID       "SSID"        // cannot be longer than 32 characters!
#define WLAN_PASS       "password"
#define WLAN_SECURITY   WLAN_SEC_WPA2 // This can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2


// These are the interrupt and control pins
#define ADAFRUIT_CC3000_IRQ   3  // MUST be an interrupt pin!
// These can be any two pins
#define ADAFRUIT_CC3000_VBAT  5
#define ADAFRUIT_CC3000_CS    10

// Create CC3000 & DHT instances
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
                                         SPI_CLOCK_DIV2); // you can change this clock speed
                                         
// Local server IP, port, and repository 
uint32_t ip = cc3000.IP2U32(192,168,0,10);
int port = 93;
String yourdata;
Adafruit_CC3000_Client client;

void setup(void)
{
  Serial.begin(115200);
    
  // Initialise the CC3000 module
  if (!cc3000.begin())
  {
    while(1);
  }

  // Connect to  WiFi network
  cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY);
  Serial.println(F("Connected to WiFi network!"));
    
  // Check DHCP
  Serial.println(F("Request DHCP"));
  while (!cc3000.checkDHCP())
  {
    delay(100);
  }
   client = cc3000.connectTCP(ip, port);
    
   Serial.println(freeMemory(), DEC);
}


void loop(void)
{
  humidityTemperature();
  delay(3002);
}

void humidityTemperature () {
  
  // sent in your POST request
  String cpr = "1547844444";
  yourdata = "temp1=" + cpr;
  
    Serial.println(F("Starting connection to server..."));
    // Send request
    if (client.connected()) {
    client.println(F("POST /add.php HTTP/1.1"));
      // EDIT: 'Host' to match your domain
    client.println(F("Host: 192.168.0.10:93"));
    client.println(F("User-Agent: Arduino/1.0"));
    client.println(F("Connection: close"));
    client.println(F("Content-Type: application/x-www-form-urlencoded;"));
    client.print(F("Content-Length: "));
    client.println(yourdata.length());  
    client.println();
    client.println(yourdata); 
      Serial.println(F("Connected & Data sent"));
    delay(100); 
    } 
    else {
      Serial.println(F("Connection failed"));
     // client.stop();
 //BLÅ LED SEND DATA    
    }
   
}

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

Re: CC3000 WIFI Shield - Problems, hanging and disconnects

Post by adafruit_support_mike »

Try adding a call to cc3000.connected() to make sure the wireless link is still active:

Code: Select all

    if (( cc3000.connected() ) && (client.connected())) {
Wifi connections are much more sensitive to noise and interference than hardwired connections, so it isn't so much a question of whether the link will fail as when it will fail.

If the connection does fail, call cc3000.reboot() and go through the connection process again.

User avatar
Svane
 
Posts: 3
Joined: Wed Jun 10, 2015 2:14 pm

Re: CC3000 WIFI Shield - Problems, hanging and disconnects

Post by Svane »

Thank you so much.

My problem is solved. I now call the method reboot every time i have checked if both the client and the cc3000 is connected. The problem was that they both were connected but still hanged. But with the reboot it doesn't hang anymore :-)

Again thanks. :-)

User avatar
ecdowney
 
Posts: 48
Joined: Fri Oct 14, 2011 8:40 am

Re: CC3000 WIFI Shield - Problems, hanging and disconnects

Post by ecdowney »

This sounded like it would help my issue also but when I tried this I get:

Code: Select all

wifi.cpp:80: error: 'class Adafruit_CC3000' has no member named 'connected'
  if (!cc3000.connected()) {
I downloaded and installed the latest Adafruit_CC3000_Library-master.zip. I grepped through all the files and it seems only Adafruit_CC3000_Client has a connected() method, not Adafruit_CC3000.

Thanks,

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

Return to “Arduino Shields from Adafruit”