Xively Datastreams设置Arduino

时间:2014-07-21 15:55:14

标签: xively

我想在Xively上更新两个频道,我无法让我的数据流更新两者。我看到一个频道正在更新("温度"),但另一个" sensor1"没有更新。

这是我在数据流中的第一次破解,所以任何建议/指针/教程都会非常感激。我看了一遍,无法让这个工作。我最初使用Feed API为一个传感器设置一个Feed,但现在我想添加更多传感器。再次,非常感谢任何帮助!

#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);
}

1 个答案:

答案 0 :(得分:1)

尝试将数据流的数量更改为2。

//最后,将数据流包装到Feed中 XivelyFeed feed(418519995,datastreams,2 / *数据流数量* /);