SOLVED - Problem with WifiShield and webclient example. Gateway always...

Hi there!
I am a bit disappointing with official arduino Wifishiled and I am having a lot of problems with it.
After upgrading the firmware I find that I can not complete the most simple “Wifi web client” sketch → http://arduino.cc/en/Reference/WiFiClient
I always get “connection failed” when try to connect to google IP (74.125.115.105) and port 80. In fact to any IP (internal or external).

Some data:

  • Arduino uno Rev.3
  • Official Wifi Shield upgraded to latest firmware
  • Arduino IDE 1.5.5
  • Wifi connects ok to my network and I can ping arduino

Process:

  • It connects to wifi ok
  • I have configured on my router one DHCP server, so by his MAC the wifishield always get 192.168.1.23 and it is pingable
  • But it can no connect to any web client, even if I specify the Google IP as the above example shows and not the FQDN.
  • It always get connection failed
  • I can see that in WiFi.gatewayIP(); variable it always get 0.0.0.0 as gateway. ?? =(
  • If a try to specify gateway, dns, netmask, etc with WiFi.config(ip, dns, gateway, subnet); before WiFi.begin; It fails to connect to wifi.

I see that more people are having this problem with arduino WifiShiled.

As you can see my sketch is pretty simple:

// http://arduino.cc/en/Reference/WiFiClient
#include <SPI.h>
#include <WiFi.h>

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

int status = WL_IDLE_STATUS;
IPAddress server(74,125,115,105);  // Google IP
IPAddress gateway;                 // Variable to store gateway IP

// Initialize the client library
WiFiClient client;

void setup() {
  
  Serial.begin(9600);
  Serial.println("Attempting to connect to WPA network...");
  Serial.print(ssid);
  
  status = WiFi.begin(ssid, pass);
  
  if ( status != WL_CONNECTED) { 
    Serial.println("Couldn't get a wifi connection");
    // don't do anything else:
    while(true);
  } 
  else {
    Serial.println("Connected to wifi");
    
    // print gateway IP:
    gateway = WiFi.gatewayIP();
    Serial.print("Gateway IP is: ");
    Serial.println(gateway);
    
    Serial.println("\nStarting connection...");
    // if you get a connection, report back via serial:
    if (client.connect(server, 80)) {
      Serial.println("connected");
      // Make a HTTP request:
      client.println("GET /search?q=arduino HTTP/1.0");
      client.println();
    }
    else {
    // If you didn't get a connection to the server:
    Serial.println("connection failed");
    }
  }
}

void loop() {

}

Any help would de apreciated, because I am stalled on my project.

Thank you very much for your time

I checked your code, and mine works fine. It shows the gateway as 192.168.0.1, which is correct.

Two possibilities: 1) Your firmware upgrade didn't work. 2) Your dhcp server is not issuing a gateway.

Add this code to your sketch after the Serial.begin() call. It should show version 1.1.0 if all went well with your upgrade.

  // 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());

Thank you. Regarding Dhcp server I know it is working ok so my other network devices are taking gateway, dns and domain name correctly. About firmware upgrade is there any way to probe if it was done correctly or minimal sketch to show what version is using?

Regrads,

mmmm, in fact if I try to specify network settings with WiFi.config(ip, dns, gateway, subnet); like the doc suggest:
http://arduino.cc/en/Reference/WiFiConfig

// http://arduino.cc/en/Reference/WiFiClient
#include <SPI.h>
#include <WiFi.h>

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

IPAddress ip(192, 168, 1, 23);
IPAddress dns(8, 8, 8, 8);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
int status = WL_IDLE_STATUS;
IPAddress server(74,125,115,105);  // Google IP
IPAddress check_gateway;           // Variable to store gateway IP

// Initialize the client library
WiFiClient client;

void setup() {
  
  Serial.begin(9600);
  Serial.println("Attempting to connect to WPA network...");
  Serial.print(ssid);
  
  WiFi.config(ip, dns, gateway, subnet);
  
  status = WiFi.begin(ssid, pass);
  
  if ( status != WL_CONNECTED) { 
    Serial.println("Couldn't get a wifi connection");
    // don't do anything else:
    while(true);
  } 

etc etc

Wifi does not connect…
If I comment that WiFi.config(ip, dns, gateway, subnet); sentence it works
What is happening here?

Some routers are very picky about the static ip assignment. Mine aren't, so it doesn't really affect me if I use an IP within the dhcp range. My router will ping the dhcp ip it is about to issue, and if it gets a response, it marks that ip as "busy" and issues another ip.

If your router is not that flexible, it may not communicate with a static ip assignment within its dhcp range. Check your router and insure the ip you are using is not in the dhcp range.

I am a bit disappointing with official arduino Wifishiled and I am having a lot of problems with it.

The lack of knowledge normally tend to blame the material at first place.

If I comment that WiFi.config(ip, dns, gateway, subnet); sentence it works

So if it works it means the wifi card is in fact receiving ip and network parameters via DHCP right?

HugoPT: So if it works it means the wifi card is in fact receiving ip and network parameters via DHCP right?

Yes. that is the main problem. If I use only WiFi.begin(ssid, pass); it connects to the wifi, DHCP server gives to him 192.168.1.23 IP address, but I always get that gateway is 0.0.0.0 and it does not connect to any web server (google.com Ip for ex). Obviously ardunio is not finding the gateway to go out. And if I try to specific the gateway and the network parameters with WiFi.config(p, dns, gateway, subnet); wifi simple does not connect.

WiFi.firmwareVersion() shows that I have 1.1.0 version, and I am sure that it is not DHCP server because I have in my home more than 10 devices (pc, laptop, smartphnes, tablets) all of them giving correctly by DHCP his IP, netmask and gateway adresses. So I think I can discard that part.

So really, that was because I was blaming to wifishiled, but I don't discard the problem is between the chair and arduino of course :roll_eyes:

It could be useful to download WireShark and watch the network traffic as the DHCP server offers an IP to your system. You would see whether the gateway is part of the offer or not and thus know where it gets lost.

First, thank you for all your answers and time. After read the wifishiled doc I found that I was using wifishiled pin 7 for other purposses, and that pin should not be used, as it is reserved for handshake between arduino and wifishield. After stop using that pin 7, all worked smoothly (wifi.config, webclient, etc).

HugoPT: The lack of knowledge normally tend to blame the material at first place.

You were right Hugo, problem was for not to read in further deep all the wifishiled documentation. I will keep it in mind for next time before surrender ;)

So thanks and my apologies.