Electronic – Arduino + Ethernet Shield hangs after some time

arduinoethernet

I am using an arduino to retrieve some data from a web application. The problem is that after some time it starts to hang.

For testing I used the default EthernetClient sketch and modified it a bit that every few secounds there is send a request to the server to get the information. For testing I don't do anything with the data I get so it does only send the request and retrieve the data.

For testing I use a Arduino Mega 2560 + Ethernet Shield and a Arduino Ethernet board, I experience the problem on both. It runs from 30 minutes up to one day then the whole board freezes. The boards doesn't get hot or anything else.

At first it seams to work but after some undefined time it starts to hang, does anyone have an idea what could cause this? Is there a bug on the arduino or the W5100 Ethernet chip?

Would you try to fix this issue or switch to a Raspberry Pi? Using the watchdog timer is no option because it doen't work on the Mega without changing the bootloader.

UPDATE (Added my loop code, there are no memory issues, I testet that before):

void loop()
{
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    delay(2000);

    if (client.connect(server, 80)) {
      Serial.println("connected");
      client.println("GET / HTTP/1.0");
      client.println();
    }
  }
}

This is all it does, in the setup there is the default initialization code from the Ethernet demo sketch.

UPDATE 2

Testing with Arduino Mega + WiFi Shield hangs too.

Testing with EtherMega 2560 from freetronics is now running 2 days without any problems I will continue this for min. one week. My only problem with this bord is the price. It's around 100$.

Best Answer

UPDATE

Here is a working solution testet with Mega (1.0.1) and Due (1.5.3)

Ok, it seams there is a bug in the arduino 1.0.x libraries that causes the ethernet module to hang after some time, when you have to permanetly query a server.

With the Arduino Due (arduino 1.5.2) it is now running and also much faster! So its maby the best option to use this when you have to deal with much network traffic and many operations. I will contact the arduino developers about this issue and update this answer when I got more information about this problems.