README.md
1| Supported Targets | ESP32 |
2| ----------------- | ----- |
3
4# BLE Heart Rate Measurement example
5
6(See the README.md file in the upper level 'examples' directory for more information about examples.)
7
8This example creates GATT server demonstrating standard Heart Rate measurement service. It simulates Hear rate measurement and notifies to client when the notifications are enabled.
9
10It uses ESP32's Bluetooth controller and NimBLE stack based BLE host
11
12This example aims at understanding notification subscriptions and sending notifications.
13
14To test this demo, any BLE scanner app can be used.
15
16A 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
18Note :
19
20* 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.
21* Currently this Python utility is only supported on Linux (BLE communication is via BLuez + DBus).
22
23
24## How to use example
25
26### Configure the project
27
28```
29idf.py menuconfig
30```
31
32### Build and Flash
33
34Build the project and flash it to the board, then run monitor tool to view serial output:
35
36```
37idf.py -p PORT flash monitor
38```
39
40(To exit the serial monitor, type ``Ctrl-]``.)
41
42See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
43
44## Example Output
45
46This console output can be observed when blehr is connected to client and client enables notifications:
47
48```
49I (91) BTDM_INIT: BT controller compile version [fe7ced0]
50I (91) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
51I (181) phy: phy_version: 4100, 6fa5e27, Jan 25 2019, 17:02:06, 0, 0
52I (421) NimBLE_BLE_HeartRate: BLE Host Task Started
53GAP procedure initiated: stop advertising.
54Device Address: xx:xx:xx:xx:xx:xx
55GAP 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
56connection established; status=0
57subscribe event; cur_notify=1
58 value handle; val_handle=3
59I (21611) BLE_GAP_SUBSCRIBE_EVENT: conn_handle from subscribe=0
60GATT procedure initiated: notify; att_handle=3
61GATT procedure initiated: notify; att_handle=3
62GATT procedure initiated: notify; att_handle=3
63GATT procedure initiated: notify; att_handle=3
64GATT procedure initiated: notify; att_handle=3
65GATT procedure initiated: notify; att_handle=3
66GATT procedure initiated: notify; att_handle=3
67
68```
69
70## Running Python Utility
71
72```
73python blehr_test.py
74```
75
76## Python Utility Output
77
78This is this output seen on the python side on successful connection:
79
80```
81discovering adapter...
82bluetooth adapter discovered
83powering on adapter...
84bluetooth adapter powered on
85
86Started Discovery
87
88Connecting to device...
89
90Connected to device
91
92Services
93
94[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
96Subscribe to notifications: On
97dbus.Array([dbus.Byte(6), dbus.Byte(90)], signature=dbus.Signature('y'), variant_level=1)
98dbus.Array([dbus.Byte(6), dbus.Byte(91)], signature=dbus.Signature('y'), variant_level=1)
99dbus.Array([dbus.Byte(6), dbus.Byte(92)], signature=dbus.Signature('y'), variant_level=1)
100dbus.Array([dbus.Byte(6), dbus.Byte(93)], signature=dbus.Signature('y'), variant_level=1)
101dbus.Array([dbus.Byte(6), dbus.Byte(94)], signature=dbus.Signature('y'), variant_level=1)
102dbus.Array([dbus.Byte(6), dbus.Byte(95)], signature=dbus.Signature('y'), variant_level=1)
103dbus.Array([dbus.Byte(6), dbus.Byte(96)], signature=dbus.Signature('y'), variant_level=1)
104dbus.Array([dbus.Byte(6), dbus.Byte(97)], signature=dbus.Signature('y'), variant_level=1)
105dbus.Array([dbus.Byte(6), dbus.Byte(98)], signature=dbus.Signature('y'), variant_level=1)
106dbus.Array([dbus.Byte(6), dbus.Byte(99)], signature=dbus.Signature('y'), variant_level=1)
107
108Subscribe to notifications: Off
109Success: blehr example test passed
110
111exiting from test...
112disconnecting device...
113device disconnected
114powering off adapter...
115bluetooth adapter powered off
116```
117