跳转到内容

Zephyr BLE Server

zephyr_ble_server 组件在运行 Zephyr RTOS 的设备上启用蓝牙低功耗 GATT 服务器。它支持安全配对流程,包括蓝牙规范中定义的 数字比较 密码 确认模型。

# 示例配置条目
zephyr_ble_server:
on_numeric_comparison_request:
then:
- logger.log:
format: "Compare this passkey with the one on your BLE device: %06d"
args: [passkey]
- ble_server.numeric_comparison_reply:
accept: true

当 BLE 设备请求数字比较时,将触发此自动化。

zephyr_ble_server:
on_numeric_comparison_request:
then:
- logger.log:
format: "Compare this passkey with the one on your BLE device: %06d"
args: [passkey]
- ble_server.numeric_comparison_reply:
accept: true

ble_server.numeric_comparison_reply 动作

Section titled “ble_server.numeric_comparison_reply 动作”

此动作在数字比较后触发一次身份验证尝试。

使用示例:

on_...:
then:
- ble_server.numeric_comparison_reply:
accept: true
  • accept (必选, boolean, 可模板化): 如果两台 BLE 设备上显示的密码匹配,应为 true。

自动接受数字比较的安全连接:

zephyr_ble_server:
on_numeric_comparison_request:
then:
- logger.log:
format: "Compare this passkey with the one on your BLE device: %06d"
args: [passkey]
- ble_server.numeric_comparison_reply:
accept: true

通过 lambda 接受数字比较的安全连接:

zephyr_ble_server:
on_numeric_comparison_request:
then:
- logger.log:
format: "Compare this passkey with the one on your BLE device: %06d"
args: [passkey]
- ble_server.numeric_comparison_reply:
accept: !lambda "return true;"