Hi, I’ve blown $100 on an Freetronics EtherTen with the hope of using it to log sensor measurements at university. I’ve been testing it out at home wired into my router. The system just doesn’t work reliably and I’m wondering why. I’ve run it with the basic Cosm sketch for a while and it falls over after a day or so. I’ve tried logging to Google Documents and every second POST request gets through for a while before the connection just hangs (you tell me why every second post gets through). I’ve spent several days of my time looking for fixes on the net and this post seems to hint at some sort of software bug which makes the WizNet chip hang. I’ve also found that one of changes to IDE v1.0.1 was the addition of the Ethernet.maintain() class, which renews the temporary IP address assigned to the device. Expiry of a temporary IP address might explain why my Cosm sketch falls over after a period although, as I recall, the sketch falls over after varying lengths of time. If it fell over after a fixed period that would be a good indication that I was experiencing a buffer overflow, expiry of a temporary IP or other finite limit.
Note that I can post data to Cosm without issue so my code and connection are fine. I was literally using the example code without any alterations beyond changing the account key and number of the analogue port read. My problem is that the EtherTen hangs after a day and you have to reset the power to get it working again (it starts immediately without issue after that). Pushing reset does nothing. In the serial output you can see successful posts going through and then one time the server response is -3 and then for every POST attempt after that the server returns -1.
Today I upgraded to IDE v1.0.1 in the hope that this might provide a fix but no such luck. I’ve been trying to log to Google again with the code below. See the serial output below that for an example of what happens.
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server(74,125,39,104); // Google
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
String formkey = "dGE5cUlvV2d3eHRhMmpyaEltQmVXNkE6MQ";
void setup(){
// start the serial library:
Serial.begin(57600);
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
for(;;)
;
}
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println("...connected!");
}
}
void loop(){
// detect state of connection
Serial.print("checking connection . . . ");
if (client.connect(server, 80)) {
Serial.println(". . . connected!");
Serial.println("Posting . . . ");
String data;
data+="";
data+="entry.0.single=";
data+=analogRead(A2);
data+="&submit=Submit";
client.print("POST /formResponse?formkey=");
client.print(formkey);
client.println("&ifq HTTP/1.1");
client.println("Host: spreadsheets.google.com");
client.println("Content-Type: application/x-www-form-urlencoded");
client.println("Connection: close");
client.print("Content-Length: ");
client.println(data.length());
client.println();
client.print(data);
client.println();
Serial.print("POST /formResponse?formkey=");
Serial.print(formkey);
Serial.println("&ifq HTTP/1.1");
Serial.println("Host: spreadsheets.google.com");
Serial.println("Content-Type: application/x-www-form-urlencoded");
Serial.println("Connection: close");
Serial.print("Content-Length: ");
Serial.println(data.length());
Serial.println();
Serial.print(data);
Serial.println();
Serial.println("Posted!");
Serial.print("client returned: ");
if (client.available()) {
char returned = client.read();
Serial.println(returned);
}
else {
Serial.println("client unavailable!");
}
}
else {
Serial.println(". . . not connected");
// check if connection is available
Serial.print("checking connection availability . . . ");
if (client.available()) {
char c = client.read();
Serial.print("client returned: ");
Serial.println(c);
}
else {
Serial.print("client unavailable");
delay(10);
client.flush();
delay(10);
client.stop();
}
}
delay(1000);
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
delay(10);
client.flush();
delay(10);
client.stop();
}
Serial.println();
Serial.println();
delay(20000);
}
Here is some output from serial monitor which shows how the connection falls over. Here the connection had run for a couple of hours before this point.
checking connection . . . . . . connected!
Posting . . .
POST /formResponse?formkey=dGE5cUlvV2d3eHRhMmpyaEltQmVXNkE6MQ&ifq HTTP/1.1
Host: spreadsheets.google.com
Content-Type: application/x-www-form-urlencoded
Connection: close
Content-Length: 32entry.0.single=143&submit=Submit
Posted!
client returned: client unavailable!checking connection . . . . . . not connected
checking connection availability . . . client returned: Hdisconnecting.
checking connection . . . . . . connected!
Posting . . .
POST /formResponse?formkey=dGE5cUlvV2d3eHRhMmpyaEltQmVXNkE6MQ&ifq HTTP/1.1
Host: spreadsheets.google.com
Content-Type: application/x-www-form-urlencoded
Connection: close
Content-Length: 32entry.0.single=143&submit=Submit
Posted!
client returned: client unavailable!checking connection . . . . . . not connected
checking connection availability . . . client returned: Hdisconnecting.
checking connection . . . . . . connected!
Posting . . .
POST /formResponse?formkey=dGE5cUlvV2d3eHRhMmpyaEltQmVXNkE6MQ&ifq HTTP/1.1
Host: spreadsheets.google.com
Content-Type: application/x-www-form-urlencoded
Connection: close
Content-Length: 32entry.0.single=143&submit=Submit
Posted!
client returned: client unavailable!checking connection . . . . . . not connected
checking connection availability . . . client returned: Hchecking connection . . . . . . not connected
checking connection availability . . . client returned: Tchecking connection . . . . . . not connected
checking connection availability . . . client returned: Tchecking connection . . . . . . not connected
checking connection availability . . . client returned: P
The single letters returned from each failed POST eventually spell out: “HTTP/1.1 200 OKContent-Type: text/html; charset=utf-8X-Robots-Tag: noindex, nofollow, nosnippetDate: Sat, 13 Oct 2012 02:19:58 GMTExpires: Sat, 13 Oct 2012 02:19:58 GMTCache-Control: private, max-age=0X-Content-Typ”.
Is there some known bug with ethernet that causes it to fall over like this? Do WiFi shields experience the same problem or is this unique to ethernet? I’ve got a lot of uses for this technology if it proves reliable.