簡體   English   中英

如何將以下 POST 請求轉換為 ESP8266 AT 命令格式?

[英]How do I translate the following POST request into ESP8266 AT-command format?

我有一個可以接收 HTML 表單數據的本地網站。

這些字段是:

溫度 濕度

服務器成功接收數據並吐出一個用新條目更新的圖表。

使用瀏覽器工具,我能夠捕獲實際的 POST 請求,如下所示:

http://127.0.0.1:5000/add_data

溫度=25.4&濕度=52.2

內容長度:30

現在,我想從使用手動輸入的人機界面瀏覽器遷移到使用 AT 命令的 ESP01 設備。

根據 ESP AT-commands 文檔,使用以下命令執行 POST 請求:

AT+HTTPCPOST=

找到下面的鏈接以獲取該命令的完整描述。

我似乎無法讓這個 POST 請求工作。 ESP01 設備立即返回“錯誤”消息,沒有任何延遲,就好像它甚至沒有嘗試發送請求一樣,表明語法可能是錯誤的。

在眾多變體中,以下是我的最佳嘗試:

AT+HTTPCPOST="http://MYIPADDR:5000/add_data",30,2,"溫度:25.4","濕度:52.2"

將上面的 MYIPADDR 替換為我的 IP 地址。

如何將發布請求轉換為 ESP01 AT 命令格式,執行此類請求是否需要具備任何先決條件?

我確實將 ESP01 設備連接到了 WiFi 網絡。

這是 POST AT 命令說明的鏈接:

https://docs.espressif.com/projects/esp-at/en/release-v2.2.0.0_esp8266/AT_Command_Set/HTTP_AT_Commands.html#cmd-httpcpost

The documentation says:

AT+HTTPCPOST=url,length[,<http_req_header_cnt>][,<http_req_header>..<http_req_header>] Response:

OK

The symbol > indicates that AT is ready for receiving serial data, and you can enter the data now. When the requirement of message length determined by the parameter is met, the transmission starts. ...

Parameters

: HTTP URL. : HTTP data length to POST. The maximum length is equal to the system allocable heap size. <http_req_header_cnt>: the number of <http_req_header> parameters. [<http_req_header>]: you can send more than one request header to the server.

You're sending:

AT+HTTPCPOST="http://MYIPADDR:5000/add_data",30,2,"Temperature: 25.4","Humidity: 52.2"

The length is 30. The problem is that everything after the length is HTTP header fields; you need to send the variables in the body. So the command is:

AT+HTTPCPOST="http://MYIPADDR:5000/add_data",30

followed on the next line by after the ESP-01 send the > character:

Temperature=25.4&Humidity=52.2

Because you passed 30 as the body length, the ESP-01 will read exactly 30 characters after the end of the AT command and send that data as the post body. If the size of that data changes (for instance, maybe the temperature is 2.2, so one digit less), you'll need to send the new length rather than 30.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM