Question

I'm doing a project involving uploading data wirelessly, from an analog sensor. In this case it is a light sensor.

I am using an Arduino Uno R2, and an official Arduino Wi-Fi Shield. Below is my code:

#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[] = "SOP7lASYJVcRecV98zlHosDc9nLIAXqnDnIxRnXAmNeKorIk";

// Analog pin which we monitor (0 and 1 are used by the Ethernet shield)
int sensorPin = 2;

// Define the strings for our datastream IDs
char sensorId[] = "light";
XivelyDatastream datastreams[] = {
  XivelyDatastream(sensorId, strlen(sensorId), DATASTREAM_FLOAT),
};
// Finally, wrap the datastreams into a feed
XivelyFeed feed(1125419529, 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);
}

However unfortunately every time I get this back in serial:

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):-20 dBm
Read sensor value 1023.00
Uploading it to Xively
xivelyclient.put returned -1

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

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

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

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

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

I noticed that after a few attempted it started to say No Socket available.

Does anyone have any clues as to where I've gone wrong?

Was it helpful?

Solution

I have resolved this problem. The issue is that I was using Arduino IDE 1.0.5 and there is a bug in that which prevents Wi-Fi communication. I have now changed to using an earlier IDE 1.0.2 and everything is running perfectly.

OTHER TIPS

Even if you change IDE version to 1.0.2 , for few months it worked fine. If this problem occurs again, consider upgrading Wifi Shield Firmware . Latest package availble in Arduino site.It solved the error

Steps to follow for ugrading: 1. Download and install Flip from here. http://www.atmel.com/tools/FLIP.aspx You don't need to use or run the Flip program. There is a sub-program in the download you will need to use later. You will get to this sub-program (batchslip.exe) using a DOS command prompt. There is also a driver for the chip on the WiFi Shield (AT32UC3A or AT32UC3A DFU) that you will need.

  1. If you recently installed a version of Arduino onto your computer, the software you need to update the WiFi Shield is in the Arduino directory structure. I know this to be true for me when I recently installed Arduino Version 1.0.5. (You might need to install a current version).

  2. Connect your WiFI Shield to the Uno board. Put the jumper across both pins on 'DFU Programming Jumper'. Shown on 4th picture of the WiFi Shield on this page: ? http://arduino.cc/en/Main/ArduinoWiFiShield To find the picture of the jumper, look for the words and arrow pointing to the board " DFU programming jumper (only used for updating shield firmware, leave unconnected for typical use)".

  3. Connect power to your Arduino. Then connect a mini USB to the WiFi shield (not a micro-USB) and your computer.

  4. Hopefully your Windows Device manager will show AT32UC3A DFU under "Other Devices". You may have to play with plugging/ unplugging power to Arduino and also the WiFI Shield's USB port connected to your computer. One time I had luck by not powering the Arduino and only plugging in the USB mini between computer and the WiFi Shield.

  5. Right-Click on the device in 'Device Manager' and select "Update Driver" . I chose to install from my computer and directed the Device Installer application to Install from... C:\Program Files (x86)\Atmel\Flip 3.4.7 . I had an option to click "Include Subdirectories'. Sorry, I am not certain what sub-folder the driver might actually be in. When this step is complete, The AT32UC3A DFUshould be properly listed in Device Manager under "Atmel USB Devices".

  6. Open a command prompt and navigate to the directory where "batchslip.exe" was installed by Flip. For me it was C:\Program Files (x86)\Atmel\Flip 3.4.7\bin ...but it depends where the Atmel software is installed and what version you download.

  7. Once you are in the directory ( C:\Program Files (x86)\Atmel\Flip 3.4.7\bin) , you will need to run two commands. You will need to determine where you initially installed your Arduino software. I installed mine in C:\Arduino instead of the recommended lengthy folder suggested ( * something like C:\Arduino 1.0.5.) .. Therefore you might need to adjust the directory structure in the two commands I have listed below. I suggest Cut and paste the first command from below, then make it match your * Arduino folder name. You may have to dump the following command in to a notepad or something to make sure there are no line breaks. Make the path as small as possible. Don't paste Arduino folder in program files while upgrading,because if path has Program Files (x86) ,spaces in between words will create un necessary error like : missing arguments " c:\Program Files (x86)\Atmel\Flip 3.4.7\bin>batchisp.exe -device AT32UC3A1256 -hardware usb -operation erase f memory flash blankcheck loadbuffer c:\Arduino\hardware\arduino\firmwares\wifishield\binary\wifi_dnld.elf program verify start reset 0 "

    Here is what you should see on the command line..........

Running batchisp 1.2.5 on Sat May 10 21:16:01 2014

AT32UC3A1256 - USB - USB/DFU

Device selection....................... PASS Hardware selection..................... PASS Opening port........................... PASS Reading Bootloader version............. PASS 1.0.2 Erasing................................ PASS Selecting FLASH........................ PASS Blank checking......................... PASS 0x00000 0x3ffff Parsing ELF file....................... PASS c:\Arduino\hardware\arduino\firmwares\wifishield\binary\wifi_dnld.elf WARNING: The user program and the bootloader overlap! Programming memory..................... PASS 0x00000 0x2902b Verifying memory....................... PASS 0x00000 0x2902b Starting Application................... PASS RESET 0

Summary: Total 11 Passed 11 Failed 0

c:\Program Files (x86)\Atmel\Flip 3.4.7\bin>

  1. Now to update the second piece Cut and paste the command from below. You may have to dump it in to a notepad or something to make sure there are no line breaks. " c:\Program Files (x86)\Atmel\Flip 3.4.7\bin>batchisp.exe -device AT32UC3A1256 -hardware usb -operation erase f memory flash blankcheck loadbuffer c:\Arduino\hardware\arduino\firmwares\wifishield\binary\wifiHD.elf program verify start reset 0
    "

Press Enter

Here is what will happen on your screen..

Running batchisp 1.2.5 on Sat May 10 21:34:04 2014

AT32UC3A1256 - USB - USB/DFU

Device selection....................... PASS Hardware selection..................... PASS Opening port........................... PASS Reading Bootloader version............. PASS 1.0.2 Erasing................................ PASS Selecting FLASH........................ PASS Blank checking......................... PASS 0x00000 0x3ffff Parsing ELF file....................... PASS c:\Arduino\hardware\arduino\firmwares\wifishield\binary\wifiHD.elf WARNING: The user program and the bootloader overlap! Programming memory..................... PASS 0x00000 0x3fe2b Verifying memory....................... PASS 0x00000 0x3fe2b Starting Application................... PASS RESET 0

Summary: Total 11 Passed 11 Failed 0

c:\Program Files (x86)\Atmel\Flip 3.4.7\bin>

  1. Remove the Jumper from the WiFi Card. Remove the Min USB.

  2. Verify Wifi shield with any sketch.


This method really solved the No Socket available issue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top