Bluetooth: Multi-roles¶
1 功能概述¶
此项目演示了蓝牙多角色的功能。可以通过 zephyr shell
控制设备执行广播、扫描、连接(主和从)等。该工程默认支持Spark BLE Controller。
2 环境要求¶
board: pan108xxb5_evb/pan108xxb1_evb
uart: 显示串口log和shell交互
测试软件:SecureCRT,用于 shell 交互
测试软件 (option): nRF Connect
执行多连接时,需要多个支持蓝牙的设备。
3 编译和烧录¶
例程位置:zephyr\samples_panchip\bluetooth\mult_roles
使用 ZAL 工具可以对其进行编译、烧录、打开 VS Code 调试等操作。关于 ZAL 工具的详细介绍请参考:Zephyr APP Launcher 工具介绍。
4 演示说明¶
4.1 启动广播¶
uart:~$ ble adv conn_ind_start
Advertising successfully started
4.2 启动扫描¶
uart:~$ ble scan passive_start
Scanning successfully started
uart:~$ 00 > DF:70:4D:A2:0B:73 (random) (RSSI -38) (ADV_IND)
01 > F9:2F:61:83:FB:21 (random) (RSSI -47) (ADV_IND)
02 > 73:49:67:67:98:F0 (random) (RSSI -58) (ADV_NONCONN_IND)
03 > 7C:DA:B6:76:D2:6A (random) (RSSI -63) (ADV_IND)
04 > 4C:AC:5C:41:32:BC (random) (RSSI -62) (ADV_NONCONN_IND)
05 > 49:74:54:A3:4A:84 (random) (RSSI -61) (ADV_SCAN_IND)
06 > B2:00:66:66:66:66 (public) (RSSI -67) (ADV_IND)
07 > 02:DD:FF:B1:52:C0 (random) (RSSI -80) (ADV_NONCONN_IND)
08 > 34:A8:0C:C6:9B:01 (random) (RSSI -64) (ADV_NONCONN_IND)
09 > EE:25:6B:3E:BB:50 (random) (RSSI -43) (ADV_IND)
10 > 68:0D:97:00:F2:A3 (random) (RSSI -74) (ADV_IND)
11 > 74:6E:3D:F1:30:E6 (random) (RSSI -61) (ADV_IND)
12 > 0A:00:04:E7:1D:0D (random) (RSSI -40) (ADV_NONCONN_IND)
13 > 3B:B1:72:CF:41:09 (random) (RSSI -65) (ADV_NONCONN_IND)
14 > 00:00:66:66:66:66 (public) (RSSI -67) (ADV_IND)
15 > 2C:00:E2:51:CF:78 (random) (RSSI -69) (ADV_NONCONN_IND)
16 > 28:F6:3D:72:5F:DA (random) (RSSI -56) (ADV_NONCONN_IND)
17 > 10:ED:A7:B9:FC:C6 (random) (RSSI -55) (ADV_NONCONN_IND)
18 > ED:67:38:6E:AF:D9 (public) (RSSI -82) (ADV_IND)
19 > 44:EE:AA:A4:4A:E8 (random) (RSSI -79) (ADV_NONCONN_IND)
20 > 51:D1:F7:DF:E0:28 (random) (RSSI -50) (ADV_NONCONN_IND)
21 > 1A:0E:20:DC:3A:F6 (random) (RSSI -58) (ADV_NONCONN_IND)
22 > 5D:38:F7:34:BA:AE (random) (RSSI -81) (ADV_IND)
23 > 6E:3C:83:36:57:0D (random) (RSSI -60) (ADV_SCAN_IND)
24 > A4:C1:38:B0:FF:DB (public) (RSSI -62) (ADV_IND)
25 > C4:18:0E:A0:D5:09 (random) (RSSI -54) (ADV_IND)
26 > 1C:4F:2C:82:1F:40 (random) (RSSI -58) (ADV_NONCONN_IND)
27 > 18:C5:FC:43:3B:92 (random) (RSSI -73) (ADV_NONCONN_IND)
28 > 1E:94:89:F4:9C:76 (random) (RSSI -86) (ADV_NONCONN_IND)
29 > E2:AC:EF:81:3B:4A (random) (RSSI -60) (ADV_IND)
30 > 13:1B:C8:A8:F4:F8 (random) (RSSI -79) (ADV_NONCONN_IND)
31 > 04:7A:0B:1A:0F:59 (public) (RSSI -82) (ADV_NONCONN_IND)
32 > 27:9C:98:51:1B:0C (random) (RSSI -81) (ADV_NONCONN_IND)
33 > 6B:9C:DF:F2:8B:30 (random) (RSSI -59) (ADV_IND)
34 > 2B:51:AE:13:D1:A8 (random) (RSSI -77) (ADV_NONCONN_IND)
35 > 0D:0E:80:E4:D7:04 (random) (RSSI -64) (ADV_NONCONN_IND)
36 > 62:05:19:58:28:D7 (random) (RSSI -63) (ADV_NONCONN_IND)
37 > 3A:84:B7:59:C4:3F (random) (RSSI -90) (ADV_NONCONN_IND)
38 > 60:34:B9:65:31:CF (random) (RSSI -79) (ADV_NONCONN_IND)
39 > 36:E4:8A:F3:F7:23 (random) (RSSI -82) (ADV_NONCONN_IND)
40 > E1:3F:65:E6:53:CD (random) (RSSI -85) (ADV_NONCONN_IND)
41 > 46:B0:92:45:CD:8D (random) (RSSI -82) (ADV_IND)
42 > 4C:76:8B:F8:24:C1 (random) (RSSI -65) (ADV_IND)
43 > D7:75:F8:33:4B:2A (random) (RSSI -91) (ADV_NONCONN_IND)
44 > 67:8B:97:4E:EF:F6 (random) (RSSI -91) (ADV_NONCONN_IND)
45 > 3F:50:3C:4A:84:89 (random) (RSSI -82) (ADV_NONCONN_IND)
46 > 7D:70:67:40:A9:67 (random) (RSSI -82) (ADV_IND)
47 > 3F:DA:2F:47:12:29 (random) (RSSI -93) (ADV_NONCONN_IND)
48 > E5:E0:F0:50:7F:97 (random) (RSSI -84) (ADV_IND)
49 > 58:9A:55:F1:65:25 (random) (RSSI -62) (ADV_NONCONN_IND)
50 > 60:74:57:2E:D2:41 (random) (RSSI -91) (ADV_IND)
51 > 30:95:87:F4:A5:54 (public) (RSSI -93) (ADV_NONCONN_IND)
52 > FD:9A:1D:10:CE:83 (random) (RSSI -62) (ADV_IND)
53 > 33:36:30:37:07:37 (random) (RSSI -39) (ADV_NONCONN_IND)
54 > D6:A7:F5:CA:9E:AC (random) (RSSI -63) (ADV_NONCONN_IND)
55 > 5E:56:91:15:80:3A (random) (RSSI -39) (ADV_IND)
56 > 12:52:6F:6F:DA:DD (random) (RSSI -63) (ADV_NONCONN_IND)
57 > 51:61:07:CF:92:59 (random) (RSSI -88) (ADV_NONCONN_IND)
58 > 20:23:50:41:63:32 (random) (RSSI -86) (ADV_NONCONN_IND)
59 > 12:80:3E:2D:8C:31 (random) (RSSI -95) (ADV_NONCONN_IND)
60 > F2:15:46:0A:A2:56 (random) (RSSI -88) (ADV_NONCONN_IND)
61 > F2:65:C0:19:E2:AE (random) (RSSI -59) (ADV_IND)
62 > 0A:31:C7:F2:91:65 (random) (RSSI -89) (ADV_NONCONN_IND)
63 > 5C:1E:21:AC:64:40 (random) (RSSI -89) (ADV_NONCONN_IND)
64 > E5:05:B4:9F:AD:C7 (random) (RSSI -80) (ADV_IND)
65 > 1F:5A:52:53:75:47 (random) (RSSI -91) (ADV_NONCONN_IND)
66 > 11:7C:D4:23:66:7C (random) (RSSI -92) (ADV_NONCONN_IND)
67 > 71:76:1D:D5:FF:AA (random) (RSSI -94) (ADV_IND)
68 > 53:15:F8:47:0B:2A (random) (RSSI -82) (ADV_NONCONN_IND)
69 > D8:4E:C1:6B:E1:CE (random) (RSSI -60) (ADV_NONCONN_IND)
70 > 48:B4:6D:DA:AA:5D (random) (RSSI -94) (ADV_IND)
71 > 55:E9:1B:09:EE:D9 (random) (RSSI -70) (ADV_IND)
72 > D1:F0:A6:C1:4E:86 (random) (RSSI -78) (ADV_NONCONN_IND)
73 > 05:EF:65:04:BD:CB (random) (RSSI -86) (ADV_NONCONN_IND)
74 > C2:2F:C1:EA:2F:D8 (random) (RSSI -81) (ADV_IND)
75 > 08:AF:AF:9C:BE:35 (random) (RSSI -64) (ADV_NONCONN_IND)
76 > 3B:B8:E8:27:5A:5F (random) (RSSI -88) (ADV_NONCONN_IND)
77 > 5A:E6:3D:61:4A:13 (random) (RSSI -86) (ADV_IND)
78 > DF:5D:FE:53:77:0B (random) (RSSI -60) (ADV_NONCONN_IND)
79 > D1:CB:11:95:9C:4A (random) (RSSI -92) (ADV_NONCONN_IND)
80 > 41:89:3D:18:DF:34 (random) (RSSI -90) (ADV_IND)
81 > E7:F5:06:FE:5C:FD (random) (RSSI -86) (ADV_IND)
82 > 58:B6:23:76:DF:E4 (public) (RSSI -86) (ADV_IND)
83 > 5C:C5:63:46:E0:8F (public) (RSSI -80) (ADV_IND)
84 > 2C:20:AC:06:06:83 (random) (RSSI -89) (ADV_NONCONN_IND)
85 > 48:BB:7A:3D:64:58 (random) (RSSI -84) (ADV_NONCONN_IND)
86 > 6B:FC:8D:82:53:6A (random) (RSSI -91) (ADV_NONCONN_IND)
87 > EA:A7:14:E3:D4:EB (random) (RSSI -63) (ADV_NONCONN_IND)
88 > F6:CC:36:3A:69:AA (random) (RSSI -88) (ADV_NONCONN_IND)
89 > C2:A7:8C:B8:6F:10 (random) (RSSI -64) (ADV_NONCONN_IND)
90 > F5:1E:7B:B6:60:D1 (random) (RSSI -76) (ADV_NONCONN_IND)
91 > D8:5A:4A:68:08:30 (random) (RSSI -80) (ADV_NONCONN_IND)
92 > A4:C1:38:1A:E0:18 (public) (RSSI -66) (ADV_IND)
93 > FA:4A:0D:71:7F:38 (random) (RSSI -72) (ADV_IND)
94 > 2C:69:2C:A9:F0:1B (random) (RSSI -89) (ADV_NONCONN_IND)
95 > 73:C4:5B:DF:10:FD (random) (RSSI -90) (ADV_IND)
96 > 5E:ED:51:36:37:EB (random) (RSSI -64) (ADV_IND)
97 > F9:BD:0C:98:95:DE (random) (RSSI -89) (ADV_NONCONN_IND)
98 > 48:44:E9:40:2C:28 (random) (RSSI -91) (ADV_IND)
99 > 65:B6:B1:F1:87:75 (random) (RSSI -101) (ADV_NONCONN_IND)
需要注意的是:
当前可以存储100条设备信息,当扫描到的设备信息存储满时,将自动终止扫描。
发起连接(
ble conn create
)时如果当前处于扫描状态,则会终止扫描后启动连接
4.3 显示设备信息¶
显示扫描、连接设备列表信息。
uart:~$ ble devs show
Detected List:
00 > 33:3F:EB:31:17:13 (random) (RSSI -69) (ADV_NONCONN_IND)
01 > 6D:75:F8:4D:49:CB (random) (RSSI -46) (ADV_NONCONN_IND)
02 > A4:C1:38:16:32:40 (public) (RSSI -61) (ADV_IND)
03 > 04:80:A5:62:3F:4A (random) (RSSI -78) (ADV_NONCONN_IND)
04 > 3C:92:C8:CF:B4:CF (random) (RSSI -65) (ADV_NONCONN_IND)
05 > B2:00:66:66:66:66 (public) (RSSI -67) (ADV_IND)
06 > 2B:43:FB:0D:79:CF (random) (RSSI -61) (ADV_NONCONN_IND)
07 > 06:BD:AA:E3:2E:15 (random) (RSSI -77) (ADV_NONCONN_IND)
08 > 56:1E:24:79:32:85 (random) (RSSI -67) (ADV_IND)
09 > 3D:F9:3C:94:70:8F (random) (RSSI -72) (ADV_NONCONN_IND)
10 > EE:25:6B:3E:BB:50 (random) (RSSI -39) (ADV_IND)
11 > 65:F2:FE:51:3F:BB (random) (RSSI -63) (ADV_NONCONN_IND)
12 > F4:EE:25:66:65:66 (random) (RSSI -68) (ADV_IND)
13 > 53:50:95:CF:9E:5F (random) (RSSI -71) (ADV_NONCONN_IND)
14 > F3:C4:F6:FB:B6:C8 (random) (RSSI -68) (ADV_NONCONN_IND)
15 > 1C:48:38:89:3F:1F (random) (RSSI -75) (ADV_NONCONN_IND)
16 > 76:E6:16:0D:41:4E (random) (RSSI -65) (ADV_IND)
17 > 07:51:DA:0D:A6:F2 (random) (RSSI -63) (ADV_NONCONN_IND)
18 > 4C:22:B7:6C:11:6B (random) (RSSI -70) (ADV_NONCONN_IND)
19 > 70:A0:B6:72:0E:03 (random) (RSSI -71) (ADV_NONCONN_IND)
20 > 0E:1D:22:D5:5C:C4 (random) (RSSI -38) (ADV_NONCONN_IND)
21 > C9:C5:9E:AB:C4:8D (random) (RSSI -68) (ADV_IND)
22 > 65:98:A0:ED:EE:77 (random) (RSSI -76) (ADV_IND)
23 > DB:3E:49:AF:87:4F (random) (RSSI -71) (ADV_IND)
Connected List:
- Empty
4.4 与设备建立连接¶
在与设备建立连接时,需要先获取待连接设备的编号,可以通过 ble devs show
获取。
如下命令,表示将与 Detected List
列表中编号为05
的设备建立连接:
uart:~$ ble conn create 5
Connecting ...
uart:~$ Connect to 74:AC:D5:CF:97:3A (random) successful
配置2主3从,连接成功后通过ble devs show
显示连接好的设备:
Connected List:
00 > Device Central
Local : C3:F3:A7:8F:C4:F3 (random)
Remote: DD:39:EA:81:08:62 (random)
01 > Device Central
Local : C3:F3:A7:8F:C4:F3 (random)
Remote: D5:D9:BF:49:71:3F (random)
02 > Device Peripheral
Local : C3:F3:A7:8F:C4:F3 (random)
Remote: 7F:F0:E0:3F:95:FA (random)
03 > Device Peripheral
Local : C3:F3:A7:8F:C4:F3 (random)
Remote: 59:0C:30:57:14:40 (random)
04 > Device Peripheral
Local : C3:F3:A7:8F:C4:F3 (random)
Remote: 6F:45:60:47:8A:14 (random)
5 其它说明¶
5.1 配置¶
项目配置文件: prj.conf
,其中包含了 Bluetooth
、shell
、debug
等的一些配置。
Host支持的最大连接数量由如下参数配置:
CONFIG_BT_MAX_CONN=8
Spark BLE Controller配置参数
CONFIG_BT_SPARK_BLE_CONTROLLER_EN=y //enable spark ble controller
CONFIG_BT_CTLR_MAX_MST_CONN=4 //配置最大支持的Master connection个数
CONFIG_BT_CTLR_MAX_SLV_CONN=4 // 配置最大支持的Slave connection个数
5.2 shell
命令¶
shell
支持的 ble
命令
ble - BLE commands
Subcommands:
adv :LE Advertising commands
Subcommands:
conn_ind_start :LE Start Advertising with ADV_IND command
nonconn_ind_start :LE Start Advertising with ADV_NONCONN_IND command
stop :LE Stop Advertising command
scan :LE Scanning commands
Subcommands:
passive_start :LE Start Passive Scanning command
active_start :LE Start Active Scanning command
stop :LE Stop Scanning command
conn :LE Connection commands
Subcommands:
create :LE Create Connection command
disconn :Disconnect command
devs :LE Device Status commands
Subcommands:
show :Display BLE Devices command
clear :Clear Detected List command
reset :Reset commands
6 RAM/Flash资源使用情况¶
Memory region Used Size Region Size %age Used
FLASH: 96312 B 384 KB 24.49%
SRAM: 38792 B 46 KB 82.35%