1

I thought this would be easy but how wrong I am... All I want to do is plot temperature data but I can't seem to get it to work. It reads it out on the serial monitor and says it has sent the data (in the serial monitor) but nothing on the Xively plots! Why?? Below is the code.

I have the API key and feedID from the Xively site. The useragent I'm assuming is the name of the project. My channels are called sensorValue1 and sensorValue2. Please help - this is taking me far too long.

#include <Bridge.h>
#include <Console.h>
#include <Process.h>
#include "DHT.h"
#define DHTPIN 0
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
 #define APIKEY "BLablablablabla" // your pachube API key 
 #define FEEDID blablabla // your feed ID
 #define USERAGENT "SebYun2" // user agent is the project name
// set up net client info:
const unsigned long postingInterval = 60000; //delay between updates to xively.com
unsigned long lastRequest = 0; // when you last made a request
String dataString = "";
void setup() {
 // start serial port:
 Bridge.begin();
 Serial.begin(9600);
 dht.begin();
 while(!Serial); // wait for Network Serial to open
 Serial.println("Xively client");
 // Do a first update immediately
 updateData();
 sendData();
 lastRequest = millis();
}
void loop() {
 // get a timestamp so you can calculate reading and sending intervals:
 long now = millis();
 // if the sending interval has passed since your
 // last connection, then connect again and send data:
 if (now - lastRequest >= postingInterval) {
 updateData();
 sendData();
 lastRequest = now;
 }
}
void updateData() {
 // convert the readings to a String to send it: 
 // Reading temperature or humidity takes about 250 milliseconds!
 // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
 dataString = "Temperature,";
 dataString += dht.readTemperature(false);
 delay(250);
 // add pressure:
 dataString += "\nHumidity,";
 dataString += dht.readHumidity();
 int sensorValue1 = analogRead(A0);
 delay(100);
 int sensorValue2 = analogRead(A0);
 dataString += "\nVoltage1,";
 dataString += sensorValue1*0.0049;
 Serial.print(sensorValue1);
 dataString += "\nVoltage2,";
 Serial.print(sensorValue2);
 dataString += sensorValue2*0.0049;
 delay(1000);
}
// this method makes a HTTP connection to the server:
void sendData() {
 // form the string for the API header parameter:
 String apiString = "X-ApiKey: ";
 apiString += APIKEY;
 // form the string for the URL parameter:
 String url = "https://api.xively.com/v2/feeds/";
 url += FEEDID;
 url += ".csv";
 // Send the HTTP PUT request
 // It is better to declare the Process here, so when the
 // sendData function finishes the resources are immediately
 // released. Declaring it global works too, BTW.
 Process xively;
 Serial.print("\n\nSending data... ");
 xively.begin("curl");
 xively.addParameter("-k");
 xively.addParameter("--request");
 xively.addParameter("PUT");
 xively.addParameter("--data");
 xively.addParameter(dataString);
 xively.addParameter("--header");
 xively.addParameter(apiString); 
 xively.addParameter(url);
 xively.run();
 Serial.println("done!");
 // If there's incoming data from the net connection,
 // send it out the Serial:
 while (xively.available()>0) {
 char c = xively.read();
 Serial.write(c);
 }
}
dda
1,5951 gold badge12 silver badges17 bronze badges
asked Jun 15, 2014 at 8:08

1 Answer 1

1

As long as I checked, this way of uploading data to Xively only works for up to tree pairs of name,data.

If you try with more pairs at the same time the response is "Done", but nothing happens. I finally divide the upload in groups of 3 parameters, and everything is Ok.

I saw your question yesterday when I was looking for a way to upload data to Xively from Yun. It was really helpful for me. Thank you.

answered Jan 4, 2015 at 13:45

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.