Ethernet Client - freeze after one day

Hi all,

I am using this code, and it works weel. Except than after one day, the arduino freezes.

Anyone have an idea of my mistake ?

Thanks,

void loop()
{

  // if there are incoming bytes available 
  // from the server, read them and print them:
  if (client.available()) {
    char c = client.read();
    if (c=='?'){
      c = client.read();
      if (c!='0'){
        Serial.println("-> ?");
        Serial.println(c);
        char c2 = client.read();
        Serial.println("-> c");
        Serial.println(c);
        Serial.println("-> c2");
        Serial.println(c2);
        Serial.println("-> c + c2");
        cline[0]=c;
        cline[1]=c2;
        Serial.println(cline);
        if (c2=='_'){
          // Call Funcion All
          client.flush();
          client.stop();
          
          icline=c-'0';
          test(icline,1);
          Serial.println("-> int(c)");
          Serial.println(c-'0');
          Serial.println("disconnecting client.");
        }else{
          // Call Funcion All
          client.flush();
          client.stop();
          
          Serial.println("-> int(cline),1");
          Serial.println(10+cline[2]-'0');
          icline=cline[1]-'0';
          icline=icline+10;
          test(icline,1);
          Serial.println("disconnecting client.");   
          }   
      }
      else
      {
        c = client.read();
        c = client.read();
        if (c!='0'){
        char c2 = client.read();
        Serial.println("-> c");
        Serial.println(c);
        Serial.println("-> c2");
        Serial.println(c2);
        cline[0]=c;
        cline[1]=c2;
        if (c2=='_'){
          // Call Funcion All
          client.flush();
          client.stop();
          
          icline=c-'0';
          Serial.println("-> int(c)__");
          Serial.println(c-'0');
          test(icline,0);
          Serial.println("disconnecting client.");
        }else{
          // Call Funcion All
          icline=cline[1]-'0';
          icline=icline+10;
          Serial.println("-> int(cline),0");
          Serial.println(icline);
          test(icline,0);
          client.flush();
          client.stop();
          Serial.println("disconnecting client.");  
          }
        }   
      }
      
    } 
      
  }
  
  // if the server's disconnected, stop the client:
  if (!client.connected() && lastConnected ) {
    Serial.println();
    Serial.println("disconnecting.");
    client.flush();
    client.stop();
    
  }
  
  // REFRESH
  // if you're not connected, and ten seconds have passed since
  // your last connection, then connect again and send data:
  if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
    httpRequest();
  }
  // store the state of the connection for next time through
  // the loop:
  lastConnected = client.connected();
}

Is the server stalling or the connection breaking?

edit: Is there a SD card in the shield's slot? Where in your code is the freeze happening? What is the last message you see on the serial monitor?

Interesting. I had the same issue when the shield was on the Uno. It would run for 15 minutes or 10 hours. I moved the shield to a Mega and the problem disappeared. Hardware issue?

impresario:
Interesting. I had the same issue when the shield was on the Uno. It would run for 15 minutes or 10 hours. I moved the shield to a Mega and the problem disappeared. Hardware issue?

Shouldn't make a difference unless you were running short on SRAM. Uno has 2k. Mega has 8k.

Is the server stalling or the connection breaking?

mmmmm. Arduino freezing is the best answer I think.

edit: Is there a SD card in the shield's slot? Where in your code is the freeze happening? What is the last message you see on the serial monitor?

I doesn't use SD Card. The last time it freezes during after one of the Serial.print. Maybe during one client.flush... But I am not sure... I will see maybe this night or tomorrow.

It is the third time that I do it, each time it froze after 30 h approx. Only the last time was connected to the viewer by USB.

Try my client GET example sketch from the playground. It has all the latest error checking stuff.
http://playground.arduino.cc/Code/WebClient
See if you have better results with it.

Thanks a lot, it seems to work. I will tell you in some days more...