Pages: [1]   Go Down
Author Topic: Xively & ethernet shield timeout  (Read 623 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 44
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 149
Posts: 2790
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

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!
« Last Edit: August 01, 2013, 07:35:49 am by jgarcia » Logged

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

The default wait for a connection is 1.6 seconds by my calculation. This will reduce that to 200ms.
Code:
// add this with your other includes
#include <utility/w5100.h>

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

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

The default wait for a connection is 1.6 seconds by my calculation. This will reduce that to 200ms.
Code:
// 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
Logged

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

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

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

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.



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

Code:
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
}
Logged

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

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.

Code:
// 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.
« Last Edit: July 31, 2013, 04:40:29 pm by SurferTim » Logged

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

Nobody uses Xively and thinks response is almost useless and wrong to wait for it?
« Last Edit: August 02, 2013, 09:25:51 am by jgarcia » Logged

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

Quote
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.
Code:
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);
  }
Logged

Pages: [1]   Go Up
Jump to: