cc3000 problem, after some connection it stopped to work.

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
User avatar
Jaeger87
 
Posts: 2
Joined: Mon Sep 22, 2014 11:32 pm

cc3000 problem, after some connection it stopped to work.

Post by Jaeger87 »

Hi.

I made a simple program for the arduino with cc3000 that send http request to a website.

The program works fine but after about 100 connection it fail all the connection after the first fail.

This is the code, i suspect that the problem could be something to clean up; is there anything to do other to close the client?

Code: Select all

void setup(void)
{
  Serial.begin(115200);
  if (!cc3000.begin()) {
    Serial.println(F("Unable to initialise the CC3000! Check your wiring?"));
    for(;;);
  }
  if (!cc3000.deleteProfiles()) {
    Serial.println(F("Failed!"));
    while(1);
  }
  char *ssid = WLAN_SSID;  
  if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
    Serial.println(F("Failed!"));
    while(1);
  }
  Serial.println(F("Connected!"));

  while (!cc3000.checkDHCP()) {
    delay(100); // ToDo: Insert a DHCP timeout!
  }

  cc3000.getHostByName(WEBSITE, &ip);

}

void loop()
{
  if(countdown%200==0)
  {
    connessioneTCPAndrea();
  }

  countdown++;
  delay(100);
}

void connessioneTCPAndrea()
{

  if(ip==0)
    return Scrivifail();
  //Serial.println(ip);
  //cc3000.printIPdotsRev(ip);
  client = cc3000.connectTCP(ip, 80);


  if(client.connected())
  {
    Scrivisuccess();
    client.fastrprint(F("GET "));
    client.fastrprint(WEBPAGE);
    client.fastrprint(F(" HTTP/1.1\r\n"));
    client.fastrprint(F("Host: ")); 
    client.fastrprint("basilicotchi.3nd.biz"); 
    client.fastrprint(F("\r\n"));
    client.fastrprint(F("\r\n"));
    //Serial.println(client.connected());
    unsigned long lastRead = millis();
    while (client.connected() && (millis() - lastRead < IDLE_TIMEOUT_MS)) {
      while (client.available()) {
        char c = client.read();
        //Serial.print(c);
        lastRead = millis();
      }

    }
  }
  else
    Scrivifail();
    
    
  client.close();



}


void Scrivifail()
{
  fail++;
  Serial.println("FAIL");
  Serial.println(fail);
  Serial.println(ip);
}

void Scrivisuccess()
{
  success++;
  Serial.println("SUCCESSO");
  Serial.println(success);
}



Thank you!

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

Re: cc3000 problem, after some connection it stopped to work

Post by adafruit_support_mike »

You're probably losing the wifi connection.

That's normal. Wireless connections are more vulnerable to noise and interference than wireless ones, so it's easier to lose the connection. If you call cc3000.connectTCP() when there's no wifi connection, the code will seem to hang.

Try adding a call to cc3000.checkConnected() before calling cc3000.connectTCP(). If it returns TRUE, you can go ahead and request the webpage. If it returns FALSE, you need to call cc3000.reboot() and re-establish the wireless connection before going on.

User avatar
Jaeger87
 
Posts: 2
Joined: Mon Sep 22, 2014 11:32 pm

Re: cc3000 problem, after some connection it stopped to work

Post by Jaeger87 »

I checked the connection and yes, the cc3000 lose the wi fi connetcion, however i tried to reboot the cc3000 with the method cc3000.reboot() but it seems that doesn't work, now i try to recall connectToAP() when i lose the wi-fi connection and i let you know if it worked.

User avatar
Barry914
 
Posts: 448
Joined: Sun Dec 08, 2013 1:26 pm

Re: cc3000 problem, after some connection it stopped to work

Post by Barry914 »

You might want to look at this thread: viewtopic.php?f=22&t=58976 The code I posted has fixed the disconnect/reconnect problems I was having with my CC3000 based project. It's not the device. As Mike said, it's just the nature of WLAN connections.

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

Re: cc3000 problem, after some connection it stopped to work

Post by adafruit_support_mike »

@Barry914: Thanks - I'd forgotten that you pretty much packaged a solution to the problem. I'm bookmarking it for future reference right now!

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

Return to “Other Arduino products from Adafruit”