我正在使用 Xively Arduino API。到目前为止,我使用的所有 API 调用都按预期工作,除了 xivelyclient.get() 调用需要 1 分钟才能返回数据。
这是预期的行为吗?
下面是我的代码。如您所见,它基本上是 Xively 的 Arduino API 附带的示例之一。我所做的只是更新 xivelyKey 和 feedID。
#include <SPI.h>
#include <Ethernet.h>
#include <HttpClient.h>
#include <Xively.h>
// MAC address for your Ethernet shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// Your Xively key to let you upload data
char xivelyKey[] = "abcdefghijklmnopqrstuvwxyz";
// Define the string for our datastream ID
char temperatureId[] = "temperature";
XivelyDatastream datastreams[] = {
XivelyDatastream(temperatureId, strlen(temperatureId), DATASTREAM_FLOAT),
};
// Finally, wrap the datastreams into a feed
XivelyFeed feed(123456789, datastreams, 1 /* number of datastreams */);
EthernetClient client;
XivelyClient xivelyclient(client);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("Reading from 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);
}
串行监视器上的输出与预期的一样:
Reading from 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
响应时间大约为 1 分 10 秒。