Hi all,
An outline of what I have is....
An RF network of RFM12 nodes with 1-wire temp sensors and an RFM12-enabled 4 output mains power switch (for lights or whatever) . These communicate to a 'gateway' that collects the info from all the RF nodes and deals with command/responses for the power-switch box.
The gateway links to an Ethermega by RS485.
On the Ethermega, I run a webserver that displays some of the temperatures and lets you turn on/off the 4 power outputs.
Also on the Ethermega, a client logs the temperatures to both nimbits and thingspeak (every 60-sec for Thingspeak, 90-sec for nimbits).
On startup, the time is retrieved from a NTP timeserver and each midnight thereafter.
What I notice is that when using the client connect with a name lookup, ie cloud.nimbits.com, NOT a fixed IP, the client side of the Ethermega eventually hangs up. This can take up to 6-hrs or even after 20-min , but the server side continues to work when the client side stops.
I am currently trying the client side (logging) with fixed IP addresses (which is not a long term solution) and at the same time the ethermega server is being worked by having a autorefresh request from firefox every 10 sec.
Since moving to fixed IP addresses for the logging, the system has been stable for 24 hours (longest ever!) now of logging to two sites and serving up a webpage every 10 seconds without a hitch ( over 8600 page refreshes).
While trying to investigate this I came across a Wiznet errata document (W3150A+/W5100 Errata Sheet) on the W5100 chip about possible errors relating to ARP requests but I am a very inexperienced at C and I lack the understanding to figure out if the fix for the errata has been included in the ethernet library, or even if the client failure while using lookups could be caused by this so I'm hoping for someone with better C/C++ understanding who has looked into this and may be willing to share their experiences and understanding.
I include the logging code here so perhaps someone may spot something I'm doing wrong. It is only a section of the complete code.
When the client side accumulates 5 successive failures, the whole system is reset by the WDT. I have never had a problem with the ethernet not coming back after a reboot.
Is there any way to check how many W5100 sockets are currently available?
Any help/suggestions gratefully received
Thanks.
/*
posts to nimbits
Uses the PString.h library.
Instead of making many connections to the server using the usual Arduino ethernet functions
like 'client.print' (every statement is a separate trasnaction), all the data to send in the
POST trasaction is 'assembled' into one large string using the Pstring library,
which then gets sent in one hit. This reduces the IP traffic considerably
*/
void do_weblog() {
  // if 'postinginterval' secs have passed since
  // your last connection, then connect again and send data:
  if((millis() - lastCloudTime > postingInterval)) {
    line();
    showTimeDate();
    showRunTime();
    sendData();  // the POST happens here
    delay(2);
    }
  }
// this makes a HTTP connection to the logging server:
void sendData() {
byte cloud[] = { 74, 125, 31, 121 }; // cloud.nimbits.com
    str.begin();  // reset the into-string pointer. This is the 'main' string being assembled.
    cont.begin(); // and for the actual content ie payload string
// Create the 'content' of the string to send. Its assembled from the user details, then the sensor data
// 1st part of content is access details
    cont.print("email=XXXXXXXXXXXXXXXX&key=YYYYYYYYYYYYYY");  // store in the string 'cont'
// the sensor data is aquired from the RFM12 gateway that receives all the assorted temp sensor data
// get the data and store it in the 'cont' string. Data is requested from the RFM12 'gateway' using RS485.
    cont.print("&p1=hot-water&v1=");
    GetTemperature(0);    // hot water address
    cont.print(temptemp);  //
    cont.print("&p2=outside1&v2=");
    GetTemperature(5);    // turning circle sensor adress
    cont.print(temptemp);  //
    cont.print("&p3=highest&v3=");
    GetTemperature(7);    // library sensor address
    cont.print(temptemp);  //
    cont.print("&p4=freezer1&v4=");
    GetTemperature(6);    // freezer in pantry address
    cont.print(temptemp);  //
    cont.print("&p5=workshop&v5=");
    GetTemperature(1);    // workshop address
    cont.print(temptemp);  //
   Â
// now get the length of the assembled content string. This string is the complete 'content'
    int contlen = (cont.length());
   Â
// Got the content assembled so try and connect to the web-site
  EthernetClient Logging_client;   // client for both logging services
  Serial2.println("Attempting to connect to Nimbits...");
  if (Logging_client.connect(cloud, 80))
//Â Â if (Logging_client.connect("cloud.nimbits.com", 80))
  {
    str.println("POST /service/batch HTTP/1.1");
    str.println("Host: cloud.nimbits.com");
    str.println("Connection: close");
    str.println("Cache-Control: max-age=0");
    str.print("Content-Length: ");
    str.println(contlen,DEC);
    str.println("Content-Type: application/x-www-form-urlencoded");
    str.println();
    str.println(cont);  // the actual content (data points)
// the total string ('post' headers and content) is sent to the ethernet connection in one hit
    Logging_client.print(str); // ethernet send to COSM
    Serial2.println();    // for debug
    Serial2.print(str);   // this is a copy of whats sent to the ethernet (same string)
    Serial2.println();    // for debug
    Serial2.println();    // for debug
   bufindex = 0;
// look for response
  while (Logging_client.connected()) {
   if (Logging_client.available()) {
    char c = Logging_client.read();
    Serial2.print(c);
    if (bufindex < 198) {
     //store characters to string
    content[bufindex] = c;
    bufindex = bufindex+1;
   }
   }
   content[bufindex] = 0;
  }
  if (strstr(content, "200 OK") != 0) {
   failcount = 0;  // reset after every successfull connect
 }
  else {
    // if you couldn't make a connection:
    failcount = failcount + 1;
    } Â
  }
// The above is when the connection succeeds and data is sent/received Â
// if the connection fails then here is next
  else {
    // if you couldn't make a connection:
    failcount = failcount + 1;
    Serial2.print("Connection failed ");
    }
// and after here for either good or bad connection
   Logging_client.flush();  // ensure no data left in buffer (wont allow close if present)
   Logging_client.stop();  // and finish the socket
   Serial2.print("failcount ");
   Serial2.println(failcount);
    if (failcount > 5) {  // if connection consistently failing then reboot.
     WDTreboot();    // sets up an 8-sec timeout
    }
  lastCloudTime = millis();
}