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

ESP32-HTML-08

一、html显示图片

1.工程包含Html需要显示的图片

2、CMakeLists.txt包含图片资源

举例:

idf_component_register(SRCS main.cEMBED_FILES root.html  favicon.ico)

3.html中图片的标签

<img src="motus.ico">

4.后台代码的添加

static esp_err_t motus_get_handler(httpd_req_t *req)
{extern const unsigned char favicon_ico_start[] asm("_binary_motus_ico_start");extern const unsigned char favicon_ico_end[]   asm("_binary_motus_ico_end");const size_t favicon_ico_size = (favicon_ico_end - favicon_ico_start);httpd_resp_set_type(req, "image/x-icon");httpd_resp_send(req, (const char *)favicon_ico_start, favicon_ico_size);return ESP_OK;
}static const httpd_uri_t html_motus_ico = {.uri       = "/motus.ico",.method    = HTTP_GET,.handler   = motus_get_handler,.user_ctx  = NULL
};httpd_register_uri_handler(server, &html_motus_ico);

二、html添加样式文件

1.工程包含Html需要的样式文件

2、CMakeLists.txt包含样式资源

idf_component_register(SRCS main.cEMBED_FILES root.html style.css favicon.ico motus.ico)

3.html中样式的链接

<link rel="stylesheet" type="text/css" href="style.css">

4.后台代码的添加

static esp_err_t css_get_handler(httpd_req_t *req)
{extern const unsigned char css_start[] asm("_binary_style_css_start");extern const unsigned char css_end[]   asm("_binary_style_css_end");const size_t css_size = (css_end - css_start);httpd_resp_set_type(req, "text/css");httpd_resp_send(req, (const char *)css_start, css_size);return ESP_OK;
}static const httpd_uri_t html_css = {.uri       = "/style.css",.method    = HTTP_GET,.handler   = css_get_handler,.user_ctx  = NULL
};httpd_register_uri_handler(server, &html_css);

三、html添加js文件

1.工程包含Html需要的js文件

2、CMakeLists.txt包含样式资源

idf_component_register(SRCS main.cEMBED_FILES root.html style.css script.js favicon.ico motus.ico)

3.html中js的链接

<script src="script.js"></script>

4.后台代码的添加

static esp_err_t js_get_handler(httpd_req_t *req)
{extern const unsigned char js_start[] asm("_binary_script_js_start");extern const unsigned char js_end[]   asm("_binary_script_js_end");const size_t js_size = (js_end - js_start);httpd_resp_set_type(req, "text/js");httpd_resp_send(req, (const char *)js_start, js_size);return ESP_OK;
}//得到用户名和密码
static const httpd_uri_t html_js = {.uri       = "/script.js",.method    = HTTP_GET,.handler   = js_get_handler,.user_ctx  = NULL
};httpd_register_uri_handler(server, &html_js);

相关文章:

  • 在 macOS 上部署 Akash Network 的完整 Shell 脚本解决方案
  • STM32[笔记]--开发环境的安装
  • python之使用cv2.matchTemplate识别缺口滑块验证码---实现最佳图像匹配
  • 让大模型“更懂人话”:对齐训练(RLHF DPO)全流程实战解析
  • 无人机不再“盲飞”!用Python搞定实时目标识别与跟踪
  • Python Minio库连接和操作Minio数据库
  • 局域网文件共享及检索系统
  • postgresql 函数调试
  • 第1章,[标签 Win32] :第一个 WIn32 程序,MessageBox 函数
  • 树莓派倾斜传感器实验指导书
  • Real-World Deep Local Motion Deblurring论文阅读
  • 高效调试 AI 大模型 API:用 Apipost 实现 SSE 流式解析与可视化
  • 浏览器调试核心技术指南:从基础到高级的完全掌握
  • OneCode 核心组件——APICaller介绍
  • VUE3 路由的跳转方法
  • 计算机——硬盘驱动器
  • 【编译原理】语句的翻译
  • Redis如何解决缓存击穿,缓存雪崩,缓存穿透
  • 实验问题记录:PyTorch Tensor 也会出现 a = b 赋值后,修改 a 会影响 b 的情况
  • Android 构建配置中的变量(通常在设备制造商或定制 ROM 的 AndroidProducts.mk 或产品配置文件中定义)
  • 本地网站开发环境搭建/seo优化技术厂家
  • 一流的句容网站建设/建站公司网站源码
  • 长沙网站开发流程/网站优化排名哪家好
  • 专做PPP项目网站/mac923水蜜桃923色号
  • 学做网站学java有用么/如何注册域名网站
  • 58招聘运营网站怎么做/讯展网站优化推广