Sending Data to Xively through WiFi Shield - Constantly Returning -1

Hi all,

I am attempting to measure the output from an analog sensor, which at the moment is simply a potentiometer. I am using an Arduino Uno R2 and an official Arduino Wi-Fi Shield.

Below is my code I am currenly using to upload my data to Xively:

#include <SPI.h>
#include <WiFi.h>
#include <HttpClient.h>
#include <Xively.h>




char ssid[] = "Bradley's MacBook Pro"; //  your network SSID (name) 

int status = WL_IDLE_STATUS;



// Your Xively key to let you upload data
char xivelyKey[] = "59R27Z3NsNcAoqXfH7mRk4zvj09Geq4HikI4dW4ODFBGvsWl";

// Analog pin which we're monitoring (0 and 1 are used by the Ethernet shield)
int sensorPin = A2;

// Define the strings for our datastream IDs
char sensorId[] = "sensor1";
XivelyDatastream datastreams[] = {
  XivelyDatastream(sensorId, strlen(sensorId), DATASTREAM_FLOAT),
};
// Finally, wrap the datastreams into a feed
XivelyFeed feed(419105219, 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(9600);
  
  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);
    // wait 10 seconds for connection:
    delay(10000);
  } 
  Serial.println("Connected to wifi");
  printWifiStatus();
}

void loop() {
  
  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);
}

I then upload my code to my Arduino and the program runs. However, the following is shown in the serial monitor:

Attempting to connect to SSID: Bradley's MacBook Pro
Connected to wifi
SSID: Bradley's MacBook Pro
IP Address: 10.0.2.3
signal strength (RSSI):-32 dBm
Read sensor value 775.00
Uploading it to Xively
xivelyclient.put returned -1

Read sensor value 775.00
Uploading it to Xively
xivelyclient.put returned -1

Read sensor value 775.00
Uploading it to Xively
xivelyclient.put returned -1

Read sensor value 775.00
Uploading it to Xively
xivelyclient.put returned -1

Read sensor value 775.00
Uploading it to Xively
No Socket available
xivelyclient.put returned -1

So every time it is returning -1, and also it begins to say there is No Socket available. The data does not appear in Xively.

If anyone has any clues to where I have gone wrong in my code that would be great, I've been plugging away for a while now and can't seem to work it out.

Many thanks,
Brad

What IDE version are you using? I hear versions later than v1.0.3 possibly have a bug that prevents a connection.

I have helped a few users here that have downgraded to IDE v1.0.2 and the Wifi shield started working. Like this one:
http://forum.arduino.cc/index.php?topic=176094.0

edit: I forgot to mention the SD card slot. If you have a SD card in the slot, remove it.

I didn't have an SD card in, so I ruled that out.

I just downloaded IDE 1.0.2. (I was using 1.0.5.) and now it works just fine! Thanks so much, I thought I had gone mad! Your help is much appreciated.

Changing the IDE could be a fluke. I have recently had problems sending data to Xively that had been working fine for weeks.

Here is a chance to test the IDE versions if Bradeley still has v1.0.5 installed. Recompile the now known good code with v1.0.5. If it works, changing versions was a fluke. If it fails, then it is an IDE version problem.

The issue is that the firmware needs an upgrade if you are using v1.0.5.

Says it on the top of that page I must have missed it before!