当前位置: 首页 > 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);
http://www.lqws.cn/news/449911.html

相关文章:

  • .Net Framework 4/C# 进程和线程的使用
  • .NET 4.7中使用NLog记录日志到数据库表
  • 基于PyQt5和PaddleSpeech的中文语音识别系统设计与实现(Python)
  • 数字媒体专业核心课程体系以“艺术创意+数字科技+产业应用”三维融合
  • VSCode1.101.1Win多语言语言编辑器便携版安装教程
  • Can‘t resolve ‘react/jsx-runtime‘ in xxx
  • Vue框架深度解析:从Vue2到Vue3的技术演进与实践指南
  • day43-硬件学习之ARM基础知识
  • uniapp 微信小程序在线引入字体图标
  • 数据集-目标检测系列- 餐具叉子 数据集 fork >> DataBall
  • LibCpr: Windows环境下实现一个C++版本的Http客户端
  • Spring Cloud 服务调用详解:Ribbon 负载均衡与 Feign 声明式接口调用
  • 【MATLAB代码】制导方法介绍与例程——追踪法,适用于二维平面,目标是移动的|附完整源代码
  • C++基础算法————并查集
  • 【Dify精讲】第14章:部署架构与DevOps实践【知识卡片】
  • 虹科案例 | 欣旺达如何实现动力电池测试的长期稳定性+自动化?
  • 【NLP入门系列三】NLP文本嵌入(以Embedding和EmbeddingBag为例)
  • 高效获取速卖通商品实时数据:API 接口开发与接入全流程
  • ReAct
  • 【二进制安全作业】250617课上作业4 - start
  • Linux (2)
  • 【stm32】标准库学习——I2C
  • 指标解读——113页企业信息化成熟度评估指标【附全文阅读】
  • 算法第38天|322.零钱兑换\139. 单词拆分
  • C语言:二分搜索函数
  • 【Java学习笔记】线程基础
  • 【RTSP从零实践】2、使用RTP协议封装并传输H264
  • JetBrains IDE v2025.1 升级,AI 智能+语言支持齐飞
  • Maven 之工程化开发核心指南:插件配置、pom 文件与依赖管理
  • GreatSQL加入openKylin社区,共推开源生态建设