我有一个 arduino 以太网屏蔽,我正在尝试在其上运行“Webserver”示例。我将防护罩放在 arduino 的顶部,arduino 通过 USB 连接到我的 PC,防护罩通过 RJ45 以太网电缆连接到我的 PC。我正在使用我大学的 wifi 网络连接到互联网,但无法访问任何路由器。所以这是我的问题:当我在命令行中键入 ipconfig 时,我看到我的计算机的 IP 地址是 143.215.98.213。因此,在 arduino IDE 中给出的“Webserver”示例代码中,我所做的唯一更改是将 IP 地址设置为: IP 地址 ip(143,215,98,2); (我 ping 地址 143.215.98.2,它没有被使用,所以我猜没问题)。 Web 服务器代码应该从 arduino 读取模拟输入并将其打印在 html 页面上。当我将代码上传到 arduino 并在我的浏览器中输入地址 143.215.98.2 时,浏览器无法连接到任何页面。 TX 和 RX 指示灯不亮。此外,我尝试在代码运行时 ping t143.215.98.2,但没有收到任何响应(arduino 上的 LED 灯也不会闪烁)。这是我正在使用的网络服务器示例代码:
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(143,215,98,2);
//IPAddress ip(128,61,79,1);
//IPAddress ip(192,168,1,1);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop() {
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println("Refresh: 5"); // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
int sensorReading = analogRead(analogChannel);
client.print("analog input ");
client.print(analogChannel);
client.print(" is ");
client.print(sensorReading);
client.println("<br />");
}
client.println("</html>");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disonnected");
}
}
那么可能是什么问题?
我认为问题是IP地址。是否可以从 DHCP 获取自动 ip?如果是这样,您应该删除 ip 地址并使用 Ethernet.begin(mac) 启动服务器。
如果无法获得自动ip..您可以向网络管理员索取网络上的免费ip部分给我们。 (如果他泄露了那种信息)
总之,祝你好运!
正确检查您的IP地址。无论您使用静态还是动态类型。
转到互联网协议。选择 Following IP address amd configure as and include in Program it should work
IPAddress ip(192,168,1, 177);
IPAddress gateway(192,168,1, 1);
IPAddress subnet(255, 255, 0, 0);
很多延迟,但我写在这里是为了帮助有类似问题的人。
中文Arduino Ethernet Shield我要疯了: 对于某些开关,它可以工作,而对于其他开关则不能。 然后在网上大量搜索后,我发现了这个: https://reedpaper.wordpress.com/2018/09/17/arduino-ethernet-w5100-how-to-fix-the-wrong-board/ 问题消失了!
在一些中国主板上,以太网连接器附近的 49.9ohm 电阻器存在错误。 他们没有安装 510 阵列电阻,而是使用 511 阵列,因此有 51ohm 而不是 510ohm 电阻,连接结果不可预测。