Problem Connecting Arduino to Xively Feed

Hello,

I am currently trying to read information from an infrared sensor, and upload it to the Xively Feed. The code is exactly how I’ve written except I haven’t included the key or the API. My project works fine when it’s not being uploaded to Xively, and it appears that my wifi is working fine (the Link button is green). However, anytime I try and upload all of my data to Xively, I get the following:

xivelyclient.put returned -1
Uploading it to Xively
No Socket available
xivelyclient.put returned -1
Uploading it to Xively
No Socket available
xivelyclient.put returned -1

Specs:
Arduino Uno
IDE 1.0.5
Sharp Infrared Sensor
Arduino Wifi Shield

#include <SPI.h>
 #include <WiFi.h>
 #include <HttpClient.h>
#include <Xively.h>
char ssid[] = "guest"; 
int status = WL_IDLE_STATUS; 
const int sensorPin = 2;
#define xivelyFeed MYFEED
const long referenceMv = 5000;
char xivelyKey[] = "Key";
char sensorId[] = "Infrared Reading:";
XivelyDatastream datastreams[] = {
  XivelyDatastream(sensorId, strlen(sensorId), DATASTREAM_FLOAT),
};
WiFiClient client;
XivelyClient xivelyclient(client);
XivelyFeed feed(xivelyFeed, datastreams, 1);
void setup() {

  Serial.begin(9600);
  while (!Serial) {
    ; 
  }
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present"); 
    // don't continue:
    while(true);
  } 
  
  while ( status != WL_CONNECTED) { 
    Serial.print("Attempting to connect to open SSID: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid);

    delay(10000);
  }   
  Serial.println("You're connected to the network");
}

 
void loop()
{
  int val = analogRead(sensorPin);
  int mV = (val * referenceMv) / 1023;
  int cm = getDistance(mV);
  datastreams[0].setFloat(cm);
  if (cm<95)
  {
  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);  
  delay(1000);
}
const int TABLE_ENTRIES = 12;
const int firstElement = 250; // first entry is 250 mV
const int INTERVAL  = 250; // millivolts between each element
static int distance[TABLE_ENTRIES] = {150,140,130,100,60,50,40,35,30,25,20,15};
int getDistance(int mV)
{
   if( mV >  INTERVAL * TABLE_ENTRIES-1 )
      return distance[TABLE_ENTRIES-1];
   else
   {
      int index = mV / INTERVAL;
      float frac = (mV % 250) / (float)INTERVAL;
      return distance[index] - ((distance[index] - distance[index+1]) * frac);
   }
}

What am I doing wrong?

Did you ever solve this? I’m having the same issue and can’t seem to solve it.

/////////////////////////////////
/*
##Xively WiFi Sensor Tutorial##
This sketch is designed to take sensors (from photocell) and upload the values to Xively
at consistant intervals. At the same time it gets a setable value from Xively to adjust the brigthness
of an LED. This sketch is reusable and can be adapted for use with many different sensors.
Derived from Xively Ardino Sensor Client by Sam Mulube.

By Calum Barnes 3-4-2013
BSD 3-Clause License - [http://opensource.org/licenses/BSD-3-Clause]
Copyright (c) 2013 Calum Barnes
*/
#include <Arduino.h>
#include <SPI.h>
#include <WiFi.h>
#include <HttpClient.h>
#include <Xively.h>

char ssid = “n4d"; // your network SSID (name)
char pass[] = "sk
r”; // your network password (use for WPA, or use as key for WEP)
int status = WL_IDLE_STATUS;
//int keyIndex = 4; // your network key Index number (needed only for WEP)

int sensorPin = 0;

// Your Xively key to let you upload data
char xivelyKey = "t7V*********WMn";
//your xively feed ID
#define xivelyFeed 1
10
//datastreams
char sensorID = “SHERLOCH_Temperature”;
//char ledID = “LED_CHANNEL”;

// Analog pin which we’re monitoring (0 and 1 are used by the Ethernet shield)
#define sensorPin A2
//led connected pin
//#define ledPin 9

// Define the strings for our datastream IDs
XivelyDatastream datastreams = {
XivelyDatastream(sensorID, strlen(sensorID), DATASTREAM_FLOAT),
//XivelyDatastream(ledID, strlen(ledID), DATASTREAM_FLOAT),
};
// Finally, wrap the datastreams into a feed
XivelyFeed feed(xivelyFeed, datastreams, 1 /* number of datastreams */);

WiFiClient client;
XivelyClient xivelyclient(client);

void printWifiStatus() {
// print the SSID of the network you’re attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());

// print your WiFi shield’s IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);

// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print(“signal strength (RSSI):”);
Serial.print(rssi);
Serial.println(" dBm");
}
void setup() {
// put your setup code here, to run once:
Serial.begin(19200);

Serial.println(“Starting single datastream upload to Xively…”);
Serial.println();

// attempt to connect to Wifi network:
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid, pass);
// wait 30 seconds for connection:
delay(10000);
}
Serial.println(“Connected to wifi”);
printWifiStatus();
}

void loop() {
int reading = analogRead(A2);
float voltage = reading * 4.73;
voltage /= 1024.0;
float temperature = (voltage - 0.5) * 100;
//convert to fehrenheit temp
float fehr = (temperature * 1.8)+32;
//End RH Code */
//datastreams[0].setFloat(temperature);
datastreams[0].setFloat(fehr);

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(60000); //1-minute delay
//delay(1000); //1-second delay
delay(5000); //5-second delay
//delay(10000); //10-second delay
//delay(60000); //1-minute delay
//delay(600000); //10-minute delay

}