当前文档版本为 v0.4.0,您可以访问当前页面的 开发中 版本以获取最近可能的更新。

Bluetooth: Peripheral / Health Thermometer sensor

1 功能概述

此项目演示了蓝牙从机的功能,该工程包含了 HT (Health Thermometer) 服务,可以采集温度并上报给主机。

在不支持温度采集的设备上,这些温度数据是虚拟的。

2 环境要求

  • board: 支持 BLE 的蓝牙设备

  • uart(option): 用来显示串口log

  • 测试软件: nRF Connect

3 编译和烧录

项目位置:zephyr\samples_panchip\bluetooth\peripheral_ht

目前可使用ZAL工具或quick build脚本进行编译和下载。

脚本位置:quick_build_samples\bluetooth\peripheral_ht.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 演示说明

  1. 烧录完成后,设备自动启动蓝牙广播,可以在手机或抓包工具上获取如下信息:

    • Service UUID: 0x1809, 0x180A, 0x180F

    • Device Name: Zephyr Health Thermometer

  2. 当手机或其它主设备与其建立连接后,串口log 会显示连接信息,如下:

    Connected
    
  3. 此时,如果使能了Temperature Measurement,主机将收到温度数据,如下:

    image

    Peripheral HT 手机端 nRF Connect Service界面

    image

    Peripheral HT 手机端 nRF Connect Log界面

    串口log也会显示当前温度和数据传输的信息:

    temperature is 20C
    Indication success
    Indication complete
    temperature is 21C
    Indication success
    Indication complete
    temperature is 22C
    Indication success
    Indication complete
    temperature is 23C
    Indication success
    Indication complete
    temperature is 24C
    Indication success
    Indication complete
    temperature is 25C
    Indication success
    Indication complete
    temperature is 26C
    Indication success
    Indication complete
    temperature is 27C
    Indication success
    Indication complete