arduino - Should the xivelyclient.get API call take 1 minute to return? -


i using xively arduino api. api calls have used far working expected, except xivelyclient.get() call takes 1 minute return data.

is expected behaviour?

below code. can see 1 of examples come arduino api xively. did going update xivelykey , feedid.

#include <spi.h> #include <ethernet.h> #include <httpclient.h> #include <xively.h>  // mac address ethernet shield byte mac[] = { 0xde, 0xad, 0xbe, 0xef, 0xfe, 0xed };  // xively key let upload data char xivelykey[] = "abcdefghijklmnopqrstuvwxyz";  // define string our datastream id char temperatureid[] = "temperature";  xivelydatastream datastreams[] = { xivelydatastream(temperatureid, strlen(temperatureid), datastream_float), }; // finally, wrap datastreams feed xivelyfeed feed(123456789, datastreams, 1 /* number of datastreams */);  ethernetclient client; xivelyclient xivelyclient(client);  void setup() {   // put setup code here, run once:   serial.begin(9600);    serial.println("reading xively example");   serial.println();     while (ethernet.begin(mac) != 1)    {      serial.println("error getting ip address via dhcp, trying again...");      delay(15000);    }  }   void loop() {    int ret = xivelyclient.get(feed, xivelykey);    serial.print("xivelyclient.get returned ");    serial.println(ret);     if (ret > 0)    {      serial.println("datastream is...");      serial.println(feed[0]);       serial.print("temperature is: ");      serial.println(feed[0].getfloat());    }     serial.println();    delay(15000ul);  } 

the output on serial monitor expected:

reading xively example  xivelyclient.get returned 200 datastream is... { "id" : "temperature", "current_value" : "23.00" } temperature is: 23.00  xivelyclient.get returned 200 datastream is... { "id" : "temperature", "current_value" : "23.00" } temperature is: 23.00 

the responses come @ approximately 1 minute 10 seconds.

i did debugging , found implementation of xivelyclient.get() in xivelyclient.cpp (part of api) hanging in following while loop:

while ((next != '\r') && (next != '\n') && (http.available() || http.connected())) {    next = http.read(); } 

i imagine reason ever coming out of loop because connection being closed server.

in order make function work me added last 2 lines in if statement above while loop , deleted while loop.

if ((idbitfield & 1<<i) && (afeed[i].idlength() == ididx)) {    // we've found matching datastream    // fixme cope errors returned    afeed[i].updatevalue(http);     // when here we'll @ end of line, if afeed[i]    // string or buffer type, we'll have consumed '\n'    next = '\n';    http.stop();    return ret; } 

i'm sure not elegant solution works me now...


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -