【发布时间】: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);
}
温度传感器也在工作,我正在另一个文件中调用函数。
【问题讨论】: