-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/services_health_therm_v5.1' into 'release/v5.1'
NimBLE: Added health thermometer profile (v5.1) See merge request espressif/esp-idf!24830
- Loading branch information
Showing
17 changed files
with
920 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# The following lines of boilerplate have to be in your project's | ||
# CMakeLists in this exact order for cmake to work correctly | ||
cmake_minimum_required(VERSION 3.16) | ||
|
||
set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/bluetooth/nimble/common/nimble_central_utils) | ||
|
||
include($ENV{IDF_PATH}/tools/cmake/project.cmake) | ||
project(htp_cent) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-S3 | | ||
| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | | ||
|
||
# BLE HTP Cent Example | ||
|
||
(See the README.md file in the upper level 'examples' directory for more information about examples.) | ||
|
||
This example creates GATT client and performs passive scan, it then connects to peripheral device if the device advertises connectability and the device advertises support for the Health Thermometer service (0x1809) as primary service UUID. | ||
|
||
After connection it enables bonding and link encryprion if the `Enable Link Encryption` flag is set in the example config. | ||
|
||
It performs four GATT operations against the specified peer: | ||
|
||
* Reads the HTP temperature type characteristic. | ||
|
||
* After the read operation is completed, writes the HTP measurement interval characteristic. | ||
|
||
* After the write operation is completed, subscribes to indications for the HTP temperature measurement characteristic. | ||
|
||
* After the subscribe operation is completed, it subscribes to notifications for the HTP intermediate temperature characteristic. | ||
|
||
If the peer does not support a required service, characteristic, or descriptor, then the peer lied when it claimed support for the Health Thermometer service! When this happens, or if a GATT procedure fails, this function immediately terminates the connection. | ||
|
||
It uses ESP32's Bluetooth controller and NimBLE stack based BLE host. | ||
|
||
This example aims at understanding BLE service discovery, connection, encryption and characteristic operations. | ||
|
||
To test this demo, use any BLE GATT server app that advertises support for the Health Thermometer service (0x1809) and includes it in the GATT database. | ||
|
||
## How to Use Example | ||
|
||
Before project configuration and build, be sure to set the correct chip target using: | ||
|
||
```bash | ||
idf.py set-target <chip_name> | ||
``` | ||
|
||
### Hardware Required | ||
|
||
* A development board with ESP32/ESP32-C2/ESP32-C3/ESP32-S3 SoC (e.g., ESP32-DevKitC, ESP-WROVER-KIT, etc.) | ||
* A USB cable for Power supply and programming | ||
|
||
See [Development Boards](https://www.espressif.com/en/products/devkits) for more information about it. | ||
|
||
### Configure the Project | ||
|
||
Open the project configuration menu: | ||
|
||
```bash | ||
idf.py menuconfig | ||
``` | ||
|
||
In the `Example Configuration` menu: | ||
|
||
* Change the `Peer Address` option if needed. | ||
|
||
### Build and Flash | ||
|
||
Run `idf.py -p PORT flash monitor` to build, flash and monitor the project. | ||
|
||
(To exit the serial monitor, type ``Ctrl-]``.) | ||
|
||
See the [Getting Started Guide](https://idf.espressif.com/) for full steps to configure and use ESP-IDF to build projects. | ||
|
||
## Example Output | ||
|
||
This is the console output on successful connection: | ||
|
||
``` | ||
I (356) BLE_INIT: BT controller compile version [921f253] | ||
I (356) phy_init: phy_version 950,f732b06,Feb 15 2023,18:57:12 | ||
I (396) BLE_INIT: Bluetooth MAC: 84:f7:03:05:a5:f6 | ||
I (396) NimBLE_HTP_CENT: BLE Host Task Started | ||
I (406) NimBLE: GAP procedure initiated: stop advertising. | ||
I (406) NimBLE: GAP procedure initiated: discovery; | ||
I (406) NimBLE: own_addr_type=0 filter_policy=0 passive=1 limited=0 filter_duplicates=1 | ||
I (416) NimBLE: duration=forever | ||
I (426) NimBLE: | ||
I (426) main_task: Returned from app_main() | ||
I (616) NimBLE: GAP procedure initiated: connect; | ||
I (616) NimBLE: peer_addr_type=0 peer_addr= | ||
I (616) NimBLE: 70:04:1d:13:66:fe | ||
I (616) NimBLE: scan_itvl=16 scan_window=16 itvl_min=24 itvl_max=40 latency=0 supervision_timeout=256 min_ce_len=0 max_ce_len=0 own_addr_type=0 | ||
I (636) NimBLE: | ||
I (676) NimBLE: Connection established | ||
I (676) NimBLE: | ||
I (676) NimBLE: GATT procedure initiated: discover all services | ||
I (856) NimBLE: GATT procedure initiated: discover all characteristics; | ||
I (856) NimBLE: start_handle=1 end_handle=5 | ||
I (1056) NimBLE: GATT procedure initiated: discover all characteristics; | ||
I (1056) NimBLE: start_handle=6 end_handle=9 | ||
I (1256) NimBLE: GATT procedure initiated: discover all characteristics; | ||
I (1256) NimBLE: start_handle=10 end_handle=22 | ||
I (1556) NimBLE: GATT procedure initiated: discover all characteristics; | ||
I (1556) NimBLE: start_handle=23 end_handle=65535 | ||
I (1756) NimBLE: GATT procedure initiated: discover all descriptors; | ||
I (1756) NimBLE: chr_val_handle=8 end_handle=9 | ||
I (1856) NimBLE: GATT procedure initiated: discover all descriptors; | ||
I (1856) NimBLE: chr_val_handle=12 end_handle=13 | ||
I (1956) NimBLE: GATT procedure initiated: discover all descriptors; | ||
I (1956) NimBLE: chr_val_handle=17 end_handle=18 | ||
I (2056) NimBLE: GATT procedure initiated: discover all descriptors; | ||
I (2056) NimBLE: chr_val_handle=20 end_handle=22 | ||
I (2156) NimBLE: GATT procedure initiated: discover all descriptors; | ||
I (2156) NimBLE: chr_val_handle=29 end_handle=65535 | ||
I (2256) NimBLE: Service discovery complete; status=0 conn_handle=1 | ||
I (2256) NimBLE: GATT procedure initiated: read; | ||
I (2256) NimBLE: att_handle=15 | ||
I (283056) NimBLE: Read temperature type char completed; status=0 conn_handle=1 | ||
I (283056) NimBLE: attr_handle=167 value= | ||
I (283056) NimBLE: 0x02 | ||
I (283066) NimBLE: | ||
I (283066) NimBLE: GATT procedure initiated: write; | ||
I (283066) NimBLE: att_handle=172 len=2 | ||
I (283156) NimBLE: Write to measurement interval char completed; status=0 conn_handle=1 attr_handle=172 | ||
I (283156) NimBLE: GATT procedure initiated: write; | ||
I (283166) NimBLE: att_handle=163 len=2 | ||
I (283256) NimBLE: Subscribe to temperature measurement char completed; status=0 conn_handle=1 attr_handle=163 | ||
I (283256) NimBLE: GATT procedure initiated: write; | ||
I (283266) NimBLE: att_handle=170 len=2 | ||
I (283356) NimBLE: Subscribe to intermediate temperature char completed; status=0 conn_handle=1 attr_handle=170 | ||
``` | ||
|
||
## Troubleshooting | ||
|
||
For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon. |
4 changes: 4 additions & 0 deletions
4
examples/bluetooth/nimble/ble_htp/htp_cent/main/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
set(srcs "main.c") | ||
|
||
idf_component_register(SRCS "${srcs}" | ||
INCLUDE_DIRS ".") |
24 changes: 24 additions & 0 deletions
24
examples/bluetooth/nimble/ble_htp/htp_cent/main/Kconfig.projbuild
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
menu "Example Configuration" | ||
|
||
config EXAMPLE_PEER_ADDR | ||
string "Peer Address" | ||
default "ADDR_ANY" | ||
help | ||
Enter the peer address in aa:bb:cc:dd:ee:ff form to connect to a specific peripheral | ||
|
||
config EXAMPLE_ENCRYPTION | ||
bool | ||
prompt "Enable Link Encryption" | ||
default y | ||
help | ||
This enables bonding and encryption after connection has been established. | ||
|
||
config EXAMPLE_EXTENDED_ADV | ||
bool | ||
depends on SOC_BLE_50_SUPPORTED | ||
default y if SOC_ESP_NIMBLE_CONTROLLER | ||
select BT_NIMBLE_EXT_ADV | ||
prompt "Enable Extended Adv" | ||
help | ||
Use this option to enable extended advertising in the example | ||
endmenu |
44 changes: 44 additions & 0 deletions
44
examples/bluetooth/nimble/ble_htp/htp_cent/main/ble_htp_cent.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2017-2023 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#ifndef H_BLE_HTP_CENT_ | ||
#define H_BLE_HTP_CENT_ | ||
|
||
#include "modlog/modlog.h" | ||
#include "esp_central.h" | ||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
struct ble_hs_adv_fields; | ||
struct ble_gap_conn_desc; | ||
struct ble_hs_cfg; | ||
union ble_store_value; | ||
union ble_store_key; | ||
|
||
/* 16 Bit Health Thermometer Service UUID */ | ||
#define BLE_SVC_HTP_UUID16 0x1809 | ||
|
||
/* 16 Bit Health Thermometer Service Characteristic UUIDs */ | ||
#define BLE_SVC_HTP_CHR_UUID16_TEMP_MEASUREMENT 0x2A1C | ||
#define BLE_SVC_HTP_CHR_UUID16_TEMP_TYPE 0x2A1D | ||
#define BLE_SVC_HTP_CHR_UUID16_INTERMEDIATE_TEMP 0x2A1E | ||
#define BLE_SVC_HTP_CHR_UUID16_MEASUREMENT_ITVL 0x2A21 | ||
|
||
/* 16 Bit Device Information Service Characteristic UUIDs */ | ||
#define GATT_DIS_DEVICE_INFO_UUID 0x180A | ||
#define GATT_DIS_CHR_UUID16_SYS_ID 0x2A23 | ||
#define GATT_DIS_CHR_UUID16_MODEL_NO 0x2A24 | ||
#define GATT_DIS_CHR_UUID16_MFC_NAME 0x2A29 | ||
|
||
/* 16 BIT CCCD UUID */ | ||
#define BLE_SVC_HTP_DSC_CLT_CFG_UUID16 0x2902 | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif |
12 changes: 12 additions & 0 deletions
12
examples/bluetooth/nimble/ble_htp/htp_cent/sdkconfig.defaults
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Override some defaults so BT stack is enabled | ||
# in this example | ||
|
||
# | ||
# BT config | ||
# | ||
CONFIG_BT_ENABLED=y | ||
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y | ||
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n | ||
CONFIG_BTDM_CTRL_MODE_BTDM=n | ||
CONFIG_BT_BLUEDROID_ENABLED=n | ||
CONFIG_BT_NIMBLE_ENABLED=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# The following lines of boilerplate have to be in your project's | ||
# CMakeLists in this exact order for cmake to work correctly | ||
cmake_minimum_required(VERSION 3.16) | ||
|
||
include($ENV{IDF_PATH}/tools/cmake/project.cmake) | ||
project(htp_prph) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-S3 | | ||
| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | | ||
|
||
# BLE Heart Rate Measurement Example | ||
|
||
(See the README.md file in the upper level 'examples' directory for more information about examples.) | ||
|
||
This example creates GATT server demonstrating standard Health Thermometer profile. It simulates temperature measurement and notifies to client when the notifications are enabled. | ||
|
||
It advertises support for the Health Thermometer service (0x1809) as primary service UUID. | ||
|
||
When internmediate temperature characteristic is subscribed, the timer resets and it sends notifications to client every 1 sec. | ||
|
||
It uses ESP32's Bluetooth controller and NimBLE stack based BLE host | ||
|
||
This example aims at understanding notification subscriptions and sending notifications. | ||
|
||
## How to Use Example | ||
|
||
Before project configuration and build, be sure to set the correct chip target using: | ||
|
||
```bash | ||
idf.py set-target <chip_name> | ||
``` | ||
|
||
### Hardware Required | ||
|
||
* A development board with ESP32/ESP32-C3 SoC (e.g., ESP32-DevKitC, ESP-WROVER-KIT, etc.) | ||
* A USB cable for Power supply and programming | ||
|
||
See [Development Boards](https://www.espressif.com/en/products/devkits) for more information about it. | ||
|
||
### Build and Flash | ||
|
||
Run `idf.py -p PORT flash monitor` to build, flash and monitor the project. | ||
|
||
(To exit the serial monitor, type ``Ctrl-]``.) | ||
|
||
See the [Getting Started Guide](https://idf.espressif.com/) for full steps to configure and use ESP-IDF to build projects. | ||
|
||
## Example Output | ||
|
||
This console output can be observed when blehr is connected to client and client enables notifications: | ||
|
||
``` | ||
I (356) BLE_INIT: BT controller compile version [921f253] | ||
I (356) phy_init: phy_version 950,f732b06,Feb 15 2023,18:57:12 | ||
I (396) BLE_INIT: Bluetooth MAC: 70:04:1d:13:66:fe | ||
I (396) NimBLE_BLE_Health_Therm: BLE Host Task Started | ||
I (396) NimBLE: GAP procedure initiated: stop advertising. | ||
I (406) NimBLE: Failed to restore IRKs from store; status=8 | ||
I (406) NimBLE: Device Address: | ||
I (416) NimBLE: 70:04:1d:13:66:fe | ||
I (416) NimBLE: | ||
I (416) NimBLE: GAP procedure initiated: advertise; | ||
I (426) NimBLE: disc_mode=2 | ||
I (426) NimBLE: adv_channel_map=0 own_addr_type=0 adv_filter_policy=0 adv_itvl_min=0 adv_itvl_max=0 | ||
I (436) NimBLE: | ||
I (446) main_task: Returned from app_main() | ||
I (6116) NimBLE: connection established; status=0 | ||
I (7946) NimBLE: subscribe event; cur_notify=0 | ||
value handle; val_handle=12 | ||
I (7956) BLE_GAP_SUBSCRIBE_EVENT: conn_handle from subscribe=1 | ||
I (8046) NimBLE: subscribe event; cur_notify=1 | ||
value handle; val_handle=17 | ||
I (8056) BLE_GAP_SUBSCRIBE_EVENT: conn_handle from subscribe=1 | ||
I (9056) NimBLE: GATT procedure initiated: notify; | ||
I (9056) NimBLE: att_handle=17 | ||
``` | ||
|
||
## Troubleshooting | ||
|
||
For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon. |
2 changes: 2 additions & 0 deletions
2
examples/bluetooth/nimble/ble_htp/htp_prph/main/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
idf_component_register(SRCS "main.c" "gatt_svr.c" | ||
INCLUDE_DIRS ".") |
11 changes: 11 additions & 0 deletions
11
examples/bluetooth/nimble/ble_htp/htp_prph/main/Kconfig.projbuild
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
menu "Example Configuration" | ||
|
||
config EXAMPLE_EXTENDED_ADV | ||
bool | ||
depends on SOC_BLE_50_SUPPORTED | ||
default y if SOC_ESP_NIMBLE_CONTROLLER | ||
select BT_NIMBLE_EXT_ADV | ||
prompt "Enable Extended Adv" | ||
help | ||
Use this option to enable extended advertising in the example | ||
endmenu |
Oops, something went wrong.