I am getting "xivelyclient.put returned -3" whenever it tries to upload the data to Xively. I have also checked my codes, but can't seems to find any error. Please help!
Here are the codes:
#include <SPI.h>
#include <Ethernet.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[] = "LJrYPIT0vx59hkZCXzkQuywSukEwZJAzJx5jZB3CQAZBxMq1";//API KEY
// Analog pin which we're monitoring (0 and 1 are used by the Ethernet shield)
int sensorPin = 2;
// Define the strings for our datastream IDs
char sensorId[] = "SensorReading";
XivelyDatastream datastreams[] = {
XivelyDatastream(sensorId, strlen(sensorId), DATASTREAM_FLOAT)
};
// Finally, wrap the datastreams into a feed
XivelyFeed feed(633350176, datastreams, 1 /* number of datastreams */);
EthernetClient client;
XivelyClient xivelyclient(client);
int flexSensorPin = A0; //analog pin 0
void setup(){
Serial.begin(9600); // telling it to begin sensing the signal at 9600 bits of data per second
}
void loop(){
int flexSensorReading = analogRead (flexSensorPin); // declaring what the sensor reading is
delay(250); // Just to slow down the output for easier reading
int flex0to100 = map(flexSensorReading, 150, 300, 100, 0);
//flexSensorReading is assigned to store the raw analog value from the sensor.
//map(value, fromLow, fromHigh, toLow, toHigh). map() function is used to reduce the range as Arduino is able to read analog value up to 1023.
Serial.println(flex0to100);
int sensorValue = analogRead(sensorPin);
datastreams[0].setFloat(sensorValue);
Serial.print("Read sensor value ");
Serial.println(datastreams[0].getFloat());
Serial.println("Uploading it to Xively");
int ret = xivelyclient.put(feed, xivelyKey);
Serial.print("xivelyclient.put returned ");
Serial.println(ret);
Serial.println();
delay(15000);
}