Bluetooth: Mesh Demo¶
2 环境要求¶
board: pan108xxb5_evb * 2(A&B),pan1020 Mesh Demo板(用于测试,其他1080板入网PanMesh也可以,记为C板)
uart (option): 显示串口log
测试软件: PanMesh
3 编译和烧录¶
例程位置:zephyr\samples_panchip\bluetooth\mesh_demo
使用 ZAL 工具可以对其进行编译、烧录、打开 VS Code 调试等操作。关于 ZAL 工具的详细介绍请参考:Zephyr APP Launcher 工具介绍。
4 演示说明¶
4.1 测试Friend-LPN流程¶
运行脚本
quick_build_samples\bluetooth\mesh_demo_firend.bat
,编译后进行烧录至 pan108xxb5_evb A运行脚本
quick_build_samples\bluetooth\mesh_demo_low_power_node.bat
,编译后进行烧录至 pan108xxb5_evb B观察Friend-LPN建立及轮询过程
将code内的netkey&appkey提取到PanMesh(或者将PanMesh中的key更新到代码内),入网其他Mesh板,通过Mesh 网络对LPN进行开关操作,验证Friend-LPN交互流程
friend连接建立log
bt_mesh_friend.bt_mesh_friend_poll: Friendship established with 0x0002
friend开始轮询log
bt_mesh_friend.buf_send_end: Waiting 30000 ms for next poll
lpn连接已建立log
bt_mesh_lpn.lpn_timeout: state: established
lpn轮询周期log
bt_mesh_lpn.poll_timeout: Poll Timeout is 26790ms
建立连接后,通过PanMesh处理好key信息入网C板,连接C板作为proxy,通过Vendor Message界面发送给LPN一条控制消息如图
0000代表关灯,0100代表开灯
friend为lpn存储message log
bt_mesh_friend.friend_lpn_enqueue_rx: Queued message for LPN 0x0002, queue_size 1
30s的friend poll到达时,friend为lpn节点发送存储消息,成功开/关灯。
4.2 测试Heartbeat publish流程¶
运行脚本
quick_build_samples\bluetooth\mesh_demo.bat
,编译后进行烧录至 pan108xxb5_evb A运行脚本
quick_build_samples\bluetooth\mesh_demo_heartbeat_publisher.bat
,编译后进行烧录至 pan108xxb5_evb B观察打印log如下
板A:
Log打印
Subscribing to heartbeat messages
不丢包情况下,每4s收取一次heartbeat publish消息
[16:51:20.480]收←◆*** Booting Zephyr OS build zephyr-v2.7.0-220-g27db6b8446e7 *** Initializing...mesh_adhoc board_init Unicast address: 0x0003 [16:51:20.523]收←◆RCL_CTRL = 0x00000000 [16:51:20.648]收←◆Bluetooth initialized gen_onoff_init Mesh initialized Provisioning completed Configuring... Configuration complete Subscribing to heartbeat messages [00:00:00.001,000] <wrn> bt_hci_core: Failed to set device name (-12) [00:00:00.176,000] <inf> bt_hci_core: Identity: D4:4B:52:E4:BF:CD (random) [00:00:00.176,000] <inf> bt_hci_core: HCI: version 5.1 (0x0a) revision 0x0003, manufacturer 0x07d1 [00:00:00.176,000] <inf> bt_hci_core: LMP: version 5.1 (0x0a) subver 0x0000 [00:00:00.177,000] <inf> bt_mesh_main: Primary Element: 0x0003 [00:00:00.177,000] <dbg> bt_mesh_main.bt_mesh_provision: net_idx 0x0000 flags 0x00 iv_index 0x0000 [16:51:28.517]收←◆heartbeat board_heartbeat,hops = 1, feat = 1 [16:51:32.653]收←◆heartbeat board_heartbeat,hops = 1, feat = 1 [16:51:40.930]收←◆heartbeat board_heartbeat,hops = 1, feat = 1 [16:51:45.153]收←◆heartbeat board_heartbeat,hops = 1, feat = 1
板B:
Log打印
Publishing heartbeat messages
*** Booting Zephyr OS build zephyr-v2.7.0-220-g27db6b8446e7 *** Initializing...mesh_adhoc board_init Unicast address: 0x000f RCL_CTRL = 0x00000000 Bluetooth initialized gen_onoff_init Mesh initialized Provisioning completed Configuring... Publishing heartbeat messages Configuration complete [00:00:00.001,000] <wrn> bt_hci_core: Failed to set device name (-12) [00:00:00.175,000] <inf> bt_hci_core: Identity: FD:2D:D9:E3:14:04 (random) [00:00:00.175,000] <inf> bt_hci_core: HCI: version 5.1 (0x0a) revision 0x0003, manufacturer 0x07d1 [00:00:00.175,000] <inf> bt_hci_core: LMP: version 5.1 (0x0a) subver 0x0000 [00:00:00.176,000] <inf> bt_mesh_main: Primary Element: 0x000f [00:00:00.176,000] <dbg> bt_mesh_main.bt_mesh_provision: net_idx 0x0000 flags 0x00 iv_index 0x0000
5 开发说明¶
5.1 KCONFIG宏说明¶
flash相关,不需要存储flash相关功能
# CONFIG_BT_SETTINGS=y
# CONFIG_FLASH=y
# CONFIG_FLASH_PAGE_LAYOUT=y
# CONFIG_FLASH_MAP=y
# CONFIG_NVS=y
# CONFIG_SETTINGS=y
# CONFIG_BT_MESH_RPL_STORE_TIMEOUT=600
调试LOG宏,基础宏打开,由
CONFIG_BT_PAN_MESH_NODE_TYPE
选择friend/lpn相关打印
CONFIG_BT_DEBUG_LOG=y
CONFIG_BT_MESH_DEBUG=y
由于此demo可以展示配置不同node功能,由
zephyr\samples_panchip\bluetooth\mesh_demo\proj.conj
内的宏进行修改选择,以下四个宏四选一进行编译
CONFIG_BT_PAN_MESH_NODE_TYPE_NORMAL=y
CONFIG_BT_PAN_MESH_NODE_TYPE_FRIEND=y
CONFIG_BT_PAN_MESH_NODE_TYPE_LPN=y
CONFIG_BT_PAN_MESH_NODE_TYPE_HB_PUB=y
5.2 MAIN函数说明¶
main函数包括3部分
flash相关的配置擦除, 包括函数
ps_settings_init
,short_time_multireset_bt_mesh_unprovisioning
bt_enable()
初始化蓝牙bt_ready()
初始化MESH蓝牙回调接口
static void connected(struct bt_conn *conn, uint8_t err) { if (err) { printk("Connection failed (err 0x%02x)\n", err); } else { printk("Connected\n"); } } static void disconnected(struct bt_conn *conn, uint8_t reason) { printk("Disconnected (reason 0x%02x)\n", reason); } BT_CONN_CB_DEFINE(conn_callbacks) = { .connected = connected, .disconnected = disconnected, };
5.3 ble_mesh说明¶
ble/mesh相关操作:
此
mesh_demo
sample没有进行provisioner入网,通过err = bt_mesh_provision(net_key, net_idx, flags, iv_index, addr,dev_key);
进行自入网,通过static void configure(void)
绑定相关config信息,为了减少gatt对扫描的干扰struct bt_mesh_model root_models[]
配置mesh model实现heartbeat的publish绑定和onoff model的灯控演示
6 RAM/Flash资源使用情况¶
Memory region Used Size Region Size %age Used
FLASH: 234920 B 1020 KB 22.49%
SRAM: 31572 B 52 KB 59.29%
IDT_LIST: 0 GB 2 KB 0.00%