Pages: [1]   Go Down
Author Topic: Ethernet shield freezes  (Read 609 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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");
    }
}
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 116
Posts: 5393
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Follow my projects - http://www.begerk.co.uk

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
« Last Edit: July 06, 2012, 06:23:29 am by rdeweerd » Logged

Pages: [1]   Go Up
Jump to: