Bluetooth: Central / Heart-rate Monitor¶
1 功能概述¶
此项目演示蓝牙主机功能,不同的是这个应用程序专门查找心率监视器,并在连接后报告心率读数。
2 环境要求¶
board: 支持 BLE 的蓝牙设备
uart(option): 用来显示串口log
测试软件: nRF Connect
3 编译和烧录¶
项目位置:zephyr\samples_panchip\bluetooth\central_hr
统一的配置、编译、下载工具正在开发中,当前可以使用脚本进行编译和下载。
脚本位置:quick_build_samples\bluetooth\central_hr.bat
。
打开脚本后默认会编译项目,编译完成时,可输入字符进行后续下载等操作:
Input the keyword to continue:
'b' build 编译项目
'r' make clean and rebuild 重新编译项目
'f' flash download 下载
'e' erase chip 擦除芯片
'o' open project by VS Code 打开 `VS Code`,可查看源码,执行编译下载等
others exit 退出
wait input:
4 演示说明¶
准备2个设备,分别烧录peripheral_hr(见peripheral_hr例程),烧录centrl_hr例程
开启central设备,此时central设备可以看到扫描数据
Scanning successfully started [DEVICE]: 1D:0C:35:49:40:DC (random), AD evt type 3, AD data len 31, RSSI -43 [DEVICE]: 1D:0C:35:49:40:DC (random), AD evt type 3, AD data len 31, RSSI -42 [DEVICE]: 59:70:28:64:72:07 (random), AD evt type 3, AD data len 31, RSSI -71 [DEVICE]: 59:70:28:64:72:07 (random), AD evt type 3, AD data len 31, RSSI -72 [DEVICE]: DF:BC:88:D2:0C:B9 (random), AD evt type 0, AD data len 11, RSSI -42 [AD]: 1 data_len 1 [AD]: 3 data_len 6
打开peripheral_hr,显示被central_hr设备扫描,串口数据打印connected
Connected <inf> hrs: HRS notifications enabled
在central_hr串口上会显示connect,收到上报的心率信息
Connected: DF:BC:88:D2:0C:B9 (random) [ATTRIBUTE] handle 25 [ATTRIBUTE] handle 28 [SUBSCRIBED] [NOTIFICATION] data 0x20009f6c length 2 [NOTIFICATION] data 0x20009f6c length 2 [NOTIFICATION] data 0x20009f6c length 2 [NOTIFICATION] data 0x20009f6c length 2