【问题标题】:Arduino - GET request and data posting to mySQLArduino - GET 请求和数据发布到 mySQL
【发布时间】:2021-11-02 17:33:50
【问题描述】:

我有一个问题。

我正在尝试设置简单的服务器,它将数据从传感器发送到 mySQL。 当我在网络浏览器中执行时,路径 /bezp/data.php?temperature="number" 正在工作。我也可以在串口监视器中看到文本“已连接”,所以它进入了 IF,但数据库仍然不会更新。

Arduino 代码:

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = {192, 168, 1, 101 }; //Enter the IP of ethernet shield
byte serv[] = {192, 168, 1, 16} ; //Enter the IPv4 address
EthernetClient cliente;
void runWebSetup() {
Ethernet.begin(mac, ip);
}
void runWebLoop(float temp) {

if (cliente.connect(serv, 80)) { //Connecting at the IP address and port we saved before
  Serial.println("connected");
  cliente.print("GET /bezp/data.php?"); //Connecting and Sending values to database
  cliente.print("temperature=");
  cliente.print(temp);

  cliente.stop(); //Closing the connection
}
else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
delay(5000);
}

温度传感器也在工作,我正在另一个文件中调用函数。

【问题讨论】:

    标签: mysql arduino get


    【解决方案1】:

    您从未完成请求内容 - 您只发送了一半的 HTTP 请求。

    你正在发送这个:

    "GET /bezp/data.php?temperature=123"

    但是一个有效的请求看起来像这样:

    "GET /bezp/data.php?temperature=123 HTTP/1.0\r\n\r\n" 用于 HTTP 1.0

    "GET /bezp/data.php?temperature=123 HTTP/1.1\r\nHost: 192.168.1.16\r\n\r\n" 用于 HTTP 1.1。

    您必须发送方法,后跟路径和协议以及 CRLF,然后是任何标头(每个标头都以 CRLF 结尾),然后是另一个 CRLF。

    您缺少协议(可能是标头)和 CRLF。

    docs

    【讨论】:

      猜你喜欢
      • 2020-08-04
      • 1970-01-01
      • 2013-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-16
      • 2011-06-09
      相关资源
      最近更新 更多