I've got a program that does a GET request to a webserver every minute, but after a few hours or sometimes even minutes, the ethernet shield freezes. My main program runs fine then, but if (client.connect(server, 80)) returns false.
If I press the reset button, the Arduino it self reboots fine, but the ethernet shield still hangs. Only after a complete powerdown the ethershield responds.
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println("connected");
// Make a HTTP request:
client.print("GET /updatedb?t1=");
client.print(Temp1);
client.print(&t2=");
client.print(Temp2);
client.println(" HTTP/1.0");
client.println();
client.stop();
}
else {
// you didn't get a connection to the server:
Serial.println("connection failed");
}
}
When the server responds, what is it telling you? I will guess by not reading (emptying) the w5100 rx buffer, the socket is not closing. Eventually, you will run out of sockets. There are only 4.
void SendData() {
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println("connected");
// Make a HTTP request:
client.print("GET /updatedb?t1=");
client.print(Temp1);
client.print(&t2=");
client.print(Temp2);
client.println(" HTTP/1.0");
client.println();
while(client.connected()) {
while(client.available()) Serial.write(client.read());
}
client.stop();
}
else {
// you didn't get a connection to the server:
Serial.println("connection failed");
}
}
There is no timeout function on the while(client.connected()). If the connection breaks, it will hang in that loop. You can add that after you test it.
SurferTim:
When the server responds, what is it telling you? I will guess by not reading (emptying) the w5100 rx buffer, the socket is not closing. Eventually, you will run out of sockets. There are only 4.
There is no timeout function on the while(client.connected()). If the connection breaks, it will hang in that loop. You can add that after you test it.
Thank you that was the solution to my problem!
My program is running now for 4 days without a problem!