ESP32做Web服务器httpServer步骤资料不多。多是国外⽹站的。
出来的代码是:
#include <WiFi.h>
#include <FS.h>
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
const char* ssid = "yourNetworkName";
const char* password = "yourNetworkPassword";
AsyncWebServer server(80);
void setup(){
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi..");
}
Serial.println(WiFi.localIP());
webserver接口开发<("/html", HTTP_GET, [](AsyncWebServerRequest *request){
request->send(200, "text/html", "<p>This is HTML!</p>");
});
server.begin();
}
void loop(){
}
发愁:这个库在哪⾥?我怎么运⾏?于是我到了这⾥:
⾥⾯使⽤ESPAsyncWebServer的步骤
如下:
1 安装:
2 创建新的⼯程:"PlatformIO Home > New Project"
3 修改配置⽂件
Add "ESP Async WebServer" to project using and option:
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
# using the latest stable version
lib_deps = ESP Async WebServer
打開main.c
#include <WiFi.h>
#include <FS.h>
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
const char *ssid = "MyESP32AP";
const char *password = "testpassword";
AsyncWebServer server(80);
void setup(){
Serial.begin(115200);
WiFi.softAP(ssid, password);
Serial.println();
Serial.print("IP address: ");
Serial.println(WiFi.softAPIP());
<("/hello", HTTP_GET, [](AsyncWebServerRequest *request){ request->send(200, "text/plain", "Hello World");
});
server.begin();
}
void loop(){}
编译运⾏下载,搞定。。。。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论