Ethernet Library hangs? Does anyone else experience this? Is it a bug?

My problem in short:

My application is to read sensors and send that data to a Sensor, my sketch is very similar to the PatchubeClient sketch. The software is running on an Arduino Mega2560 with an µSD Ethernet Shield. Everything seems to work fine but after 3 days of operation (my sketch sends every 30 seconds) the server didn’t get any new data. After a Reset of the Arduino it worked for five days (more than 10,000 data entries logged on the server), then it stopped working again.

I am suspecting some functions of the Ethernet Client class to hang on some specific exceptions, but knows somebody better? I dont think the rest of the code could be wrong, because it is very basic(not much more than some analogRead() function calls). It is frustrating to see your sketch hang and because I don’t know what I can do about it.

My application is to read sensors and send that data to a Sensor,

You really sending the data to a sensor?

zoomkat:

My application is to read sensors and send that data to a Sensor,

You really sending the data to a sensor?

I think it's more of a communication issue, than what we think it is.

buggybug: I am suspecting some functions of the Ethernet Client class to hang on some specific exceptions, but knows somebody better? I dont think the rest of the code could be wrong, because it is very basic(not much more than some analogRead() function calls). It is frustrating to see your sketch hang and because I don't know what I can do about it.

Without us seeing the code, it's a bit hard to point in some direction. One such direction would be to just use the Ethernet client to connect and send data to Pachube (if it's pachube your using). The other would be for you to create some sort of debugging interface and leave a computer connected (or, why not, the uSD card) to see where it fails. I remember seeing a lot of people complaining about this before and implementing an auto reset for the system. Maybe it can be a possibility for you?

sorry! I send the data to a webserver via a HTTP GET request.

bubulindo:
…I remember seeing a lot of people complaining about this before and implementing an auto reset for the system. Maybe it can be a possibility for you?

@bubulindo: what do you mean by auto reset or how could I implement such an auto reset?

My code looks like this:

void loop() {
		
		if(millis()>(lastSend+sendInterval)) 
		{ 
			sensorValue = analogRead(A1);
			send(); 
			lastSend=millis(); 
		}
		
}


void send(){
  if (client.connect()) {
	  client.print("GET /savedata.php?d=");
	  client.print(sensorValue);
	  client.println(" HTTP/1.1");
	  client.println("Host: myhost.com");
	  client.println("");
	  client.println("");
	  
		
		for(time = 0; i < waitTime; ++i){ 
			if (client.available()) { char c = client.read(); Serial.print(c); }
    	                if (!client.connected()) { Serial.println("disconnecting"); break; } 
	  	delayMicroseconds(100); 
		}
  }
	else { Serial.print("sending ERROR ");}
  client.stop();
}
		for(time = 0; i < waitTime; ++i){ 
			if (client.available()) { char c = client.read(); Serial.print(c); }
    	                if (!client.connected()) { Serial.println("disconnecting"); break; } 
	  	delayMicroseconds(100); 
		}

Reading the response from the server would be better done in a while loop.

unsigned long waitStarted = millis();
while(millis() - waitStarted < waitTime && client.connected())
{
   if(client.available() > 0)
   {
      Serial.print(client.read());
   }
}

No delays required, and the while loop will end as soon as the data has been retrieved. If no response arrives within the time defined in waitTime (another unsigned long), the while function will end, eventually. It will end immediately, if the client/server connection is broken.

Hi, it looks a little bit similar to my last topic - take a look on http://arduino.cc/forum/index.php/topic,64020.0.html . The codes are partially different nevermind based on my experience I suggest to try insert "client.stop()" before the "break" command.

It helped me with my data feed to Pachube and it works for at least 5 days without problem.

Cheers