在这个 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()
{
}
我的电脑的网络服务器没有收到任何连接请求等。
最佳答案
您的示例甚至无法编译。这是固定版本。
连接后,最好使用 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()
{
}
米哈尔
关于python - Arduino 无法与以太网客户端连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28916264/