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!