简体   繁体   English

Arduino以太网屏蔽:dhcpaddressprinter错误

[英]Arduino Ethernet shield: dhcpaddressprinter error

I am new to the Ethernet shield , and I tried to used the DhcpAddressPrinter example given. 我是以太网屏蔽的新手,我尝试使用给定的DhcpAddressPrinter示例。 But I can't get the program running correctly. 但是我无法使程序正确运行。

Below is the sketch: 下面是草图:

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

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
    // Open serial communications and wait for port to open:
    Serial.begin(9600);

    // This check is only needed on the Leonardo:
    while (!Serial) {
    ; // Wait for serial port to connect. Needed for Leonardo only.
}

// 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:
    for(;;)
        ;
    }

    // Print your local IP address:
    Serial.print("My IP address: ");
    for (byte thisByte = 0; thisByte < 4; thisByte++) {
        // print the value of each byte of the IP address:
        Serial.print(Ethernet.localIP()[thisByte], DEC);
        Serial.print(".");
    }
    Serial.println();
}

void loop() {

}

And after I open the serial monitor, I got the message "Failed to configure Ethernet using DHCP" after a long period of time. 在打开串行监视器后,经过很长一段时间,我收到消息“无法使用DHCP配置以太网”。

It sounds like your network does not have DHCP configured. 听起来您的网络没有配置DHCP This is usually set up on the router for most home networks. 通常,对于大多数家庭网络,这是在路由器上设置的。

Try giving the Ardunio a static IP address like so 尝试像这样给Ardunio一个静态IP地址

byte MAC_address[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ipAddress(192,168,1,1152); 
EthernetClient client;
Ethernet.begin(MAC_address, ipAddress);

If that doesn't work how are you connecting your Arduino? 如果那不起作用,您如何连接Arduino? Is it to a computer, a router, or a modem? 是计算机,路由器还是调制解调器?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM