【问题标题】:Arduino fails to connect with ethernet clientArduino 无法与以太网客户端连接
【发布时间】:2025-12-02 17:05:02
【问题描述】:

在这个GET请求中,我不需要服务器的回答,所以循环函数是空的。

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

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip;
byte localIp[] = {192,168,1,181};
EthernetClient client;

void setup()
{
  Serial.begin(9600);
  Ethernet.begin(mac , localIp);
  delay(1000);//give ethernet time to boot?
  byte x[] = { 192,168,1,1 };//my pc , running SimpleHTTPServer (python)
       client.connect(x , 8000);
       delay(1000);
       if(client.connected()){
        Serial.println("connected"); //does never print
       }
}

void loop()
{

}

我电脑的网络服务器没有收到任何连接请求左右。

【问题讨论】:

    标签: python c arduino ethernet


    【解决方案1】:

    您的示例甚至无法编译。在这里你是固定版本。

    连接后最好关闭与 client.stop() 的连接,否则一些简单的服务器可能不会监听新连接,并且仍在等待前一个连接上的数据。

    #include <SPI.h>
    #include <Ethernet.h>
    
    byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
    IPAddress ip;
    IPAddress localIp (192,168,1,181);
    EthernetClient client ;
    
    void setup()
    {
      Serial.begin(9600);
      Ethernet.begin(mac , localIp);
      char x[] = "192.168.1.1" ;//my pc , running SimpleHTTPServer (python)  
      client.connect(x , 8000);
      if( client.connected() ){
        Serial.println("connected"); //does never print
      }
      client.println ("Hellou world from Arduino!") ;
      client.stop();       
    }
    
    void loop()
    {
    
    }
    

    迈克尔

    【讨论】:

    • prntscr.com/6e8ic4 还是不行。 + IPAddress = 字节包装器
    • 你能远程登录服务器吗? telnet 192.168.1.1 8000
    • 可能是因为您的 Windows 防火墙。在测试期间将其关闭。
    • 它关闭了。这个和杀毒软件等