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

标签 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()
{

}

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

最佳答案

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

连接后,最好使用 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/

相关文章:

Java串行读取程序返回乱码

python - Django Tinymce 不显示富文本表单

python - 一个点和一组其他点之间的最短距离?

python - 无法使用 gunicorn 运行 Tornado 应用程序

c - 如何为所有 3 个 C 文件创建 makefile?

c - 解除分配多个内存指针的最方便的方法?

visual-studio - 使用 Unity 时出错。没有解决方案有效..错误 CS0234 : The type or namespace name `Ports' does not exist in the namespace `System.IO'

python - 有效地在python关联列表中查找元素

objective-c - 错误预期标识符或 (

c - 指向结构内元素的指针 ( C )