这个页面的 最新开发版本 可能比这个发布的 2.1.0rc1 版本新。

Bluetooth: Central/sc general

概述

本示例演示了使能 BLE 中央设备角色,和 Central general 示例不同的是, 本示例支持加密流程。 在连接建立后,用户可以在控制台下输入相关的指令以完成配对流程,比如发起安全流程、设置 IO 能力和根据提示,输入配对码。

配对指令 (cli commands)

security:
  • 发起配对流程.

auth_method:
  • 设置设备输入输出能力,支持display, display and yes/no, input, no-input-no-output, display and input.

auth_passkey:
  • 给对方设备回复配对码.

auth_cancel:
  • 取消配对流程.

auth_passkey_confirm:
  • 确认配对码正确.

auth_pairing_confirm
  • 确认配对流程.

环境要求

  • 支持 BLE 功能的开发板

编译和烧录

示例位置:

examples/bluetooth/central_sc_general

编译、烧录等操作请参考:[快速入门](https://doc.winnermicro.net/w800/zh_CN/2.1.0rc1/get_started/index.html)

运行结果

[I] (34) main: ver: 0.9.0 build at Sep 12 2024 16:18:17

[I] (90) bt: LE SC enabled
[I] (216) bt: No ID address. App must call settings_load()
[I] (218) bt: Identity: 28:6D:CD:55:E4:57 (public)
[I] (218) bt: HCI: version 4.2 (0x08) revision 0x0709, manufacturer 0x070c
[I] (218) bt: LMP: version 4.2 (0x08) subver 0x0709
[I] (236) sc_central: Bluetooth initialized
[I] (238) sc_central: Scanning successfully started
[I] (29730) sc_central: Device found: 28:6D:CD:68:D7:99 (public) (RSSI -38)
[I] (30046) sc_central: Updated MTU: TX: 23 RX: 23 bytes
[I] (30046) sc_central: Connected: 28:6D:CD:68:D7:99 (public)

[I] (30046) sc_central: mtu_exchange: Current MTU = 23
[I] (30046) sc_central: mtu_exchange: Exchange MTU...
[I] (30048) bt: auth_req:0x0d, init_key:0x05, resp_key:0x07
[I] (30436) sc_central: Updated MTU: TX: 247 RX: 247 bytes
[I] (30438) sc_central: mtu_exchange_cb: MTU exchange successful (247)
[I] (30438) sc_central: Remote pairing features: IO: 0x00, OOB: 0, AUTH: 0x0d, Key: 16, Init Kdist: 0x04, Resp Kdist: 0x04
[I] (30536) sc_central: input passkey for 28:6D:CD:68:D7:99 (public)

[I] (30686) sc_central: LE conn  param req: 28:6D:CD:68:D7:99 (public) int (0x0010, 0x0014) lat 0 to 500

[I] (31036) sc_central: LE conn param updated: 28:6D:CD:68:D7:99 (public) int 0x0014 lat 0 to 500

auth_passkey 764892

[W] (49844) bt: chan 0x2000415c conn 0x20003cd4 handle 0 encrypt 0x01 hci status 0x00
[I] (49844) sc_central: Security changed: 28:6D:CD:68:D7:99 (public) level 4

[I] (49884) sc_central: BONDED with 28:6D:CD:68:D7:99 (public)