Arduino 以太网 + PHP 请求

Arduino Ethernet + PHP Request

我正在为 Arduino + 以太网屏蔽编写代码,以使用 $_GET 方法 (PHP) 将数据发送到 Mysql 数据库。

我已经在浏览器上测试了 PHP 代码,它运行良好,但在 Arduino 上它不起作用。我不知道问题出在哪里。我一直在寻找其他论坛,找不到任何答案。下面是我的代码,如果有人能帮助解决崩溃,我将不胜感激

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

byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
byte ip[] = { 192, 168, 1, 60 }; //IP (WEB CLIENT)
byte server[] = { 192, 168, 1, 8 }; //IP (SERVER) 
EthernetClient client;

void setup() { 
  Serial.begin(9600);  
  Ethernet.begin(mac, ip);
  if (client.connect(server, 8095)) {        
    Serial.println("CONECTED");
    client.print("GET http://192.168.1.8:8095/prs/Query.php?a=");
    client.print(2);
    client.print(" HTTP/1.1\r\n");
    Serial.println("Information sent successfully!"); 
    delay(1000);
  } else {
    Serial.println("Conection fail");
  }
}

void loop() { 
}

我注意到以太网客户端 variable/object 在它声明的地方被称为 cliente(末尾有一个 e),但是在此之下对象的名称是 client(末尾没有 e),如果你更正此名称差异是否有效?

EthernetClient cliente;

client.connect(server, 8095)
client.print("GET http://192.168.1.8:8095/prs/Query.php?a=");
client.print(2);
client.print(" HTTP/1.1\r\n");

这不是 well-formed HTTP 1.1 请求:

  1. 它在请求行中包含协议、主机名和端口。这在 HTTP 代理请求之外是不合适的。

  2. 它不包含 Host header。

  3. 请求后不包含两个换行符

正确的请求可能类似于:

"GET /prs/Query.php?a=2\r\nHost: 192.168.1.8\r\n\r\n"