1 # BLE Heart Rate Measurement example
3 (See the README.md file in the upper level 'examples' directory for more information about examples.)
5 This example creates GATT server demonstrating standard Heart Rate measurement service. It simulates Hear rate measurement and notifies to client when the notifications are enabled.
7 It uses ESP32's Bluetooth controller and NimBLE stack based BLE host
9 This example aims at understanding notification subscriptions and sending notifications.
11 To test this demo, any BLE scanner app can be used.
13 A Python based utility `blehr_test.py` is also provided (which will run as a BLE GATT Client) and can be used to test this example.
17 * Make sure to run `python -m pip install --user -r $IDF_PATH/requirements.txt -r $IDF_PATH/tools/ble/requirements.txt` to install the dependency packages needed.
18 * Currently this Python utility is only supported on Linux (BLE communication is via BLuez + DBus).
23 ### Configure the project
29 * Set serial port under Serial Flasher Options.
33 Build the project and flash it to the board, then run monitor tool to view serial output:
36 make -j4 flash monitor
39 (To exit the serial monitor, type ``Ctrl-]``.)
41 See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
45 This console output can be observed when blehr is connected to client and client enables notifications:
48 I (91) BTDM_INIT: BT controller compile version [fe7ced0]
49 I (91) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
50 I (181) phy: phy_version: 4100, 6fa5e27, Jan 25 2019, 17:02:06, 0, 0
51 I (421) NimBLE_BLE_HeartRate: BLE Host Task Started
52 GAP procedure initiated: stop advertising.
53 Device Address: xx:xx:xx:xx:xx:xx
54 GAP procedure initiated: advertise; disc_mode=2 adv_channel_map=0 own_addr_type=0 adv_filter_policy=0 adv_itvl_min=0 adv_itvl_max=0
55 connection established; status=0
56 subscribe event; cur_notify=1
57 value handle; val_handle=3
58 I (21611) BLE_GAP_SUBSCRIBE_EVENT: conn_handle from subscribe=0
59 GATT procedure initiated: notify; att_handle=3
60 GATT procedure initiated: notify; att_handle=3
61 GATT procedure initiated: notify; att_handle=3
62 GATT procedure initiated: notify; att_handle=3
63 GATT procedure initiated: notify; att_handle=3
64 GATT procedure initiated: notify; att_handle=3
65 GATT procedure initiated: notify; att_handle=3
69 ## Running Python Utility
75 ## Python Utility Output
77 This is this output seen on the python side on successful connection:
80 discovering adapter...
81 bluetooth adapter discovered
82 powering on adapter...
83 bluetooth adapter powered on
87 Connecting to device...
93 [dbus.String(u'00001801-0000-1000-8000-00805f9b34fb', variant_level=1), dbus.String(u'0000180d-0000-1000-8000-00805f9b34fb', variant_level=1), dbus.String(u'0000180a-0000-1000-8000-00805f9b34fb', variant_level=1)]
95 Subscribe to notifications: On
96 dbus.Array([dbus.Byte(6), dbus.Byte(90)], signature=dbus.Signature('y'), variant_level=1)
97 dbus.Array([dbus.Byte(6), dbus.Byte(91)], signature=dbus.Signature('y'), variant_level=1)
98 dbus.Array([dbus.Byte(6), dbus.Byte(92)], signature=dbus.Signature('y'), variant_level=1)
99 dbus.Array([dbus.Byte(6), dbus.Byte(93)], signature=dbus.Signature('y'), variant_level=1)
100 dbus.Array([dbus.Byte(6), dbus.Byte(94)], signature=dbus.Signature('y'), variant_level=1)
101 dbus.Array([dbus.Byte(6), dbus.Byte(95)], signature=dbus.Signature('y'), variant_level=1)
102 dbus.Array([dbus.Byte(6), dbus.Byte(96)], signature=dbus.Signature('y'), variant_level=1)
103 dbus.Array([dbus.Byte(6), dbus.Byte(97)], signature=dbus.Signature('y'), variant_level=1)
104 dbus.Array([dbus.Byte(6), dbus.Byte(98)], signature=dbus.Signature('y'), variant_level=1)
105 dbus.Array([dbus.Byte(6), dbus.Byte(99)], signature=dbus.Signature('y'), variant_level=1)
107 Subscribe to notifications: Off
108 Success: blehr example test passed
111 disconnecting device...
113 powering off adapter...
114 bluetooth adapter powered off