Intel Galileo & Ethernet

I have been trying to get my Ethernet adapter working with a sample Arduino example all morning. I could use the knowledge of more experience users.

I have been trying to run the following code:

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


byte mac[] = { 0x98, 0x4F, 0xEE, 0x00, 0x0E, 0x70 };
byte server[] = { 64, 233, 187, 99 }; // Google

EthernetClient client;

void setup()
{
  Ethernet.begin(mac);
  Serial.begin(9600);
  
  delay(1000);
  
  Serial.println("Setup has Started..");
  Serial.println("connecting...");

  if (client.connect(server, 80)) {
    Serial.println("connected");
    client.println("GET /search?q=arduino HTTP/1.0");
    client.println();
  } else {
    Serial.println("connection failed");
  }
  
  Serial.println("Setup has Finished..");
}

void loop()
{
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    for(;;)
      ;
  }
}

It continually fails to connect. No matter what I have tried, I always get “connection failed”. I thought that maybe the IP address of google was incorrect, so I used the other implementation of client.connect that takes only the domain name. For example, I have tried

  if (client.connect("www.google.com", 80)) {
    Serial.println("connected");
    client.println("GET /search?q=arduino HTTP/1.0");
    client.println();
  } else {
    Serial.println("connection failed");
  }
  }
}

But that doesn’t work either. I have also verified that the Ethernet cord works by plugging it into another machine. I’ve pretty much pin-pointed that it is the connectivity of the adapter. Is anyone familiar with setting up the Ethernet on the Galileo? I don’t know where to look anymore.

I would start by verifying that your ethernet connectivity is working like this:

 // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    // try to congifure using IP address instead of DHCP:
    Ethernet.begin(mac, ip);
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");

You can test success of the connection from the returned result, there are several options to the begin function, you can query the localIP address to confirm connectivity and as per the example above you should wait one second to the connectivity to settle down before attempting a client connection.

Catweazle NZ

CatweazleNZ, thanks for the suggestion. I added that code that you recommended, but client.connect("google.com", 80) continues to fail. It can't connect with either domain name, or ip address. I'm just using the same code as was posted above.

Any other possibilities?

What local IP address is your board getting. You might be able to see it as attached device in your router/modem.

Does the board respond to a ping - test that before and after the ethernet.begin to confirm the basic ethernet connectivity is in place.

Assuming ethernet connectivity is in place you could try sending an email using available example code.

You could also test an incoming client connect - but you need to use the ethernet server class after the ethernet begin and before your ethernetclient. Once again check out available example code.

Good luck?

Catweazle NZ

PS Exactly how much RAM is available on a Galileo for Arduno sketches?

I figured it out. I wasn't waiting long enough after connecting to a given server, so the main body of the loop was getting executed prior to the actual connection being made. Simple fix.

Thanks for your recommendation Catweazle, it helped me better pin-point the issue.

Hi I’m having the same problem and haven’t been able to fix it. How long is your delay? Would you mind posting your final code?

Thanks!

Please post your final code, I have the same issue!

Can someone please post the code that works???
I’m having the exact same problem…
Thanks