当前位置: 首页 > news >正文

ESP32-CAM实验集(WebServer)

WebServer
效果图

已连接
在这里插入图片描述
在这里插入图片描述

web端
在这里插入图片描述

platformio.ini
; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html[env:esp32]
platform = espressif32
framework = arduino
board = esp32dev
源代码
/* ESP32 HTTP IoT Server Example for Wokwi.comhttps://wokwi.com/arduino/projects/320964045035274834When running it on Wokwi for VSCode, you can connect to thesimulated ESP32 server by opening http://localhost:8180in your browser. This is configured by wokwi.toml.
*/#include <WiFi.h>
#include <WiFiClient.h>
#include <WebServer.h>
#include <uri/UriBraces.h>// #define WIFI_SSID "Wokwi-GUEST"
// #define WIFI_PASSWORD ""
#define WIFI_SSID "iQOO Neo6"
#define WIFI_PASSWORD "yyuuiioo"
// Defining the WiFi channel speeds up the connection:
#define WIFI_CHANNEL 6WebServer server(80);const int LED1 = 2;
const int LED2 = 4;bool led1State = false;
bool led2State = false;void sendHtml()
{String response = R"(<!DOCTYPE html><html><head><meta charset="UTF-8"><!-- 其他原有头部标签内容 --><title>ESP32 Web Server Demo</title><meta name="viewport" content="width=device-width, initial-scale=1"><style>html { font-family: sans-serif; text-align: center; }body { display: inline-flex; flex-direction: column; }h1 { margin-bottom: 1.2em; } h2 { margin: 0; }div { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: auto auto; grid-auto-flow: column; grid-gap: 1em; }.btn { background-color: #5B5; border: none; color: #fff; padding: 0.5em 1em;font-size: 2em; text-decoration: none }.btn.OFF { background-color: #333; }</style></head><body><h1>ESP32 Web Server</h1><div><h2>蓝色LED 灯</h2><a href="/toggle/1" class="btn LED1_TEXT">LED1_TEXT</a><h2>绿色的LED 灯</h2><a href="/toggle/2" class="btn LED2_TEXT">LED2_TEXT</a></div></body></html>)";response.replace("LED1_TEXT", led1State ? "ON" : "OFF");response.replace("LED2_TEXT", led2State ? "ON" : "OFF");server.send(200, "text/html", response);
}void setup(void)
{Serial.begin(115200);pinMode(LED1, OUTPUT);pinMode(LED2, OUTPUT);WiFi.begin(WIFI_SSID, WIFI_PASSWORD, WIFI_CHANNEL);Serial.print("Connecting to WiFi ");Serial.print(WIFI_SSID);// Wait for connectionwhile (WiFi.status() != WL_CONNECTED){delay(2000);Serial.print("Wait for connection .");}Serial.println(" Connected!");Serial.print("IP address: ");Serial.println(WiFi.localIP());server.on("/", sendHtml);server.on(UriBraces("/toggle/{}"), [](){String led = server.pathArg(0);Serial.print("Toggle LED #");Serial.println(led);switch (led.toInt()) {case 1:led1State = !led1State;if (led1State){Serial.print("打开");}else{Serial.print("关闭");}Serial.println("蓝色LED");digitalWrite(LED1, led1State);break;case 2:led2State = !led2State;if (led2State){Serial.print("打开");}else{Serial.print("关闭");}Serial.println("打开绿色LED");digitalWrite(LED2, led2State);break;}sendHtml(); });server.begin();Serial.println("HTTP server started (http://" + WiFi.localIP().toString() + ":80)");
}void loop(void)
{server.handleClient();delay(2);
}
http://www.lryc.cn/news/527692.html

相关文章:

  • Case逢无意难休——深度解析JAVA中case穿透问题
  • Golang笔记——常用库context和runtime
  • 2000-2020年各省第二产业增加值占GDP比重数据
  • unity商店插件A* Pathfinding Project如何判断一个点是否在导航网格上?
  • Day24-【13003】短文,数据结构与算法开篇,什么是数据元素?数据结构有哪些类型?什么是抽象类型?
  • 富文本 tinyMCE Vue2 组件使用简易教程
  • 强化学习在自动驾驶中的实现与挑战
  • 记录 | MaxKB创建本地AI智能问答系统
  • 特种作业操作之低压电工考试真题
  • [免费]基于Python的Django博客系统【论文+源码+SQL脚本】
  • Cannot resolve symbol ‘XXX‘ Maven 依赖问题的解决过程
  • 我们需要有哪些知识体系,知识体系里面要有什么哪些内容?
  • 什么是vue.js组件开发,我们需要做哪些准备工作?
  • 网络工程师 (3)指令系统基础
  • 第4章 神经网络【1】——损失函数
  • 【Python】第五弹---深入理解函数:从基础到进阶的全面解析
  • 【MQ】如何保证消息队列的高性能?
  • RAG是否被取代(缓存增强生成-CAG)吗?
  • 用C++编写一个2048的小游戏
  • 为何SAP S4系统中要设置MRP区域?MD04中可否同时显示工厂级、库存地点级的数据?
  • Windows10官方系统下载与安装保姆级教程【U盘-官方ISO直装】
  • 第05章 07 切片图等值线代码一则
  • 【深度学习】线性回归的简洁实现
  • 渗透测试技法之口令安全
  • 【R语言】数学运算
  • 小游戏源码开发搭建技术栈和服务器配置流程
  • 深度学习|表示学习|卷积神经网络|输出维度公式|15
  • cpp智能指针
  • 【面试题】 Java 三年工作经验(2025)
  • MOS的体二极管能通多大电流