ESP32 做Web服务器 http Server步骤

资料不多。多是国外网站的。

百度搜基本出来的是这个网站https://www.dfrobot.com/blog-922.html

出来的代码是:

#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());
 
  server.on("/html", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send(200, "text/html", "<p>This is HTML!</p>");
  });
 
  server.begin();
}
 
void loop(){
}

发愁:这个库在哪里?我怎么运行?于是我找到了这里:

https://github.com/me-no-dev/ESPAsyncWebServer

里面使用ESPAsyncWebServer的步骤

如下:

1   安装:PlatformIO IDE

这里有详细教材:https://blog.csdn.net/baimei4833953/article/details/78771611/

2 创建新的工程:"PlatformIO Home > New Project"

http://docs.platformio.org/en/latest/ide/vscode.html

3 修改配置文件

Add "ESP Async WebServer" to project using Project Configuration File platformio.ini and lib_deps 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()); server.on("/hello", HTTP_GET, [](AsyncWebServerRequest *request){
request->send(200, "text/plain", "Hello World");
}); server.begin();
} void loop(){}

编译运行下载,搞定。。。。

 
上一篇:试水jdk8 stream


下一篇:Python iter() 函数