I have a small test application (a modified version of the EthernetClient example) that is permanently using the Ethernet library. Here is the sketch:
#include <SPI.h>
#include <Ethernet.h>
#define GREEN_PIN 41
byte mac[] = { ... };
// google.de
IPAddress server(173, 194, 69, 94);
int port = 80;
EthernetClient client;
boolean ethernetAvailable;
char testCharacter = ' ';
void setup() {
Ethernet.begin(mac);
pinMode(GREEN_PIN, OUTPUT);
digitalWrite(GREEN_PIN, HIGH);
delay(1000);
}
void loop() {
if (client.connected()) {
if (client.available()) {
char c = client.read();
testCharacter += c;
} // no else
digitalWrite(GREEN_PIN, LOW);
} else {
client.stop();
digitalWrite(GREEN_PIN, HIGH);
delay(1000);
if (client.connect(server, port)) {
client.println("GET / HTTP/1.0");
client.println();
} // no else
}
}
Link to Gist: Demonstration: This code hangs on all arduino versions after some time... · GitHub
This sketch runs for some time and the LED on the GREEN_PIN blinks. Between a few minutes or days the arduino hangs and I don't know why.
I have testst this sketch with this setups:
- Arduino Ethernet (1.0.3)
- Arduino Mega (1.0.3) + Ethernet Shield
- Arduino Due (1.5.1) + Ethernet Shield
- Arduino Due (1.5.2) + Ethernet Shield
- Arduino Mega (1.0.3) + Wifi Shield [with a Wifi setup of course]
It's always the same problem, it does what it should for a while and than it hangs. I also logged the output of client.read(); into a file with a serial monitoring tool it works for some time but then stops working while reading. I also tried this using a static IP and none from DHCP, the same issue.
I this a bug or is there any change I have to apply to get this sketch working?
Best regards.