#include "http_server.h"
void setup(){
Serial.begin(9600); // setup serial communication
// Set WiFi to station(STA) and access point (AP) mode simultaneously
WiFi.mode(WIFI_AP_STA);
delay(100); // Recommended delay
WiFi.softAP("choose_some_ssid", "choose_some_password");
// Remember to configure the previous server
setup_http_server(); // starts the asyncronus https server*/
}
void loop(){
delay(1000);
}
import requests
r = requests.post('http://192.168.4.1:80/set_data', data="{'number':55}") // remember that you get the keyword 'number' in the server side
print(r.text) // should print "Some message"
当您发送GET/POST请求时,您必须输入目的地的IP,在本例中,是您的ESP32的IP。在
首先要注意的是,我的服务器.begin默认情况下,()正在作为访问点侦听
192.168.4.1:80
。在现在,要创建一个异步服务器来保存带有json数据的GET和POST请求,可以使用如下函数:
文件http_server.h:
文件http示例_服务器.cpp公司名称:
^{pr2}$最后,如果您想通过移动/计算机直接连接到您的ESP32,则需要将其wifi连接配置为}在你的
ACCESS_POINT
。所以,你的setup()
和{main.ino
中可能看起来像:文件主.ino公司名称:
仅此而已。要检查一切是否正常,您可以使用密码
chose_some_password
将手机连接到wifichoose_some_ssid
,打开浏览器并转到192.168.4.1/get_data
,您将得到“我在这里”作为响应。在正如您在问题中所说,如果您想用python发送帖子,您可以:
更多信息可在https://techtutorialsx.com/2018/10/12/esp32-http-web-server-handling-body-data/上找到 希望有帮助!在
相关问题 更多 >
编程相关推荐