我有個問題。
我正在嘗試設定簡單的服務器,它將從傳感器發送資料到 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);
}
溫度傳感器也在作業,我正在另一個檔案中呼叫函式。
uj5u.com熱心網友回復:
您從未完成請求內容 - 您只發送了一半的 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。
請參閱檔案。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/346468.html
