WiFiWebClient

Hi everyone,

I just got the official Arduino Wifi Shield. I can successful connect to a wifi network but can't load a simple website like Google. I copied it straight from the example but changed my WiFI information. What do I need to do to get it work? Any help would be greatly appreciated!

The serial monitor response I get is as follows:
Attempting to connect to SSID: Network
Connected to WiFi Network!
SSID: Network
IP Address: 10.0.0.19
Signal Strength (RSSI):-45 dBm

Starting connection to server...
failed to connect!

disconnecting from server.

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

char ssid[] = "Network";     //  your network SSID (name) 
char pass[] = "Password";    // your network password
int keyIndex = 0;            // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;
// 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(74,125,232,128);  // numeric IP for Google (no DNS)
char server[] = "www.google.com";    // name address for Google (using DNS)

// Initialize the Ethernet client library
// with the IP address and port of the server 
// that you want to connect to (port 80 is default for HTTP):
WiFiClient client;

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);
  } 
  
  // 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);
  } 
  Serial.println("Connected to WiFi Network!");
  printWifiStatus();
  
  Serial.println("\nStarting connection to server...");
  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("connected to server");
    // Make a HTTP request:
    client.println("GET /search?q=arduino HTTP/1.1");
    client.println("Host: www.google.com");
    client.println("Connection: close");
    client.println();
  } else {
    Serial.println("failed to connect!");
  }
}

void loop() {
  // if there are incoming bytes available 
  // from the server, read them and print them:
  while (client.available()) {
    char c = client.read();
    Serial.write(c);
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting from server.");
    client.stop();

    // do nothing forevermore:
    while(true);
  }
}


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

// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:

So, which DNS server are you using? Where are you telling the Arduino that?

I have tried both using the IP Address and both using DHS and both failed. I have tried these on two separate instances and not at the same time. No website is working.

IPAddress server(74,125,232,128);  // numeric IP for Google (no DNS)
char server[] = "www.google.com";    // name address for Google (using DNS)

Can you look at your WiFi router's status to see what devices are connected to it, and confirm the Arduino is actually connected?

What network are you in? 10.0.0.19 is not a standard private network address and might imply you're in a corporate network behind a proxy server which is restricting internet access. In that case, it would be easier to connect to a web server within the same network as the Arduino.

Its a home network. The IP Address is like that because its a Comcast router and thats what it comes with. I thought it was weird when I first got Comcast.

The device is getting connected and shows in the router administration. I also can access the internet through WiFi from all of the other computers connected to the same network.

Just as a sanity check, what happens if you put the wrong WiFi SSID in, or the wrong password? I'd expect the WiFi association to fail, and if you confirm that happens that proves that it isn't just an encryption/authentication issue.

I have tried. If I enter the wrong SSiD or wrong password it doesn't connect. Could it be the firmware or something like that?

Find or install a server locally that you can connect to, to eliminate the internet part of the problem. A web server would be the most obvious one to go for since that would be useful for testing your web client too, but at this stage it doesn't absolutely have to be a web server, just anything that will accept TCP connections.

I found out the problem. I had to downgrade the client from 1.05 to 1.02. I found this post posted earlier:

http://forum.arduino.cc/index.php?topic=196513.0