C++ Xively-API:can´;t上传两个变量

C++ Xively-API:can´;t上传两个变量,c++,arduino,xively,C++,Arduino,Xively,我对Arduino的Xively API有一些问题。我的项目包括通过以太网屏蔽发送模拟传感器收集的数据,并将其打印到Xively网站(目前在我的帐户中)。问题是,我必须向xively发送两个不同的变量:一个用于LDR值(LDREsq),另一个用于通过DHT_11温度传感器收集的温度值。但是,我只能发送LDR值,而不能发送TEMPERATURE值。我已经为每个变量构建了两个void函数,它们都使用不同的API键连接到xively。但是我不能上传温度值 这是我的代码-只有两个函数-前面阅读的LDRE

我对Arduino的Xively API有一些问题。我的项目包括通过以太网屏蔽发送模拟传感器收集的数据,并将其打印到Xively网站(目前在我的帐户中)。问题是,我必须向xively发送两个不同的变量:一个用于LDR值(LDREsq),另一个用于通过DHT_11温度传感器收集的温度值。但是,我只能发送LDR值,而不能发送TEMPERATURE值。我已经为每个变量构建了两个void函数,它们都使用不同的API键连接到xively。但是我不能上传温度值

这是我的代码-只有两个函数-前面阅读的LDREsq的sendData和DHT.temperature的sendData2(如果你不懂一件事,请告诉我,我会解释,因为部分代码可能是葡萄牙语):

这就是所谓的

temp3++;
if(temp3 >= 20)
{
  sendData2(DHT.temperature);
  delay(100);
  temp3 = 0;
}


temp2++;
if (temp2 >= 10)
{
  sendData(estadoLDREsq);
  temp2 = 0;
}

只需让Xivley库为您完成以下工作:

#include <SPI.h>
#include <Ethernet.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[] = "[Put your Key here]";

// Define a datastream textual name 
char sensorId[] = "TEMP_001";

// Create as many datastreams you need (one in this case)
XivelyDatastream datastreams[] = {
  XivelyDatastream(sensorId, strlen(sensorId), DATASTREAM_FLOAT),
};

// Finally, wrap the datastreams into a feed
XivelyFeed feed([put your feed number here], datastreams, 1); // Where 1 is the number of datastreams we are wrapping

// Create a Etherent client
EthernetClient client;

// Let Xively know about the Ethernet client
XivelyClient xivelyclient(client);


// Run all the setup you need
void setup(void) {
  Serial.begin(9600);
  while (Ethernet.begin(mac) != 1){
    Serial.println("Error getting IP address via DHCP, trying again...");
    delay(15000);
  }
}


// Loop over
void loop(void) {

  // Read your sensor
  float celsius = [put your sensor reading value here];

  // Copy sensor reading to the apropriate datastream
  datastreams[0].setFloat(celsius);

  // Ask Xively lib to PUT all datastreams values at once
  int ret = xivelyclient.put(feed, xivelyKey);

  // Printout PUT result
  Serial.print("xivelyclient.put returned ");
  Serial.println(ret);

  // Wait 10 sec.
  delay(10000);  
}
#包括
#包括
#包括
//以太网屏蔽的MAC地址
字节mac[]={0xDE,0xAD,0xBE,0xEF,0xFE,0xED};
//您的Xively密钥允许您上载数据
char xivelyKey[]=“[把钥匙放在这里]”;
//定义数据流文本名称
char sensorId[]=“TEMP_001”;
//创建所需数量的数据流(本例中为一个)
XIVELYDATASEAM数据流[]={
十四数据流(传感器ID、strlen(传感器ID)、数据流_浮点),
};
//最后,将数据流包装到提要中
XivelyFeed提要([在此处输入提要编号],数据流,1);//其中1是我们正在包装的数据流的数量
//创建以太客户端
以太网络客户端;
//让Xively了解以太网客户端
XivelyClient XivelyClient(客户);
//运行所有需要的安装程序
作废设置(作废){
Serial.begin(9600);
while(以太网开始(mac)!=1){
Serial.println(“通过DHCP获取IP地址时出错,请重试…”);
延迟(15 000);
}
}
//绕圈子
无效循环(无效){
//读取你的传感器
浮动摄氏度=[将传感器读数放在此处];
//将传感器读数复制到适当的数据流中
数据流[0]。setFloat(摄氏度);
//要求Xively lib一次放置所有数据流值
int-ret=xivelyclient.put(feed,xivelyKey);
//打印输出结果
Serial.print(“xivelyclient.put返回”);
序列号println(ret);
//等10秒。
延迟(10 000);
}
#include <SPI.h>
#include <Ethernet.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[] = "[Put your Key here]";

// Define a datastream textual name 
char sensorId[] = "TEMP_001";

// Create as many datastreams you need (one in this case)
XivelyDatastream datastreams[] = {
  XivelyDatastream(sensorId, strlen(sensorId), DATASTREAM_FLOAT),
};

// Finally, wrap the datastreams into a feed
XivelyFeed feed([put your feed number here], datastreams, 1); // Where 1 is the number of datastreams we are wrapping

// Create a Etherent client
EthernetClient client;

// Let Xively know about the Ethernet client
XivelyClient xivelyclient(client);


// Run all the setup you need
void setup(void) {
  Serial.begin(9600);
  while (Ethernet.begin(mac) != 1){
    Serial.println("Error getting IP address via DHCP, trying again...");
    delay(15000);
  }
}


// Loop over
void loop(void) {

  // Read your sensor
  float celsius = [put your sensor reading value here];

  // Copy sensor reading to the apropriate datastream
  datastreams[0].setFloat(celsius);

  // Ask Xively lib to PUT all datastreams values at once
  int ret = xivelyclient.put(feed, xivelyKey);

  // Printout PUT result
  Serial.print("xivelyclient.put returned ");
  Serial.println(ret);

  // Wait 10 sec.
  delay(10000);  
}