Xively Arduino针对单个数据流的put
我在xively中创建了两个数据流,一个是我想在xively上发送数据,另一个是我想获取的数据,但在使用put方法时,它正在更改我的两个值,但我不想更新我正在使用的xively.put方法中的一个Xively Arduino针对单个数据流的put,arduino,xively,Arduino,Xively,我在xively中创建了两个数据流,一个是我想在xively上发送数据,另一个是我想获取的数据,但在使用put方法时,它正在更改我的两个值,但我不想更新我正在使用的xively.put方法中的一个 #include <SPI.h> //spi library #include <Ethernet.h> //ethernet library #include <HttpClient.h>//http client library #include <X
#include <SPI.h> //spi library
#include <Ethernet.h> //ethernet library
#include <HttpClient.h>//http client library
#include <Xively.h> //xively library
//using the mac id of ethernrt shield Mac_ID = 90-A2-DA-0E-99-85
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0E, 0x99, 0x85 };
//Xively api key for upload and download
char xivelyKey[] = "api_key";
// Dtastream id i.e Device create in Xively account with same name otherwise will get an error
char ledId[] = "led";
char sensorId[]="stepper";
int sensorPin = A0; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int sensorValue = 0;
//Initializing the xively datastream for the devices created in xively account
XivelyDatastream datastreams[] = {
XivelyDatastream(ledId, strlen(ledId), DATASTREAM_FLOAT),
XivelyDatastream(sensorId, strlen(sensorId), DATASTREAM_FLOAT),
};
//The transmission happen through feed initialize it
//XivelyFeed feed(FEED_ID,XIVELY_DATASTREAM,NO_OF_DATASTREAM)
XivelyFeed feed(feedid, datastreams, 2);
//Initializing the ethernet client for http support
EthernetClient myclient;
//Use the ethernet client to initialize xively client
XivelyClient xivelyclient(myclient);
/* Initial setup of arduino */
void setup(){
/* initialize the serial communication to monitor the transmission */
//starting the serial communication with the baud rate 9600
Serial.begin(9600);
Serial.println("Serial Communication started");
Serial.println();
//assigning the ip address using dhcp
while (Ethernet.begin(mac) != 1){
Serial.println("Error getting IP address via DHCP, trying again...");
delay(15000);
}
}
/* loop for doing continous upload and dowload of data*/
void loop(){
int sensor;
sensor=analogRead(sensorPin);
datastreams[1].setFloat(sensor);
/* uploading the data */
Serial.print("uploading data of stepper");
Serial.println(datastreams[1].getFloat());
Serial.println("Uploading it to Xively");
while((xivelyclient.put(feed, xivelyKey) != 200));
Serial.println();
delay(15000);
Serial.println("uploading of data completed");
/* finidh uploading data*/
/* Downloading the data*/
Serial.println("downloading data");
while((xivelyclient.get(feed, xivelyKey) != 200));
Serial.println("Datastream is...");
Serial.println(feed[0]);
Serial.println("Datastream is...");
Serial.println(feed[1]);
Serial.print("stepper motor downloaded data is: ");
Serial.println(feed[1].getFloat());
Serial.println("downloadind data completed");
Serial.println();
delay(15000);
/* Downloading data completed */
}
#包括//spi库
#包括//以太网库
#包含//http客户端库
#包括//xively库
//使用以太网屏蔽mac_id=90-A2-DA-0E-99-85的mac id
字节mac[]={0x90,0xA2,0xDA,0x0E,0x99,0x85};
//Xively用于上传和下载的api密钥
char xivelyKey[]=“api_密钥”;
//Dtastream id,即在Xively帐户中创建的设备,如果使用相同的名称,则会出现错误
字符ledId[]=“led”;
char sensorId[]=“步进器”;
内部传感器引脚=A0;//选择电位计的输入引脚
int-ledPin=13;//选择LED的引脚
int-sensorValue=0;
//为在xively帐户中创建的设备初始化xively数据流
XIVELYDATASEAM数据流[]={
XivelyDatastream(ledId、strlen(ledId)、DATASTREAM_FLOAT),
十四数据流(传感器ID、strlen(传感器ID)、数据流_浮点),
};
//传输是通过对其进行初始化来实现的
//XivelyFeed提要(提要ID、XIVELY\u数据流、没有\u数据流)
XivelyFeed提要(提要ID、数据流,2);
//初始化以太网客户端以获得http支持
EthernetClient-myclient;
//使用ethernet客户端初始化客户端
XivelyClient XivelyClient(我的客户);
/*arduino的初始设置*/
无效设置(){
/*初始化串行通信以监控变速箱*/
//以波特率9600启动串行通信
Serial.begin(9600);
Serial.println(“串行通信已启动”);
Serial.println();
//使用dhcp分配ip地址
while(以太网开始(mac)!=1){
Serial.println(“通过DHCP获取IP地址时出错,请重试…”);
延迟(15 000);
}
}
/*用于连续上传和下载数据的循环*/
void循环(){
int传感器;
传感器=模拟读数(传感器引脚);
数据流[1]。设置浮点(传感器);
/*上传数据*/
串行打印(“步进机上传数据”);
Serial.println(datastreams[1].getFloat());
Serial.println(“上传到Xively”);
而((xivelyclient.put(feed,xivelyKey)!=200));
Serial.println();
延迟(15 000);
Serial.println(“数据上传完成”);
/*finidh上传数据*/
/*下载数据*/
Serial.println(“下载数据”);
而((xivelyclient.get(feed,xivelyKey)!=200));
Serial.println(“数据流是…”);
Serial.println(提要[0]);
Serial.println(“数据流是…”);
Serial.println(提要[1]);
串行打印(“步进电机下载数据为:”);
Serial.println(提要[1].getFloat());
Serial.println(“下载数据完成”);
Serial.println();
延迟(15 000);
/*下载资料完成*/
}
制作两个XIVELYDATASSTREAM:一个带有要发送的Id,另一个带有要读取的Id
否则,数据流中的所有内容都会更新。
如果没有一些代码可以查看,很难说出可能是什么错误。
// Setup two different streams:
XivelyDatastream datastreams_get[] = {
XivelyDatastream(sensorId, strlen(sensorId), DATASTREAM_FLOAT),
};
XivelyDatastream datastreams_put[] = {
XivelyDatastream(ledId, strlen(ledId), DATASTREAM_FLOAT),
};
//The transmission happen through feed initialize it
//XivelyFeed feed(FEED_ID,XIVELY_DATASTREAM,NO_OF_DATASTREAM)
XivelyFeed feedget(feedid, datastreams_get, 1);
XivelyFeed feedput(feedid, datastreams_put, 1);
// then use different stream definitions for PUT and GET:
xivelyclient.get(feedget, xivelyKey);
xivelyclient.put(feedput, xivelyKey);