简体   繁体   English

如何将以下 POST 请求转换为 ESP8266 AT 命令格式?

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

I've got a working local website that takes in HTML form data.我有一个可以接收 HTML 表单数据的本地网站。

The fields are:这些字段是:

Temperature Humidity温度 湿度

The server successfully receives the data and spits out a graph updated with the new entries.服务器成功接收数据并吐出一个用新条目更新的图表。

Using a browser tool, I was able to capture the actual POST request as follows:使用浏览器工具,我能够捕获实际的 POST 请求,如下所示:

http://127.0.0.1:5000/add_data http://127.0.0.1:5000/add_data

Temperature=25.4&Humidity=52.2温度=25.4&湿度=52.2

Content-Length:30内容长度:30

Now, I want to migrate from using the human interface browser with manual entries to an ESP01 device using AT commands.现在,我想从使用手动输入的人机界面浏览器迁移到使用 AT 命令的 ESP01 设备。

According to the ESP AT-commands documentation, a POST request is performed using the following command:根据 ESP AT-commands 文档,使用以下命令执行 POST 请求:

AT+HTTPCPOST= AT+HTTPCPOST=

Find the link below for the full description of the command.找到下面的链接以获取该命令的完整描述。

I cannot seem to get this POST request working.我似乎无法让这个 POST 请求工作。 The ESP01 device immediately returns an "ERROR" message without any delay, as though it did not even try to send the request, that the syntax might be wrong. ESP01 设备立即返回“错误”消息,没有任何延迟,就好像它甚至没有尝试发送请求一样,表明语法可能是错误的。

Among many variations, the following is my best attempt:在众多变体中,以下是我的最佳尝试:

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

With MYIPADDR above replaced with my IP address.将上面的 MYIPADDR 替换为我的 IP 地址。

How do I translate a post request into ESP01 AT command format, and are there any prerequisites needed to be in place to perform such a request?如何将发布请求转换为 ESP01 AT 命令格式,执行此类请求是否需要具备任何先决条件?

I did connect the ESP01 device to the WiFi network.我确实将 ESP01 设备连接到了 WiFi 网络。

Here's the link to the POST AT command description:这是 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 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