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);
}
}