esp32-cam的使用
esp32开启服务器
#include <WiFi.h>
#include <ESPAsyncWebServer.h>
const char* ssid = "HYCX_1";
const char* password = "hycx123456";
AsyncWebServer server(80);
const char index_html[] PROGMEM = R"rawliteral(
<!DOCTYPE HTML><html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<h2>ESP Image Web Server</h2>
<img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD//gA7Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcgSlBFRyB2NjIpLCBxdWFsaXR5ID0gODAK/9sAQwAGBAUGBQQGBgUGBwcGCAoQCgoJCQoUDg8MEBcUGBgXFBYWGh0lHxobIxwWFiAsICMmJykqKRkfLTAtKDAlKCko/9sAQwEHBwcKCAoTCgoTKBoWGigoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgo/8IAEQgAgACAAwEiAAIRAQMRAf/EABsAAAICAwEAAAAAAAAAAAAAAAAGBQcBAwQC/8QAGAEBAQEBAQAAAAAAAAAAAAAAAAECAwT/2gAMAwEAAhADEAAAAbUAAECH8rCzK9gAcFaRbRAz1BE7zvNW0AArSd0RM1/aHjOkbL3iys7I9+pUKYgnHWa04t3VViMKyzBr2KYs2NBTuNAtyksgYDILYxVxZKlYxeKwg9ZuVgpCzKY64seth8M8/PpFa5FPWC3dnSmrvh7EOrl8dEtAz8u0dONf2TFT1rClumsgJSuLKxvlOqIzqteaz4XSOf19nTnhWGtpG1p8+t8wC0AIREtatYfcrUTnUJANK/n0XF1ad14ozWm2RrnsA0AAACtLLrOHzi7FzOlqHn8VYW2Bns1VmfcDrLwBqAAAHms7MgIlM7jOtGdwasbg0I1gQ9k8BqAB/8QAKRAAAQQBAgUDBQEAAAAAAAAABAECAwUGABIQERMUIBUhIxYiJCUxQP/aAAgBAQABBQL/AB5MVNvGsS6kljke3gYVEJBKfanspTe/A0MfAST3kHcRSMlZ4M/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QatJkZoIruK6+FU9l47uOq7DPOiqz7irXgsnv/qJnYWwiyqo44Il0GjfMcSaboidxKc4DXtZ8RXUKaU3n+D0j+imwhSRZQmxXCX/wg6jNqx09xywnrWHYAfOHzGfwGEVCGsjuURuPNjZTfvctNAuh/igVGhAC1dBFQb7Wxf7ZUDTCAAwHpFkBvaC9+djycxFMdk8h0MZUkPRAF4xL5hiMt5ptA5uTjNQSk6yM5vh9wz88O6GV8rb8zSA2zerYinWFXWJY0NClNvsaDr16RjzRO6GfqBvaL0SrYN3g41POeZ7zhxgHLeVYTCOnuGhs9Pc2KoyozcScjD9Bh4u4nMdlH3FWH9HzFtEbHIlnrZY3RA2CK3jB9RUTGqFtWGUI5F+luFUhtJNFqWuPTAmjjCMU0dI0YqKQeK1IKvJqXjzFOX9BD+FLE/Zd+stTaS9dJ/fxkpzrVsYmuVugn1cAvjzSKotZzluA67ziN8TzYka13YiF547vvibQxF0HvevzCTq5/ga9dZGguBYUvktX7IdRStSoMSlbgxAQtSPDFew6OrEf09d1KUSyV/FqFVVFGontAcrKdpWtp709yVOUVU0wBWqofl16f//Z">
</body>
</html>)rawliteral";
void setup(){
// Serial port for debugging purposes
Serial.begin(115200);
// Connect to Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.println("Connecting to WiFi..");
}
// Print ESP32 Local IP Address
Serial.println(WiFi.localIP());
// Route for root / web page
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
request->send_P(200, "text/html", index_html);
});
// Start server
server.begin();
}
void loop(){
}
坚持下去就能成功