arduino - 本地的 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 未定义。
我尝试了其他几种解决方案均无济于事-因此会收到一些建议。
解决方案
推荐阅读
- python - 正则表达式对象如何在 Python 循环中工作?
- android - Android build.gradle 排除重复类
- angular - 这是过滤 BehaviorSubject 的正确方法吗
- jsp - 如何在 JSP 中比较两个 Arraylists 值
- python - 具有不同实例化的 Python
- python - 根据列值添加空间
- data-structures - 删除二叉树中节点的代码不起作用
- java - JSP for 在列表检索中给出相同的重复值
- javascript - 如何将背景图像固定到视口那使用transfrom?
- node.js - 如果客户端在 NodeJs 之间取消请求,则停止进一步的执行过程