简体   繁体   English

Arduino以太网屏蔽不起作用

[英]Arduino ethernet shield not working

I have an arduino ethernet shield and I am trying to run the "Webserver" example on it.我有一个 arduino 以太网屏蔽,我正在尝试在其上运行“Webserver”示例。 I have the shield sitting on top of the arduino, with the arduino connected to my PC via USB and the shield connected to my PC as well with an RJ45 ethernet cable.我将屏蔽板放在 arduino 的顶部,arduino 通过 USB 连接到我的电脑,屏蔽板也通过 RJ45 以太网电缆连接到我的电脑。 I am using my university's wifi network to connect to the internet and do not have access to any routers.我正在使用我大学的 wifi 网络连接到互联网,并且无法访问任何路由器。 So here is my problem: when I type ipconfig on the command line I see that my computer's IP adress is 143.215.98.213.所以这是我的问题:当我在命令行上键入 ipconfig 时,我看到我的计算机的 IP 地址是 143.215.98.213。 So in the "Webserver" example code given in the arduino IDE, the only change I made is to set the IP adress as: IPAddress ip(143,215,98,2);因此,在 arduino IDE 中给出的“Webserver”示例代码中,我所做的唯一更改是将 IP 地址设置为:IPAddress ip(143,215,98,2); (I pinged the adress 143.215.98.2, it was not used so it's fine I guess). (我ping了地址143.215.98.2,它没有被使用,所以我猜没关系)。 The Webserver code is supposed to read the analog inputs from the arduino and print it on an html page. Webserver 代码应该从 arduino 读取模拟输入并将其打印在 html 页面上。 When I upload the code to the arduino and type in the adress 143.215.98.2 to my browser, the browser cannot connect to any page.当我将代码上传到 arduino 并在浏览器中输入地址 143.215.98.2 时,浏览器无法连接到任何页面。 The TX and RX leds do not light up. TX 和 RX LED 不亮。 Also, I tried pinging t143.215.98.2 while the code is running and I get no response (leds on the arduino do not blink either).此外,我尝试在代码运行时 ping t143.215.98.2,但没有得到任何响应(arduino 上的 LED 也不闪烁)。 Here is the webserver example code I am using:这是我正在使用的网络服务器示例代码:

#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");
  }
}

So what could be the problem ?那么可能是什么问题?

I think the problem is the IP address.我认为问题是IP地址。 Is it possible to obtain an automated ip from the DHCP?是否可以从 DHCP 获取自动 ip? If so, the you should remove the ip address and just start the server with Ethernet.begin(mac).如果是这样,您应该删除 IP 地址并使用 Ethernet.begin(mac) 启动服务器。

If it isn't possible to obtain an automated ip.. you can ask the network administrator for free ip sections to us on the network.如果无法获得自动 ip.. 您可以向网络管理员索取网络上的免费 ip 部分给我们。 (If he gives that kind of info away) (如果他把那种信息泄露出去)

Anyway, good luck!无论如何,祝你好运!

Check your Ip address properly.正确检查您的 IP 地址。 Whether your using static or dynamic type.无论您使用的是静态类型还是动态类型。

Goto INTERNET protocol.转到 INTERNET 协议。 select Following IP address amd configure as and include in Program it should work选择以下 IP 地址并配置为并包含在程序中它应该可以工作

IPAddress ip(192,168,1, 177);
IPAddress gateway(192,168,1, 1);
IPAddress subnet(255, 255, 0, 0);

A lot of delay, but I write here to help someone with similar problem.很多延迟,但我写在这里是为了帮助有类似问题的人。

I'm going to be crazy with the Chinese Arduino Ethernet Shield: With some switch it works, with some other it doesn't.我会为中国的 Arduino 以太网屏蔽而疯狂:有一些开关它可以工作,而另一些则不能。 Then after a lot of search in the net I've found this: https://reedpaper.wordpress.com/2018/09/17/arduino-ethernet-w5100-how-to-fix-the-wrong-board/ And the problem is gone!然后在网上进行了大量搜索后,我发现了这个: https ://reedpaper.wordpress.com/2018/09/17/arduino-ethernet-w5100-how-to-fix-the-wrong-board/问题消失了!

In some Chinese boards there is an error in the 49.9ohm resistors near the ethernet connector.在某些中文板中,以太网连接器附近的 49.9 欧姆电阻器存在错误。 Instead of mounting a 510 array resistor they use a 511 array so instead have 51ohm there are a 510ohm resistors and the connection result is unpredictable.他们没有安装 510 阵列电阻器,而是使用 511 阵列,因此有一个 51ohm 电阻器,而不是 510ohm 电阻器,连接结果是不可预测的。

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

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