Xively & ethernet shield timeout

Hello guys,
I don't want to wait the response of Xively, how I reduce this timeout or take out?

Would you post the code in here from the other thread.

oric_dan:
Would you post the code in here from the other thread.

I don't need anymore, it was another problem that I solved...
Now the problem is very simple, if my internet is out, I don't want that Xively wait too much for response, I need to reduce Xively library timeout!

The default wait for a connection is 1.6 seconds by my calculation. This will reduce that to 200ms.

// add this with your other includes
#include <utility/w5100.h>

  // then in setup after Ethernet.begin(), call this function
  W5100.setRetransmissionCount(1);

SurferTim:
The default wait for a connection is 1.6 seconds by my calculation. This will reduce that to 200ms.

// add this with your other includes

#include <utility/w5100.h>

// then in setup after Ethernet.begin(), call this function
  W5100.setRetransmissionCount(1);

Didn't work, look what happens:

Uploading it to Xively
(then wait for response) <- I don't want wait, I don't care if it was send or not. The rest of my code is more importante then Xively.
xivelyclient.put returned 200

You need to dig into the xively library to break the connection there. I don't use Xively. I have my own servers.

edit: Take a look at my client code.
http://playground.arduino.cc/Code/WebClient
It has a 10 second timeout if the connection breaks. Use what you need from that in the Xively code.

SurferTim:
You need to dig into the xively library to break the connection there. I don't use Xively. I have my own servers.

edit: Take a look at my client code.
Arduino Playground - HomePage
It has a 10 second timeout if the connection breaks. Use what you need from that in the Xively code.

xively\XivelyDatastream.cpp (1 hit)
Line 64: return -1; // -1 indicates timeout

int XivelyDatastream::timedRead(Stream& aStream)
{
  int c;
  long _startMillis = millis();
  do {
    c = aStream.read();
    if (c >= 0) return c;
  } while(millis() - _startMillis < 100UL); // I changed to 100UL, save, Ctrl+R (Verify / Compile), but I didn't notice  any difference...
  return -1;     // -1 indicates timeout
}

If that function does not return -1, then it is getting a character at least every 100ms. The server, if the programmer is good, will return that page in chunks. It will return the header almost immediately, then send packets sporadically as it reads or writes to the database. Then another big chunk when it sends the footer.

That is the way database servers work!

edit: Your best bet is to try to service the server clients (or do your critical stuff) while waiting for the Xively server to respond to you. You should be able to do that. You are using separate sockets for those.

// use this client (socket) to contact Xively
EthernetClient client;

  EthernetClient client = connect(server,port);

// use this client (socket) for the server
EthernetClient srvclient;

  EthernetClient srvclient = server.available();

  if(srvclient) {
    //send 'em a response
  }

The Xively server will not timeout the connection if you do not read the packets immediately. It will also wait for a second or two. It knows your device may be busy.

Nobody uses Xively and thinks response is almost useless and wrong to wait for it?

Nobody uses Xively and thinks response is almost useless and wrong to wait for it?

I did not say or even imply that. What I said was you should do things the other way around.

Take a look at my client code.
http://playground.arduino.cc/Code/WebClient
I would do something like this. This checks the server for clients every trip thru the while loop. This presumes you have a function doServerClient(EthernetClient srvclient); that gets the client request and returns a response.

while(client.connected())
  {
    while(client.available())
    {
      // get the packet
      inChar = client.read();
      Serial.write(inChar);
      // set connectLoop to zero if a packet arrives
      connectLoop = 0;
    }

    connectLoop++;

    // if more than 10000 milliseconds since the last packet
    if(connectLoop > 10000)
    {
      // then close the connection from this end.
      Serial.println();
      Serial.println(F("Timeout"));
      client.stop();
    }

    // check the server
    EthernetClient srvclient = server.available();

    // If server client, take care of it, else delay 1ms
    if(srvclient) doServerClient(srvclient);
    else delay(1);
  }