[Solved] Arduino WiFi Sheild- Unable to connect

Hi,
I am making a project to monitor certain parameters on xively.

I am using:

  • Arduino 1.0.5 r-2 I.D.E.
  • Arduino uno R3
  • Arduino wifi shield with WiFi firmware version: 1.1.0. (upgraded firmware to last version).

My Sheild was working good just had a issue that after 40-50 mintues it got hanged and it stop sending data on server.
I Googled and found that if i update firmware this will be fixed but after firmware update it is not sending data on server.
It is not able to connect also.
All happened after updating the firmware.
I updated it from the file on arduino website but my shield is not working after successfull firmware update.
Can i get the firmware which was originally programmed in the wifi shield.

/*
  Wifi Xively sensor client with Strings
 
 This sketch connects an analog sensor to Xively (http://www.xively.com)
 using a Arduino Wifi shield.

 This example is written for a network using WPA encryption. For
 WEP or WPA, change the Wifi.begin() call accordingly.
 
 This example has been updated to use version 2.0 of the xively.com API. 
 To make it work, create a feed with a datastream, and give it the ID
 sensor1. Or change the code below to match your feed.

 This example uses the String library, which is part of the Arduino core from
 version 0019.

 Circuit:
 * Analog sensor attached to analog in 0
 * Wifi shield attached to pins 10, 11, 12, 13

 created 16 Mar 2012
 modified 31 May 2012
 by Tom Igoe
 modified 8 Sept 2012
 by Scott Fitzgerald

 This code is in the public domain.

 */

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

#define APIKEY         "***" // replace your xively api key here
#define FEEDID         1669434505                   // replace your feed ID
#define USERAGENT      "My Arduino Project"     // user agent is the project name

char ssid[] = "***";      //  your network SSID (name)
char pass[] = "***";   // your network password

int status = WL_IDLE_STATUS;

// initialize the library instance:
WiFiClient client;

// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(216,52,233,121);      // numeric IP for api.xively.com
char server[] = "api.xively.com";   // name address for xively API

unsigned long lastConnectionTime = 0;          // last time you connected to the server, in milliseconds
boolean lastConnected = false;                 // state of the connection last time through the main loop
const unsigned long postingInterval = 10*1000;  //delay between updates to xively.com

void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while (true);
  }

  String fv = WiFi.firmwareVersion();
  if ( fv != "1.1.0" )
    Serial.println("Please upgrade the firmware");

  // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }
  // you're connected now, so print out the status:
  printWifiStatus();
}

void loop() {
  // read the analog sensor:
  int ldr = analogRead(A0);
  // convert the data to a String to send it:

  String dataString = "LDR,";
  dataString += ldr;

  // you can append multiple readings to this String if your
  // xively feed is set up to handle multiple values:
 // int otherldr = analogRead(A1);
  //dataString += "\nsensor2,";
  //dataString += otherldr;

  // if there's incoming data from the net connection.
  // send it out the serial port.  This is for debugging
  // purposes only:
  while (client.available() && status == WL_CONNECTED) {
    char c = client.read();
    Serial.print(c);
  }

 client.flush();
   client.stop();
   
   
  // if there's no net connection, but there was one last time
  // through the loop, then stop the client:
  if (!client.connected() && lastConnected) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
  }

  // if you're not connected, and ten seconds have passed since
  // your last connection, then connect again and send data:
  if (!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
    sendData(dataString);
  }
  // store the state of the connection for next time through
  // the loop:
  lastConnected = client.connected();
}

// this method makes a HTTP connection to the server:
void sendData(String thisData) {
  // if there's a successful connection:
  if (client.connect(server, 80)) {
    Serial.println("connecting...");
    // send the HTTP PUT request:
    client.print("PUT /v2/feeds/");
    client.print(FEEDID);
    client.println(".csv HTTP/1.1");
    client.println("Host: api.xively.com");
    client.print("X-ApiKey: ");
    client.println(APIKEY);
    client.print("User-Agent: ");
    client.println(USERAGENT);
    client.print("Content-Length: ");
    client.println(thisData.length());

    // last pieces of the HTTP PUT request:
    client.println("Content-Type: text/csv");
    client.println("Connection: close");
    client.println();

    // here's the actual content of the PUT request:
    client.println(thisData);
  }
  else {
    // if you couldn't make a connection:
    Serial.println("connection failed");
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
  }
  // note the time that the connection was made or attempted:
  lastConnectionTime = millis();
}


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");
}

O/P of Serial Monitor

