我已经在xively中创建了两个数据流,我希望在xively和我想要的数据上发送数据但是在使用put方法时它正在改变我的两个值,但我不想更新其中一个数据流我是使用xively.put方法进行此
#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 */
}
答案 0 :(得分:0)
制作两个XivelyDatastream:一个包含您要发送的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);