Everything seems fine but arduino won't reach internet


I have my Wifi Shield, which seems to be working properly (it connects to wifis and i've used it before as a webserver), but I can't reach a website. I want Arduino to do a GET against a public server I own to store temperatures but it just won't connect. I've tried other servers, I even tried the simplest thing (using the untouched example of WifiWebClient that comes with the software) and it never connects.

It says Starting connection to server... and after a few seconds: disconnecting from server. Which makes me think that client.connect(server, 80) is failing.
I've tried "server" as a char[] with the URL, and also as an "IPAddress server(74,125,132,94)" just in case it's a DNS thing...but same results.

Any idea? Thanks!

Any idea?

The usual one, for posts in the Programming section. Where is your code?

As I said, i have the same problem with the default "WiFiWebClient" that comes with the Arduino suite, so i don't think there's a code problem there. I can paste it anyway for reference (I only edited my wifi login info):

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

char ssid[] = "myssid"; //  your network SSID (name) 
char pass[] = "mypass";    // 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;
// 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,132,94);  // 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:
  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:
  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) { 
    Serial.print("Attempting to connect to 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:
  Serial.println("Connected to wifi");
  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");

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

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

    // do nothing forevermore:

void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.println(" dBm");

By the way, I just tried another default sketch example (WifiWebServer) just to try and I can't connect to it! When I try, chrome says Error 101 (net::ERR_CONNECTION_RESET)

What does the "IP Address:" show when you start the Arduino?

It shows a seemingly correct IP ( giving my router settings, and checking my router admin page it shows arduino connected as a wifi device.

I've just now tried using my android as an AP just to rule out router problems... but same result :frowning:

Does your router have a html setup page? Should be
Can you connect to that ip with the Wifi shield?

Same result, client.connect(server, 80) returns 0.

Is there a way to get a more verbose error message?

You said the web server example works? I've helped others with WiFi shield code, and it seems to do ok as a client.
What version IDE are you using?

edit: There does not seem to be any more detailed error checking, except if the shield runs out of sockets, it should display a "No Socket available" serial message. Otherwise, for all other errors, it just returns 0. This is the connect function from WiFiClient.cpp.

int WiFiClient::connect(IPAddress ip, uint16_t port) {
    _sock = getFirstSocket();
    if (_sock != NO_SOCKET_AVAIL)
    	ServerDrv::startClient(uint32_t(ip), port, _sock);
    	WiFiClass::_state[_sock] = _sock;

    	unsigned long start = millis();

    	// wait 4 second for the connection to close
    	while (!connected() && millis() - start < 10000)

    	if (!connected())
    		return 0;
    	Serial.println("No Socket available");
    	return 0;
    return 1;

By the way, I just tried another default sketch example (WifiWebServer) just to try and I can't connect to it! When I try, chrome says Error 101 (net::ERR_CONNECTION_RESET)

I don't think I'm good enough in C/C++ to write a verbose version of WiFiClient.cpp ... What to do?

Sounds like a firmware or library problem. Someone else may recognize the symptoms and know what you should do.
What version IDE are you using? That seems to be an issue in some cases, just by a quick forum search.

Uhmm... I've never changed the firmware (yet). But it's true that if i recall correctly when the WiFiWebServer worked it was before my last PC reinstall so maybe I now have a different IDE version (which now i'm using 1.0.5).

Well, it seems that you got it right! I downloaded and tried Arduino 1.0.2, using the WifiWebClient sketch example and it works perfectly fine now. So I guess I'll stick with this version from now on...