Please upgrade the firmware
Attempting to connect to SSID: ****
SSID: ****
IP Address: 192.168.1.21
signal strength (RSSI):-66 dBm
connection failed

disconnecting.
connection failed

disconnecting.
connection failed

disconnecting.
connection failed

disconnecting.
connection failed

xively.ino (5.35 KB)

If it says please update the firmware then you didn't update it

I have upgraded the latest firmware from 1.0.6 version of Arduino I.D.E

Insure the ssid and pass phrase is correct. They are case sensitive.

The SSID and the password are right and it connects to wifi also the green led is continuously on, wifi shield is connected.
The same code was working fine before firmware update, after update it is not working with the same code.
Can i get the firmware which is originally programmed in this wifi shield.

amirchaudhary:
The SSID and the password are right and it connects to wifi also the green led is continuously on, wifi shield is connected.
The same code was working fine before firmware update, after update it is not working with the same code.
Can i get the firmware which is originally programmed in this wifi shield.

If it was working before the upgrade, and isn't now, you must be programming with an IDE (or wifi library) prior to v1.0.4. To use the wifi shield after the upgrade, I recommend IDE v1.0.5 or higher. Using IDE v1.0.5, the wifi shield would not have connected to any server until you upgraded the firmware.

This is presuming you are meaning "unable to connect" is unable to connect to a server, not the wireless network, right?

edit: Try this code. Does it display the firmware version you expect? It should show 1.1.0.

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

void setup() {
  Serial.begin(9600); 

  // disable SD SPI
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present"); 
    // don't continue:
    while(true);
  } 

  // check firmware version
  Serial.print(F("Firmware version: "));
  Serial.println(WiFi.firmwareVersion());.
}

void loop() {
}

I had installed Arduino 1.0.5 -r2 version previously and it worked fine before firmware updation.

This is presuming you are meaning "unable to connect" is unable to connect to a server, not the wireless network, right?
Yes, the shield was able to connect the wifi network the green led was constantly on but it didnt sent any data nor it received.

Today i uninstalled arduino cleaned all files and downloaded latest arduino ide 1.0.6 downloaded latest libraries for xively.
Then updated the wifi firmware from the arduino wifi firmware folder of arduino 1.0.6 version and tried your sketch to check version it displayes

Firmware version: 1.0.0

The firmware was successfully programmed i am attaching the printscreen for the cmd.

Then i checked for one of the xively sketch( WiFiDatastreamUpload )to upload data from the examples i am attaching the codes also.
But it didnt worked

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

char ssid[] = "hitechfone"; //  your network SSID (name) 
char pass[] = "hitech";    // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0;            // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;

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

// 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[] = "sensor_reading";
XivelyDatastream datastreams[] = {
  XivelyDatastream(sensorId, strlen(sensorId), DATASTREAM_FLOAT),
};
// Finally, wrap the datastreams into a feed
XivelyFeed feed(1669439404, 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, pass);
    // 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);
}

The Serial Monitor displays

Starting single datastream upload to Xively...

Attempting to connect to SSID: hitechfone
Connected to wifi
SSID: hitechfone
IP Address: 192.168.1.20
signal strength (RSSI):-59 dBm
Read sensor value 470.00
Uploading it to Xively
xivelyclient.put returned -1

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

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

Read sensor value 256.00
Uploading it to Xively

Your thread title implies that you are not able to connect to any server, once the shield connects to the network.

Your code, and output, state that you are unable to send any data to xively. Why do you assume that this means that the WiFi shield is at fault, or that the WiFi library is at fault?

  int sensorValue = analogRead(sensorPin);
  datastreams[0].setFloat(sensorValue);

Is it just me, or does anyone else think this looks stupid? Why are you using a float data stream to store integers?

Have you tried debugging the xivelyclient instance? If not, why not?

If firmwareVersion reports v1.0.0, then the firmware upgrade didn't work. It should report v1.1.0.

Your thread title implies that you are not able to connect to any server, once the shield connects to the network.
Yes i am able to connect to network but not able to connect xively

Your code, and output, state that you are unable to send any data to xively. Why do you assume that this means that the WiFi shield is at fault, or that the WiFi library is at fault?
When my codes were not working so downloaded arduino ide 1.0.6. and this is the code from the samples in the ide
I took the codes from the ide to ensure the coding part is not wrong. but still not able to connect.

