ESP32 BLE mesh api研究
1. demo使用
a. 文档介绍/功能介绍
ESP-BLE-MESH - ESP32 - — ESP-IDF 编程指南 latest 文档
相关ESP32 BLE mesh资料如上
ⅰ. 功能Feature
Mesh 核心
- 入网
-
- PB-ADV,PB-GATT,PB-Remote
- OOB 验证
- 基于证书的入网
- 远程入网
- 增强入网验证
- 网络
-
- 中继
- 分包和重组
- 密钥更新程序
- IV 更新程序
- 朋友节点
- 低功耗节点
- 代理服务器
- 代理客户端
- 定向转发
- 私有信标
- 子网桥
- 次要增强
- 多个客户端模型同时运行
-
- 支持多个客户端模型同时向不同节点发送数据包
- 客户端模型与服务器模型之间无阻塞
- NVS 存储
-
- 存储 ESP-BLE-MESH 节点的入网和配置信息
Mesh 模型
- 基础模型
-
- 配置服务器模型
- 配置客户端模型
- 健康服务器模型
- 健康客户端模型
- 远程供应服务器模型
- 远程供应客户端模型
- 定向转发配置服务器模型
- 定向转发配置客户端模型
- 桥接配置服务器模型
- 桥接配置客户端模型
- Mesh 专用信标服务器模型
- Mesh 专用信标客户端模型
- 按需提供的专用代理服务器模型
- 按需提供的专用代理客户端模型
- SAR 配置服务器模型
- SAR 配置客户端模型
- 请求 PDU RPL 配置服务器模型
- 请求 PDU RPL 配置客户端模型
- 操作码聚合器服务器模型
- 操作码聚合器客户端模型
- 大型合成数据服务器模型
- 大型合成数据客户端模型
- 通用客户端模型
-
- 通用开关客户端
- 通用电平客户端
- 通用默认过渡时间客户端
- 通用电源开关客户端
- 通用功率电平客户端
- 通用电池客户端
- 通用位置客户端
- 通用属性客户端
- 传感器客户端模型
-
- 传感器客户端
- 时间与场景客户端模型
-
- 时间客户端
- 场景客户端
- 调度器客户端
- 照明客户端模型
-
- 灯光亮度客户端
- 灯光 CTL 客户端
- 灯光 HSL 客户端
- 灯光 xyL 客户端
- 灯光 LC 客户端
- 通用服务器模型
-
- 通用开关服务器
- 通用电平服务器
- 通用默认过渡时间服务器
- 通用电源开关服务器
- 通用电源开关设置服务器
- 通用功率电平服务器
- 通用功率电平设置服务器
- 通用电池服务器
- 通用位置服务器
- 通用位置设置服务器
- 通用用户属性服务器
- 通用管理员属性服务器
- 通用制造商属性服务器
- 通用客户端属性服务器
- 传感器服务器模型
-
- 传感器服务器
- 传感器设置服务器
- 时间和场景服务器模型
-
- 时间服务器
- 时间设置服务器
- 场景服务器
- 场景设置服务器
- 调度器服务器
- 调度器设置服务器
- 照明服务器模型
-
- 灯光亮度服务器
- 灯光亮度设置服务器
- 灯光 CTL 服务器
- 灯光 CTL 温度服务器
- 灯光 CTL 设置服务器
- 灯光 HSL 服务器
- 灯光 HSL 色调服务器
- 灯光 HSL 饱和度服务器
- 灯光 HSL 设置服务器
- 灯光 xyL 服务器
- 灯光 xyL 设置服务器
- 灯光 LC 服务器
- 灯光 LC 设置服务器
ⅱ. 架构
ESP-BLE-MESH 架构主要由以下 5 大部分组成:
Mesh 协议栈
-
Mesh Networking
负责 ESP-BLE-MESH 节点的网络消息处理等。Mesh Provisioning
负责 ESP-BLE-MESH 设备的启动配置流程。Mesh Models
负责实现 SIG 定义的模型。
网络管理
-
- 负责实现网络管理程序,包括节点删除程序、网络索引 (IV Index) 恢复程序等。
特性
-
- 包括 ESP-BLE-MESH 特性,如低功耗特性、好友特性、中继特性等。
Mesh 承载层
-
- 包括
广播承载层
和GATT 承载层
。承载层对于 ESP-BLE-MESH 协议栈至关重要,因为协议栈基于蓝牙低功耗技术构建而成,其必须利用承载层通过 BLE 广播通道和连接通道进行数据传输。
- 包括
应用程序
-
- 基于 ESP-BLE-MESH 协议栈和
Mesh Models
。 - 通过调用 API 和处理事件,
Applications
实现了与 ESP-BLE-MESH 协议栈中的Mesh Networking
和Mesh Provisioning
的交互,也实现了与Mesh Models
中一系列模型的交互。
- 基于 ESP-BLE-MESH 协议栈和
b. 手机app安装
我是下载的nrf mesh这个apk,可以自行去网上下载
c. 开发使用
ⅰ. 选择example
我们选择onoff_server的example工程
另外这里会有更多的测试demo,来达到不同的验证目的,各位可以自行下载使用
- bluetooth/esp_ble_mesh/onoff_models/onoff_server 展示了将 ESP-BLE-MESH 作为拥有 Configuration Server model 和 Generic OnOff Server model 的节点的用法。
- bluetooth/esp_ble_mesh/onoff_models/onoff_client 展示了 Generic OnOff Client model 如何在节点内工作。节点拥有 Configuration Server model 和 Generic OnOff Client model。
- bluetooth/esp_ble_mesh/provisioner 展示了设备如何充当 ESP-BLE-MESH Provisioner 以配网设备。Provisioner 拥有 Configuration Client model 和 Generic OnOff Client model。
- bluetooth/esp_ble_mesh/fast_provisioning/fast_prov_client 与 bluetooth/esp_ble_mesh/fast_provisioning/fast_prov_server 展示了如何快速配网,配网 100 个设备费时不超过 60 秒。
- bluetooth/esp_ble_mesh/sensor_models/sensor_client 与 bluetooth/esp_ble_mesh/sensor_models/sensor_server 分别演示如何在 Provisioner 中创建 Sensor Client model 以及在未配网设备中创建 Sensor Server model 与 Sensor Setup Server model。
- bluetooth/esp_ble_mesh/vendor_models/vendor_client 与 bluetooth/esp_ble_mesh/vendor_models/vendor_server 分别演示如何在 Provisioner 中创建 Vendor Client model 以及在未配网设备中创建 Vendor Server model。
- bluetooth/esp_ble_mesh/wifi_coexist 展示了 Wi-Fi 和 ESP-BLE-MESH 共存的功能。简而言之,用户可在运行 ESP-BLE-MESH 时使用 Wi-Fi。
- bluetooth/esp_ble_mesh/remote_provisioning/rpr_client, bluetooth/esp_ble_mesh/remote_provisioning/rpr_server 与 bluetooth/esp_ble_mesh/remote_provisioning/unprov_dev 演示了 mesh 协议 v1.1 中新增的远程配网功能。
- bluetooth/esp_ble_mesh/remote_provisioning/rpr_client 与 bluetooth/esp_ble_mesh/remote_provisioning/rpr_server 演示 mesh 协议 v1.1 中新增的定向转发功能。只有路径上的节点才会对定向消息进行转发,而其他节点不参与转发。
ⅱ. 修改board LED等的控制
https://github.com/sj15712795029/esp32_study/tree/main/4_bluetooth/5_ble_mesh_onoff_server
可以看下这个工程!!
ⅲ. 编译工程/下载
我们已经在前面很多文章已经介绍过编译/下载了,所以我们不额外赘述了,烧录完毕就有了这个效果
ⅳ. 验证
步骤一: 手机扫描
步骤二:Generic provisioning layer Link establish
步骤三:Provisioning
步骤四:BIND KEY
步骤五:控灯
点击这个ON/OFF就可以控制我们开发板中的灯了!
2. API介绍
对于应用层的接口如下: