Can't ping the Ethernet Shield

I am having trouble getting started with the Ethernet Shield (http://www.sparkfun.com/products/9026) using the Arduino Decimilia.

I am using a manually configured Ethernet connection sharing on my Mac with the following values

On my computer:

IP: 192.168.1.92

Router: 192.168.1.254

DNS Server: 192.168.2.254

Ethernet shield on Arduino:

IP: 192.168.1.124

MAC Address:

Gateway: 192.168.1.92 (have also tried 192.168.1.254)

Subnet: 255.255.255.0

and then do Ethernet.begin(mac, ip, gateway, subnet)

I can’t ping it and my Client.connect() always returns false in the following code

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

byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x79, 0x4B }; //mac address of the arduino
byte ip[] = { 192, 168, 1, 124 }; //ip address for arduino 
byte gateway[] = { 192, 168, 1, 92 }; //ip address of the gateway or router
byte subnet[] = { 255, 255, 255, 0 }; 
 
byte server[] = { 74, 125, 224, 72 };

uint8_t connectStatus;
uint8_t closeStatus;
int ignore;

Client client(server, 80);

void setup()
{
  Ethernet.begin(mac, ip, gateway);
  Serial.begin(9600);
}

void loop()
{
  for (int i=1; i<=50; i++) {
    Serial.print("Connection Attempt ");
    Serial.print(i, DEC);
    ConnectToWebserver();
    delay(1);
  }

// Enter an infinite loop to "stop" the sketch
  while (true);
}


void ConnectToWebserver(){

  uint8_t connectStatus;
  
  if (client.connect()) {
    Serial.print(" - Connected");
    
// Send the HTTP GET to the server
    client.println("GET / HTTP/1.0");
    client.println();

// Read the response
    Serial.print(" - ");
    Serial.print(ReadResponse(), DEC);
    Serial.println(" bytes received");

// Disconnect from the server
    client.flush();
    client.stop();
    
  } else {
// Connection failed
    Serial.println(" - CONNECTION FAILED!");
  }
}


int ReadResponse(){
  int totalBytes=0;
  unsigned long startTime = millis();

// First wait up to 5 seconds for the server to return some data.
// If we don't have this initial timeout period we might try to
// read the data "too quickly" before the server can generate the
// response to the request

  while ((!client.available()) && ((millis() - startTime ) < 5000));

  while (client.available()) {
    char c = client.read();
    totalBytes+=1;
  }
  return totalBytes;
}

Would really appreciate some help

Unless your PC (excuse me, MAC :wink: ) is sharing it’s internet connection, the Gateway: 192.168.1.92 address is wrong. It really should be your router address: 192.168.1.254 Why it didn’t work is a mystery to me too. Are you sure the code updated properly with the changed IP address?

Client client(server, 80);

The client-class constructor code tries to connect to “server”, with IP 74.125.224.72. But without a proper IP address for gateway this traffic won’t reach it, and fail it. Your MAC is not (probably) going to relay those packets onto the internet.

BTW, it should be of no concern when pinging IP addresses, but are you sure that DNS IP address on your MAC is correct? It seems like it is in a different subnet. Well, if it was wrong, you’d have big trouble browsing the net on it. Probably a typo.

[EDIT]Hmm, what is the subnet code that your MAC uses? Might afterall be related to the failing connection if it is different to the subnet code entered in the shield.

Thanks for your reply Valen,

I am sharing my internet through the ethernet port and thats why I thought I should be able to reach the server with its IP address.

The DNS was a typo in the forum post, it should have been 192.168.1.254.

Using the subnet as 255.255.255.0, same as on my computer

meekal:
Thanks for your reply Valen,

I am sharing my internet through the ethernet port and thats why I thought I should be able to reach the server with its IP address.

I’m sorry, but that statement confuses me. If you have a router in your network (192.168.1.254) then why do you share your internet via your Mac. Which probably connects to the internet through this router. Please describe in more detail how all the devices connect together in your home LAN. Starting from the point the internet comes through your walls.

I should have said this upfront, I know nothing about how Macs work, or what network services they are capable of. I suggested internet connection sharing because it is possible in Windows PCs (those I know a bit about, and only realized too late you had a Mac). ICS in Windows makes your PC function like a simplified (NAT)router (internet traffic comes in on one network card or modem-device, and LAN traffic goes to a different networkcard; the PC hides the LAN from the internet). But according to that IP address list you already seem to have a router. It wouldn’t make sense why you’d want that extra complexity (a software router connected to a hardware router in the same subnet).

I am sharing my WiFi connection, which I use to connect to the internet, with my ethernet connection to which I have my Arduino plugged in.

This allows me to develop applications without having to sit next to my router. I don’t mind developing applications with just locahost as well, but the main problem is I can’t ping my device.

The connection sharing probably causes the ethernet card to get a IP address in a different subnet range. If so, then the Shield should have a similar IP address. And the gateway be indeed your Mac, but this other IP adress.

Anyway, to isolate the cause of this fault I suggest you hook up the Ethernet shield to your router anyway. Just temporarily If that works then you know the connection sharing is likely making it fail. If not then you’d focus faultfinding on the Arduino and Ethernet-shield.

Also, with the Ethernet shield/Mac connection, check if your ethernet port supports [Auto-MDIX. Modern computers do have it, but older might not. With Auto-MDIX the ethernetport checks how the wires are connected to the port on the other side. It could be that the Ethernet-shield receive pins are connected to the Mac’s receive pins. (and vice-versa) In that case the LEDs on the ethernetport should also indicate that there is no link.

[EDIT] Consult this: http://support.apple.com/kb/HT2274](Medium-dependent interface - Wikipedia)

Are you sure the Ethernet Shield and Arduino code actually supports ICMP protocol (Echo, a.k.a. Ping)