Also having trouble getting ethernet shield fully working

I’ve read many posts, including recent ones below, that sound similar to my problem, but I haven’t been able to get it going yet. I am able to ping my ethernet shield and cisco network magic shows it as ‘online’, but when I try any of the sample sketches testing the connection, like a recent one from zoomkat, I get ‘connection failed’, and the ip address doesn’t show up in my 2WIRE 3800HGV-B router listing. I’ve tried different myserver addresses, mac addresses, ip addresses, ports (80 below) without any success.

Here’s the code as I’m presently trying it.

//zoomkat 4-04-12
//simple client test
//for use with IDE 1.0
//open serial monitor and send an e to test
//for use with W5100 based ethernet shields
//note that the below bug fix may be required
// http://code.google.com/p/arduino/issues/detail?id=605 
//the arduino lan IP address { 192, 168, 1, 102 } may need 
//to be modified modified to work with your router.

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEE }; //physical mac address
byte ip[] = { 
  192, 168, 1, 104 }; // ip in lan assigned to arduino
byte gateway[] = { 
  192, 168, 1, 254}; // internet access via router
byte subnet[] = { 
  255, 255, 255, 0 }; //subnet mask
byte myserver[] = { 
  208, 104, 2, 86 }; // zoomkat web page server IP address
EthernetClient client;
//////////////////////


void setup(){

  //Ethernet.begin(mac, ip);
  Ethernet.begin(mac, ip, gateway, subnet);
  Serial.begin(9600); 
  Serial.println("Better client test 4/04/12"); // so I can keep track of what is loaded
  Serial.println("Send an e in serial monitor to test"); // what to do to test

}

void loop(){
  // check for serial input
  if (Serial.available() > 0) //if something in serial buffer
  {
    byte inChar; // sets inChar as a byte
    inChar = Serial.read(); //gets byte from buffer
    if(inChar == 'e') // checks to see byte is an e
    {
      sendGET(); // call sendGET function below when byte is an e
    }
  }  
} 

//////////////////////////

void sendGET() //client function to send/receive GET request data.
{
  if (client.connect(myserver, 80)) {  //starts client connection, checks for connection
    Serial.println("connected");
    client.println("GET /~shb/arduino.txt HTTP/1.0"); //download text
    client.println(); //end of get request
  } 
  else {
    Serial.println("connection failed"); //error message if no client connect
    Serial.println();
  }

  while(client.connected() && !client.available()) delay(1); //waits for data
  while (client.connected() || client.available()) { //connected or data available
    char c = client.read(); //gets byte from ethernet buffer
    Serial.print(c); //prints byte to serial monitor 
  }

  Serial.println();
  Serial.println("disconnecting.");
  Serial.println("==================");
  Serial.println();
  client.stop(); //stop client

}

Here’s the output:

Better client test 4/04/12
Send an e in serial monitor to test
connection failed
disconnecting.
==================
Better client test 4/04/12
Send an e in serial monitor to test
connection failed
disconnecting.
==================

Thanks in advance for any advice on what to check for this.

This is incorrect.

  Ethernet.begin(mac, ip, gateway, subnet);

In IDE v1.0, it should be

  Ethernet.begin(mac, ip, dns, gateway, subnet);

You can use the gateway for the dns server if you do not plan in using dns.

  Ethernet.begin(mac, ip, gateway, gateway, subnet);

...and the last I checked, the reference page on the ethernet shield is also incorrect.

I would be interesting to see if the sequence order of (mac, ip, dns, gateway, subnet) is actually important. These appear to be place holders for variables previously established, and I would think the code would use them as the place holder is called, and not the sequence order they listed in. Also, note that the use of dns, gateway, and subnet appear to not need to be declaired in some some instances (with no declaraton, default values may or may not be used). Do note that the OP has modified the origionally posted to meet his needs, which may not be correct. The use of “192, 168, 1, 254” as the gateway value seems suspect (but maybe that is the router’s lan ip address). I just tried the below code and at this time it works with out any issues, so not declaring dns, gateway, and subnet seems to have no negative impact to my setup. I leave these commented out in the below code as they can be a source of error if incorrectly used.

//zoomkat 4-04-12
//simple client test
//for use with IDE 1.0
//open serial monitor and send an e to test
//for use with W5100 based ethernet shields
//note that the below bug fix may be required
// http://code.google.com/p/arduino/issues/detail?id=605 
//the arduino lan IP address { 192, 168, 1, 102 } may need 
//to be modified modified to work with your router.

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 102 }; // ip in lan assigned to arduino
//byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
//byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
byte myserver[] = { 208, 104, 2, 86 }; // zoomkat web page server IP address
EthernetClient client;
//////////////////////

void setup(){

  Ethernet.begin(mac, ip);
  //Ethernet.begin(mac, ip, gateway, subnet);
  Serial.begin(9600); 
  Serial.println("Better client test 4/04/12"); // so I can keep track of what is loaded
  Serial.println("Send an e in serial monitor to test"); // what to do to test
}

