首页 > 解决方案 > 本地的 Arduino DNS

问题描述

如何引用 DNS serverIP、subnetIP、gatewayIP 的地址?

正如您从下面的代码中看到的那样,我已经尝试过,但我得到的只是以下错误,

“类 EthernetClass 没有称为子网的成员”。

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

// Network configuration
// Note : DNS server, gateway and subnet are optional.

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };  

//  The IP address of Arduino Ethernet shield.
IPAddress myLocalIP(192, 168, 100, 2);

// The DNS server IP.
IPAddress dnsServer(192, 168, 100, 1);

// The router's gateway IP address.
IPAddress gateway(192, 168, 0, 1);

// the subnet:
IPAddress subnet(255, 255, 255, 0);


void setup() {
  Serial.begin(9600);

  Ethernet.begin(mac, myLocalIP, subnet);    // Initialize the ethernet device
//  Ethernet.begin(mac, ip, dnServer, gateway, subnet);

  Serial.print("Local IP = ");  // Print out the IP address of the shield.
  Serial.println(Ethernet.localIP());
  Serial.print("DNS Address = ");
  Serial.println(Ethernet.IPAddress.subnet() );
}  // End setup.

void loop()
{

}  // End loop.

Wallek876,感谢您提供的信息。

我也添加了其他的,即子网掩码、网关IP,但是当我使用记录的方法(根据您的链接)打印 MAC 地址时 - 即 - Ethernet.MACAddress(macBuffer); 我有一个错误。

记录的代码 - (从文档中复制)如下;

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

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(10, 0, 0, 177);

void setup() {
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Ethernet.begin(mac, ip);

  byte macBuffer[6];  // create a buffer to hold the MAC address
  Ethernet.MACAddress(macBuffer); // fill the buffer
  Serial.print("The MAC address is: ");
  for (byte octet = 0; octet < 6; octet++) {
    Serial.print(macBuffer[octet], HEX);
    if (octet < 5) {
      Serial.print('-');
    }
  }
}

void loop () {}

错误在线 Ethernet.MACAddress(macBuffer); MACAddress 未定义。

我尝试了其他几种解决方案均无济于事-因此会收到一些建议。

标签: arduinoethernet

解决方案


推荐阅读