Go Down

Topic: Ethernet shield freezes (Read 736 times) previous topic - next topic

rdeweerd

My ethernet shield freezes randomly.

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.

This is the code that sends the data:

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();
        client.stop();
    } 
    else {
        //  you didn't get a connection to the server:
        Serial.println("connection failed");
    }
}

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.
Code: [Select]
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.

PeteOC

My code that calls a webpage can be seen here http://www.begerk.co.uk/general/latest-code/ which at the time of writing has done this 109427 times in the space of 12hrs
Follow my projects - http://www.begerk.co.uk

rdeweerd

#3
Jul 06, 2012, 01:20 pm Last Edit: Jul 06, 2012, 01:23 pm by rdeweerd Reason: 1

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!

Go Up