【问题标题】:Ethernet Shield does not supplying the correct IPEthernet Shield 未提供正确的 IP
【发布时间】:2015-11-24 11:40:15
【问题描述】:

大家好。

我很难配置以太网屏蔽。

  1. 我在 Arduino Mega 2560 上安装了 ENC28J60 以太网扩展板。
  2. 我将 Arduino 的 USB 端口连接到我的 PC 的 USB 端口,
  3. 我将 Ethernet Shield 的以太网端口连接到 IP 地址为 192.168.0.1 且 DHCP 起始地址从 .100 到 .200 的 TP-Link 路由器的 LAN 端口

我把我得到的代码上传到 Arduino 模块:https://www.arduino.cc/en/Reference/EthernetClient

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


byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 0, 100 };
byte server[] = { 64, 233, 187, 99 }; // Google

EthernetClient client;

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

  delay(1000);

  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");
  }
}

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

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

然后,从 Arduino IDE 的串行窗口,我得到了

connecting... connection failed disconnecting...

我也从上面尝试了一些类似的代码,有些正在输出屏蔽 IP,但我仍然遇到同样的问题,Ethernet Shield 没有输出 IP 地址或显示“已连接”。

我还尝试了直通和交叉电缆。

请帮忙。

谢谢。

【问题讨论】:

    标签: networking arduino ethernet


    【解决方案1】:

    在您的代码中:
    byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

    必须与您的 Ethernet Shield MAC 地址匹配。

    【讨论】:

    • 不,您可以使用任何您喜欢的 MAC 地址,只要它不与您网络上的其他设备冲突。
    【解决方案2】:

    也许可以尝试让您的路由器通过 DHCP 提供 IP 地址。为此,只需将设置例程中的行更改为 Ethernet.begin(mac);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多