1
votes

I have an Intel Galileo Gen 2 Board and I am testing some code with the Arduino IDE. I am having problems when cofiguring the Ethernet network. I have the following code, basically evolved from the examples:

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

byte mac[] = { 0x98, 0x4F, 0xEE, 0x05, 0x65, 0x02 };
IPAddress server(192, 168, 15, 64);
IPAddress ip(192, 168, 15, 177);
IPAddress dnServer(8, 8, 8, 8);
IPAddress gateway(192, 168, 15, 1);
IPAddress subnet(255, 255, 255, 0);

EthernetClient client;

void setup() {

Serial.begin(9600);
Serial.print("ip - ");
Serial.println(ip);
Ethernet.begin(mac, ip, dnServer, gateway, subnet);
delay(1000);
system("ifup eth0");  
delay(1000);
Serial.println(Ethernet.localIP());


  Serial.println("connecting...");

  if (client.connect("www.google.com", 80)) {
      Serial.println("connected");
    client.println("GET /search?q=arduino HTTP/1.1");
    client.println("Host: www.google.com");
    client.println("Connection: close");
    client.println();
  } 
  else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }

}

// the loop function runs over and over again forever
void loop() {

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

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

    for(;;)
      ;
  }

}

This is what I see as a result:

ip - 192.168. 15.177
255.255.255.255
connecting...
connection failed

disconnecting.

What I see is that no IP address is aparently assigned as the localIP indicates 255.255.255.255.

I have tried some workarounds found in forums (interface up, disable de SD card) but nothing worked.

What I am doing wrong?

Thanks


UPDATED

I have corrected the wrong MAC address. Added the ifup command. No changes.

After adding the system("ifconfig -a > /dev/ttyGS0"); command I get this:

enp0s20f6 Link encap:Ethernet  HWaddr 98:4F:EE:05:65:02  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:980 (980.0 B)
          Interrupt:50 Base address:0x4000 

enp0s20f6:avahi Link encap:Ethernet  HWaddr 98:4F:EE:05:65:02  
          inet addr:169.254.4.217  Bcast:169.254.255.255  Mask:255.255.0.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          Interrupt:50 Base address:0x4000 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:584 errors:0 dropped:0 overruns:0 frame:0
          TX packets:584 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:45040 (43.9 KiB)  TX bytes:45040 (43.9 KiB)

As I understand it is not trying to set the IP but still searching for DHCP.

2

2 Answers

1
votes

The solution was to change Interface name. The actual commands to be run are these ones:

system("ifconfig enp0s20f6 down ");
system("ip link set enp0s20f6 name eth0");
system("ifconfig eth0 up");
0
votes

You can add the line system("ifup eth0"); in the setup function to ensure the network interface is up.

Check your IP address straight from the "Linux side" of the board with the line system("ifconfig -a > /dev/ttyGS0");