1

I want to update two channels on Xively and I can not get my datastream to update both. I am seeing one channel being updated ("Temperature"), but the other "sensor1" is not being updated.

This is my first crack at a datastream, so any advice/pointers/tutorials to look at would be much appreciated. I have looked all over and can not get this to work. I intially used the Feed API to set up one feed for one sensor, but now i want to add more sensors. Again, any help would be extremely appreciated!

#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 Answers1

1

Try changing the number of datastreams to 2.

// Finally, wrap the datastreams into a feed XivelyFeed feed(418519995, datastreams, 2 /* number of datastreams */);