void loop(){
  // check for serial input
  if (Serial.available() > 0) //if something in serial buffer
  {
    byte inChar; // sets inChar as a byte
    inChar = Serial.read(); //gets byte from buffer
    if(inChar == 'e') // checks to see byte is an e
    {
      sendGET(); // call sendGET function below when byte is an e
    }
  }  
} 

//////////////////////////

void sendGET() //client function to send/receive GET request data.
{
  if (client.connect(myserver, 80)) {  //starts client connection, checks for connection
    Serial.println("connected");
    client.println("GET /~shb/arduino.txt HTTP/1.0"); //download text
    client.println(); //end of get request
  } 
  else {
    Serial.println("connection failed"); //error message if no client connect
    Serial.println();
  }

  while(client.connected() && !client.available()) delay(1); //waits for data
  while (client.connected() || client.available()) { //connected or data available
    char c = client.read(); //gets byte from ethernet buffer
    Serial.print(c); //prints byte to serial monitor 
  }

  Serial.println();
  Serial.println("disconnecting.");
  Serial.println("==================");
  Serial.println();
  client.stop(); //stop client

}

SurferTim - thanks for the DNS variable information. When I include this the connection is successful, though it seems like I in general need to wait a bit (maybe a minute - haven’t quantified it yet) before rerunning the sketch by resetting the Arduino will allow another successful connection. I’m not using the zoomkat server as I’m unable to ping it at the moment, but the other ip addresses seem to be live.

The ip address now shows up in my router list as well. Here’s the code. I added a client.stop up front to make sure it wasn’t connected to begin with in case an unsuccessful disconnect from a previous run was preventing a successful connection, by my guess is this isn’t doing anything here. I also added a counter to try to bail out if I was getting a lot input from the server, but I’m not sure that is working correctly either.

Should I be able to repeatedly connect to the servers without any significant (more than a few seconds) wait? If not I think this part may be working now. Thanks for the help.

//zoomkat 4-04-12
//simple client test
//for use with IDE 1.0
//open serial monitor and send an e to test
//for use with W5100 based ethernet shields
//note that the below bug fix may be required
// http://code.google.com/p/arduino/issues/detail?id=605 
//the arduino lan IP address { 192, 168, 1, 102 } may need 
//to be modified modified to work with your router.

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEE }; //physical mac address
byte ip[] = { 
  192, 168, 1, 104 }; // ip in lan assigned to arduino
byte gateway[] = { 
  192, 168, 1, 254 }; // internet access via router
byte dns[] = {
  192, 168, 1, 254 }; //use router ip 
byte subnet[] = { 
  255, 255, 255, 0 }; //subnet mask
byte myserver[] = { 
//  208, 104, 2, 86 }; // zoomkat web page server IP address
//     173, 203, 98, 29 }; //pachube ip address
//    216, 52, 233, 122 };  // another pachube address
    209, 191, 122, 70 }; // yahoo
EthernetClient client;
//////////////////////

void setup(){

  //Ethernet.begin(mac, ip);
  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  Serial.begin(9600); 
//add as an attempt to make sure we aren't already connected -
// don't need?
//
    Serial.println();
  Serial.println("disconnecting.");
  Serial.println("==================");
  Serial.println();
  client.stop(); //stop client
  
  Serial.println("Better client test 4/04/12"); // so I can keep track of what is loaded
  Serial.println("Send an e in serial monitor to test"); // what to do to test
}

void loop(){
  // check for serial input
  if (Serial.available() > 0) //if something in serial buffer
  {
    byte inChar; // sets inChar as a byte
    inChar = Serial.read(); //gets byte from buffer
    if(inChar == 'e') // checks to see byte is an e
    {
      Serial.println("read an 'e'");
      sendGET(); // call sendGET function below when byte is an e
    }
  }  
} 

//////////////////////////

void sendGET() //client function to send/receive GET request data.
{
  if (client.connect(myserver, 80)) {  //starts client connection, checks for connection
    Serial.println("connected");
    client.println("GET /~shb/arduino.txt HTTP/1.0"); //download text
    client.println(); //end of get request
  } 
  else {
    Serial.println("connection failed"); //error message if no client connect
    Serial.println();
  }

  while(client.connected() && !client.available()) delay(1); //waits for data
// add counter as an attempt to bail out if too much input comes in
//
  int counter = 0;
  while (client.connected() || client.available()) { //connected or data available
    char c = client.read(); //gets byte from ethernet buffer
    Serial.print(c); //prints byte to serial monitor 
    counter = counter + 1;
    if (counter >= 500 ) {
      exit;  
    }
  }
  Serial.println();
  Serial.println("disconnecting.");
  Serial.println("==================");
  Serial.println();
  client.stop(); //stop client

}

When I include this the connection is successful, though it seems like I in general need to wait a bit (maybe a minute - haven't quantified it yet) before rerunning the sketch by resetting the Arduino will allow another successful connection. I'm not using the zoomkat server as I'm unable to ping it at the moment, but the other ip addresses seem to be live.

I suspect one of the issues with your current code is that it connects to yahoo and tries to down load a file off of my server (below). That won't work. If you want to test using a server besides mine, the below line will need to try to get something that exist on the server you are connecting to.

client.println("GET /~shb/arduino.txt HTTP/1.0"); //download text