Arduino无法与以太网客户端连接

时间:2015-03-07 15:07:53

标签: python c arduino ethernet

在这个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()
{

}

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

1 个答案:

答案 0 :(得分: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()
{

}

米甲

相关问题