我有一个arduino以太网盾,我正在尝试运行“Webserver”示例 . 我把盾牌放在arduino的顶部,arduino通过USB连接到我的电脑,屏蔽连接到我的电脑以及RJ45以太网电缆 . 我正在使用我大学的无线网络连接到互联网,无法访问任何路由器 . 所以这是我的问题:当我在命令行输入ipconfig时,我看到我的计算机的IP地址是143.215.98.213 . 因此,在arduino IDE中给出的“Webserver”示例代码中,我所做的唯一更改是将IP地址设置为:IPAddress ip(143,215,98,2); (我把地址143.215.98.2,它没用过,所以我觉得很好) . Web服务器代码应该从arduino读取模拟输入并在html页面上打印 . 当我将代码上传到arduino并在我的浏览器中输入地址143.215.98.2时,浏览器无法连接到任何页面 . TX和RX LED不亮 . 此外,我尝试在代码运行时ping t143.215.98.2并且我没有得到响应(arduino上的LED也没有闪烁) . 这是我正在使用的webserver示例代码:
#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("
");
}
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");
}
}
那可能是什么问题呢?
2 回答
我认为问题是IP地址 . 是否有可能从DHCP获得自动IP?如果是这样,您应该删除IP地址,然后使用Ethernet.begin(mac)启动服务器 .
如果无法获得自动IP ..您可以向网络管理员询问网络上的免费IP部分 . (如果他提供那种信息)
无论如何,祝你好运!
正确检查您的IP地址 . 无论您使用静态还是动态类型 .
转到INTERNET协议 . 选择以下IP地址amd configure as和include in Program它应该工作