我想在Xively上更新两个频道,但我无法让我的数据流同时更新这两个频道。我看到一个频道正在更新("Temperature"),但另一个"sensor1“没有更新。
这是我在数据流上的第一次尝试,所以任何建议/指针/教程都将不胜感激。我已经找遍了,就是不能让它工作。我最初使用Feed API为一个传感器设置一个摘要,但现在我想添加更多传感器。再说一次,任何帮助都将非常感谢!
#include <SPI.h>
#include <EthernetV2_0.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[] = "osUccdJJbn9lkhjSOZMoTznEUOYJH7j1mgU5Jz8DRXOtGzHf";
// Analog pin which we're monitoring (0 and 1 are used by the Ethernet shield)
int tempPin = 3;
int motionPin = 5;
// Define the strings for our datastream IDs
char sensorId[] = "sensor_reading";
XivelyDatastream datastreams[] = {
XivelyDatastream("Temperature", strlen("Temperature"), DATASTREAM_FLOAT),
XivelyDatastream("sensor1", strlen("sensor1"), DATASTREAM_FLOAT),
};
// Finally, wrap the datastreams into a feed
XivelyFeed feed(418519995, 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("Starting single datastream upload to Xively...");
Serial.println();
while (Ethernet.begin(mac) != 1)
{
Serial.println("Error getting IP address via DHCP, trying again...");
delay(15000);
}
}
void loop() {
int tempValue = analogRead(tempPin);
int motionValue = analogRead(motionPin);
//temperature conversion - not working currently.
int tempValueTmp = log(((10240000/tempValue) - 10000));
tempValueTmp = 1 / (0.001129148 + (0.000234125 * tempValueTmp) + (0.0000000876741 * tempValueTmp * tempValueTmp * tempValueTmp));
tempValueTmp = tempValueTmp - 273.15;
int ftemp = (tempValueTmp * 1.8) + 32;
datastreams[0].setFloat(ftemp);
datastreams[1].setFloat(motionValue);
Serial.print("Read temp sensor value ");
Serial.println(datastreams[0].getFloat());
Serial.print("Read motion sensor value ");
Serial.println(datastreams[1].getFloat());
Serial.println("Uploading it to Xively");
int ret = xivelyclient.put(feed, xivelyKey);
Serial.print("xivelyclient.put returned ");
Serial.println(ret);
Serial.println();
delay(3000);
}发布于 2014-08-03 14:17:21
尝试将数据流的数量更改为2。
//最后,将数据流打包成一个feed XivelyFeed feed(418519995,数据流,2 /*个数的数据流*/);
https://stackoverflow.com/questions/24869380
复制相似问题