I had downloaded many firmware from github but after successfull update also as mentioned in the wifi firmware update method on arduino website it still show version 1.0.0 . I have attached successful firmware update also in the old post.
Got confused which to belive as latest firmware so downloaded new ide 1.0.6 and updated the firmware from it but no progress.
Please provide the latest firmware or the firmware which was orignallly programmed in the shield.

Are you using Windows to do the upgrade? It will be a couple hours before I can get to my Windows box.

Here is one of my posts that has what I did to upgrade.
http://forum.arduino.cc/index.php?topic=216104.msg1580246#msg1580246

I attached the files I used. I put them in the C: root directory to make it easy to enter the commend line upgrade as in the link above.

Here is a link from a user that did the upgrade and posted the output of the upgrade.
http://forum.arduino.cc/index.php?topic=244963.msg1757298#msg1757298

wifi_dnld.elf (178 KB)

wifiHD.elf (707 KB)

I downloaded these two firware update files and overwritten these inside the arduino folder as per the path in the arduio firmware update method.
After a successful update i checked the version is shows Firmware 1.0.0
.
Yes I am using Windows 7 to update the firmware this is not proper or wat.
Its still not working
I followed the method as per this link

and it was successfully programmed.
I have updated many firmwares but all shows only 1.0.0.
I even downloaded new arduino ide 1.0.6 and upgraded firmware but then also it shows firmware 1.0.0.
Is there something like firmware is not upgraded but i can see in cmd that firmware is updated.

I got a link to update the shield while the shield fixed on aruino uno
http://forum.arduino.cc/index.php/topic,155414.0.html
As as note on arduino firmware link it is mentioned not to update the firmware with wifi shield attached to arduino uno.

At the bottom of this link i got another link
http://www.dfrobot.com/community/how-to-upgrade-arduino-wifi-shield-firmware-on-windows.html
Should i try this but i fear of my module if they got damaged.

After a successful update i checked the version is shows Firmware 1.0.0

Then it was not a successful upgrade. After the upgrade, it should show 1.1.0.

I followed the method as in the firmware upgrading link of arduino

and the board reacts in the same way as in the link.
After the updating first file the blue led stays on then reset , replug and burn the next file.
Is there any other way to upgrade it
The files u gave are of version 1.1.0??

Should i try for this
http://www.dfrobot.com/community/how-to-upgrade-arduino-wifi-shield-firmware-on-windows.html
but will this damage by shield or arduino ?? as it is mentioned not to update shield while connected to arduonio uno

The files u gave are of version 1.1.0??

Yes.

I left my (PaulS's) shield connected to my Mega during the upgrade, but I'm not sure it matters.

Are you using the Atmel FLIP software for your upgrade? I recommended putting those two files in your C: directory. Did you do that? Did your display look like this?

C:\Program Files (x86)\Atmel\Flip 3.4.7\bin>batchisp.exe -device AT32UC3A1512 -hardware usb -operation erase f memory flash blankcheck loadbuffer c:\wifiHD.elf program verify start reset 0
Running batchisp 1.2.5 on Sun Jun 08 09:50:56 2014

AT32UC3A1512 - 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 0x7ffff
Parsing ELF file....................... PASS c:\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>batchisp.exe -device AT32UC3A1512 -hardware usb -operation erase f memory flash blankcheck loadbuffer c:\wifi_dnld.elf program verify start reset 0
Running batchisp 1.2.5 on Sun Jun 08 09:51:37 2014

AT32UC3A1512 - 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 0x7ffff
Parsing ELF file....................... PASS c:\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>

yes both are same i am attaching the cmd
I checked the arduino firmware updating link they have mentioned to program wifi_dnld.elf first then wifiHD.elf but as i can see u have programmed the other way out first wifiHD.elf then wifi_dnld.elf

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    /Arduino/hardware/arduino/firmware/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\Atmel\Flip 3.4.7\bin>batchisp.exe -device AT32UC3A1256 -hardware usb -operation erase f memory flash blankcheck loadbuffer /Arduino/hardware/arduino/firm
ware/wifishield/binary/wifiHD.elf program verify start reset 0
Running batchisp 1.2.5 on Wed Oct 01 16:50:23 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    /Arduino/hardware/arduino/firmware/wifishield/binary/wifiHD.elf
WARNING: The user program and the bootloader overlap!
Programming memory..................... PASS    0x00000 0x3f01b
Verifying memory....................... PASS    0x00000 0x3f01b
Starting Application................... PASS    RESET   0

Summary:  Total 11   Passed 11   Failed 0

C:\Program Files\Atmel\Flip 3.4.7\bin>