I've been working on this all day and can't seem to figure out the problem. I'm running an official arduino wifi shield with an arduino mega 2560 running 1.0.5. I can connect to the internet, but can't seem to upload/download anything from Xively. Here is the error message:
Starting single datastream upload to Xively...
Attempting to connect to SSID: LLKGQ
Connected to wifi
SSID: LLKGQ
IP Address: 192.168.1.5
signal strength (RSSI):-50 dBm
HTTP Error
Read sensor value 452.00
Uploading it to Xively
xivelyclient.put returned -1
/*
##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 <SPI.h>
#include <WiFi.h>
#include <HttpClient.h>
#include <Xively.h>
char ssid[] = "<security snip>"; // your network SSID (name)
char pass[] = "<security snip>"; // your network password (use for WPA, or use as key for WEP)
//int keyIndex = 2; // your network key Index number (needed only for WEP)
int status = WL_IDLE_STATUS;
// Your Xively key to let you upload data
char xivelyKey[] = "<security snip>";
//your xively feed ID
#define xivelyFeed <security snip>
//datastreams
//char sensorID[] = "Temperature";
char ledID[] = "LED";
// 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 \n");
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
//pin setup
// pinMode(sensorPin, INPUT);
pinMode(ledPin, OUTPUT);
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 10 seconds for connection:
delay(10000);
}
Serial.println("Connected to wifi");
printWifiStatus();
}
void loop() {
//adjust LED level. set from Xively
int getReturn = xivelyclient.get(feed, xivelyKey); //get data from xively
if(getReturn > 0){
Serial.println("LED Datastream");
Serial.println(feed[1]);
}else Serial.println("HTTP Error");
//write value to LED - change brightness
int level = feed[1].getFloat();
if(level < 0){
level = 0;
}else if(level > 255){
level = 255;
}
//actually write the value
digitalWrite(ledPin, level);
///////////////////////////////////////////////////////
//read sensor values
int sensorValue = analogRead(sensorPin);
datastreams[0].setFloat(sensorValue);
//print the sensor valye
Serial.print("Read sensor value ");
Serial.println(datastreams[0].getFloat());
//send value to xively
Serial.println("Uploading it to Xively");
int ret = xivelyclient.put(feed, xivelyKey);
//return message
Serial.print("xivelyclient.put returned ");
Serial.println(ret);
Serial.println("");
//delay between calls
delay(15000);
}
If you get an error, why are you executing all this code anyway?
//write value to LED - change brightness
int level = feed[1].getFloat();
if(level < 0){
level = 0;
}else if(level > 255){
level = 255;
}
//actually write the value
digitalWrite(ledPin, level);
///////////////////////////////////////////////////////
//read sensor values
int sensorValue = analogRead(sensorPin);
datastreams[0].setFloat(sensorValue);
//print the sensor valye
Serial.print("Read sensor value ");
Serial.println(datastreams[0].getFloat());
//send value to xively
Serial.println("Uploading it to Xively");
int ret = xivelyclient.put(feed, xivelyKey);
//return message
Serial.print("xivelyclient.put returned ");
Serial.println(ret);
Serial.println("");
getReturn contained a value. Perhaps there's a clue in the value that you ignore.
I know that is where the problem is, but don't know how to fix it. The code is slightly modified from the example found in the Xively library. Can you give me some insight into what that means and how I can fix it?
I've spent a week on this and have not solved it. I've updated the firmware on my Arduino WiFi Shield that I use on an Uno. I've reverted back to Arduino 1.0.2. I've read dozens of posts and fixes and I'm still stuck. I've mixed and matched and tweaked sketches for 5 days now and I still get:
HTTP Error
Read sensor value 165.00
Uploading it to Xively No Socket available xivelyclient.put returned -1." Below is my Sketch and Monitor data
I'm not a programmer but I'm not completely a noob either. I just can see what's causing the problem.
/*
##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[] = "nvision4d"; // your network SSID (name)
char pass[] = "xxxxxxxx"; // your network password (use for WPA, or use as key for WEP)
int status = WL_IDLE_STATUS;
//int keyIndex = 0; // your network key Index number (needed only for WEP)
//int sensorPin = 0;
// Your Xively key to let you upload data
char xivelyKey[] = "wrhwFnr97jtGvLnxxxxxxxxxxxxVWVt9sEgdbx6C4Vqvs";
//your xively feed ID
#define xivelyFeed 35xxxx761
//datastreams
//light Channel
char sensorID[] = "light";
//led Channel;
char ledID[] = "led";
// 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, 2); /* 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);
//pin setup
pinMode(sensorPin, INPUT);
pinMode(ledPin, OUTPUT);
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, keyIndex, pass);
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
}
Serial.println("Connected to wifi");
printWifiStatus();
}
void loop() {
//adjust LED level. set from Xively
int getReturn = xivelyclient.get(feed, xivelyKey); //get data from xively
if(getReturn > 0){
Serial.println("LED Datastream");
Serial.println(feed[1]);
}else Serial.println("HTTP Error");
//write value to LED - change brightness
int level = feed[1].getFloat();
if(level < 0){
level = 0;
}else if(level > 255){
level = 255;
}
//actually write the value
digitalWrite(ledPin, level);
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);
}
////////////////////////Serial Monitor Data Below////////////
Starting single datastream upload to Xively...
Attempting to connect to SSID: nvision4d
Connected to wifi
SSID: nvision4d
IP Address: 192.168.1.6
signal strength (RSSI):-44 dBm
HTTP Error
Read sensor value 165.00
Uploading it to Xively
xivelyclient.put returned -1
HTTP Error
Read sensor value 164.00
Uploading it to Xively
xivelyclient.put returned -1
No Socket available
HTTP Error
Read sensor value 165.00
Uploading it to Xively
No Socket available
xivelyclient.put returned -1
No Socket available
HTTP Error
Read sensor value 164.00
Uploading it to Xively
No Socket available
xivelyclient.put returned -1
Did you figure it out yet? I had the same problem all day. I finally figured out how to update firmware. I made a few other adjustments aswell. I changed the analogoutput pin to 6. Also is your sensor pin on pin 0? I would change that to A0 or A2. Are you sure your firmware was I upgraded? That's what solved it for me. Let me know how its going.
Hey, thanks for checking in. Yes, I did finally resolve it but forgot exactly what I did. It was probably at 3AM one night that I fixed it back in December. I've that the device in my boat for 3 months now and it works like a charm. The power has gone on and off many times in the marina and it always connects right back to the router.
To recall though, I believe it was a combination of reverting my firmware back and finding some corrupt code left over from the firmware 'upgrade' in one of my folders. But, all is good now.
Ok good, I made a long tutorial with pictures so I wouldn't forget how to update firmware or connect to xively in the future. Let me know if you need it.
I'm always happy to hold onto a good tutorial. I save them all the them. They are useful when 6-months have gone by and you forgot about those 3-days in hell when you figured out how to do something... If it's handy I'll be glad to take it for reference as I'm sure sometime later this year I'll get back to more Arduino tinkering.