未设置Arduino + Intel Galileo Gen 2以太网IP

时间:2016-11-03 15:49:17

标签: arduino intel-galileo

我有一个Intel Galileo Gen 2主板,我正在使用Arduino IDE测试一些代码。我在配置以太网时遇到问题。我有以下代码,基本上是从示例演变而来的:

#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(;;)
      ;
  }

}

这就是我看到的结果:

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

disconnecting.

我看到的是没有明确分配IP地址,因为localIP表示255.255.255.255。

我尝试过在论坛中找到的一些解决方法(界面,禁用de SD卡),但没有任何效果。

我做错了什么?

由于

已更新

我已更正错误的MAC地址。添加了ifup命令。没有变化。

添加system("ifconfig -a > /dev/ttyGS0");命令后,我得到了这个:

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)

据我所知,它不是试图设置IP但仍在搜索DHCP。

2 个答案:

答案 0 :(得分:1)

解决方案是更改接口名称。要运行的实际命令是:

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

答案 1 :(得分:0)

您可以在设置功能中添加行system("ifup eth0");以确保网络接口已启动。

直接从&#34; Linux端&#34;检查您的IP地址第system("ifconfig -a > /dev/ttyGS0");

的董事会成员