Skip to content

Commit 925b563

Browse files
committed
Merge branch 'feat/gattc_gatts_coex' into 'master'
feat(nimble): Add new gattc + gatts coex example for nimble Closes IDFGH-11642 See merge request espressif/esp-idf!37139
2 parents 0dbce72 + 3f65227 commit 925b563

File tree

8 files changed

+783
-0
lines changed

8 files changed

+783
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# The following lines of boilerplate have to be in your project's
2+
# CMakeLists in this exact order for cmake to work correctly
3+
cmake_minimum_required(VERSION 3.16)
4+
5+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
6+
# "Trim" the build. Include the minimal set of components, main, and anything it depends on.
7+
idf_build_set_property(MINIMAL_BUILD ON)
8+
project(ble_gattc_gatts_coex)
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-S3 |
2+
| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | -------- |
3+
4+
# BLE GATTC GATTS Coex Example
5+
6+
(See the README.md file in the upper level 'examples' directory for more information about examples.)
7+
8+
This is a simple demo example to showcase a single code which exhibits functionality of both GATT client and GATT server. This example creates a GATT client and performs passive scan to connect to a peripheral device if the device advertises connectability and the device advertises support for the Alert Notification service (0x1811) as primary service UUID. This example also creates a GATT server and advertises, so a remote device can connect to it. If the device is not found within 120 seconds, the example will stop scanning. Upon disconnection in any role, the example ONLY advertises and accepts incoming connections.
9+
10+
It uses ESP32's Bluetooth controller and NimBLE stack based BLE host.
11+
12+
To test this demo, you can run a bleprph example first where gatt client connects to bleprph. Once a disconnect happens, you can use any third party phone and initiate a BLE connection. The same ble_gattc_gatts_coex example will accept incoming connection request. The client is free to perform GATT operations on this connection.
13+
14+
The test demo example is only to show how to use the API. The actual ble coex stability is not the criteria for this demo example.
15+
16+
Note :
17+
18+
* To install the dependency packages needed, please refer to the top level [README file](../../../README.md#running-test-python-script-pytest).
19+
20+
## How to Use Example
21+
22+
Before project configuration and build, be sure to set the correct chip target using:
23+
24+
```bash
25+
idf.py set-target <chip_name>
26+
```
27+
28+
### Hardware Required
29+
30+
* A development board with ESP32 series SoC (e.g., ESP32-DevKitC, ESP-WROVER-KIT, etc.)
31+
* A USB cable for Power supply and programming
32+
33+
See [Development Boards](https://www.espressif.com/en/products/devkits) for more information about it.
34+
35+
### Configure the Project
36+
37+
Open the project configuration menu:
38+
39+
```
40+
### Build and Flash
41+
42+
Run `idf.py -p PORT flash monitor` to build, flash and monitor the project.
43+
44+
(To exit the serial monitor, type ``Ctrl-]``.)
45+
46+
See the [Getting Started Guide](https://idf.espressif.com/) for full steps to configure and use ESP-IDF to build projects.
47+
48+
## Example Output
49+
50+
This is the console output on successful connection:
51+
52+
```
53+
I (439) NimBLE: GAP procedure initiated: advertise;
54+
I (439) NimBLE: disc_mode=2
55+
I (449) NimBLE: adv_channel_map=0 own_addr_type=0 adv_filter_policy=0 adv_itvl_min=0 adv_itvl_max=0
56+
I (459) NimBLE:
57+
58+
I (459) NimBLE: GAP procedure initiated: discovery;
59+
I (459) NimBLE: own_addr_type=0 filter_policy=0 passive=1 limited=0 filter_duplicates=1
60+
I (469) NimBLE: duration=120000ms
61+
I (469) NimBLE:
62+
63+
I (479) main_task: Returned from app_main()
64+
I (489) NimBLE: GAP procedure initiated: connect;
65+
I (489) NimBLE: peer_addr_type=0 peer_addr=
66+
I (489) NimBLE: 84:f7:03:05:a5:f6
67+
I (489) 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
68+
I (509) NimBLE:
69+
70+
I (629) NimBLE: Client connection established; status=0
71+
I (629) NimBLE:
72+
73+
I (629) NimBLE: peer_ota_addr_type=0 peer_ota_addr=
74+
I (629) NimBLE: 84:f7:03:05:a5:f6
75+
I (639) NimBLE: peer_id_addr_type=0 peer_id_addr=
76+
I (639) NimBLE: 84:f7:03:05:a5:f6
77+
I (639) NimBLE: GATT procedure initiated: discover all services
78+
79+
I (829) NimBLE: GATT procedure initiated: discover all characteristics;
80+
I (829) NimBLE: start_handle=1 end_handle=5
81+
82+
I (1029) NimBLE: GATT procedure initiated: discover all characteristics;
83+
I (1029) NimBLE: start_handle=6 end_handle=13
84+
85+
I (1229) NimBLE: GATT procedure initiated: discover all characteristics;
86+
I (1229) NimBLE: start_handle=14 end_handle=26
87+
88+
I (1529) NimBLE: GATT procedure initiated: discover all characteristics;
89+
I (1529) NimBLE: start_handle=27 end_handle=65535
90+
91+
I (1729) NimBLE: GATT procedure initiated: discover all descriptors;
92+
I (1729) NimBLE: chr_val_handle=8 end_handle=9
93+
94+
I (1829) NimBLE: GATT procedure initiated: discover all descriptors;
95+
I (1829) NimBLE: chr_val_handle=18 end_handle=19
96+
97+
I (1929) NimBLE: GATT procedure initiated: discover all descriptors;
98+
I (1929) NimBLE: chr_val_handle=23 end_handle=24
99+
100+
I (2029) NimBLE: GATT procedure initiated: discover all descriptors;
101+
I (2029) NimBLE: chr_val_handle=29 end_handle=65535
102+
103+
I (2329) NimBLE: Service discovery complete; status=0 conn_handle=3
104+
105+
I (2329) NimBLE: GATT procedure initiated: read;
106+
I (2329) NimBLE: att_handle=16
107+
108+
I (2429) NimBLE: Read complete; status=0 conn_handle=3
109+
I (2429) NimBLE: attr_handle=16 value=
110+
I (2429) NimBLE: 0x00
111+
I (2429) NimBLE:
112+
113+
I (2429) NimBLE: GATT procedure initiated: write;
114+
I (2439) NimBLE: att_handle=26 len=2
115+
116+
I (2529) NimBLE: Write complete; status=270 conn_handle=3 attr_handle=26
117+
118+
I (2529) NimBLE: GATT procedure initiated: write;
119+
I (2529) NimBLE: att_handle=24 len=2
120+
121+
I (2629) NimBLE: Subscribe complete; status=0 conn_handle=3 attr_handle=24
122+
123+
I (2629) NimBLE: GAP procedure initiated: terminate connection; conn_handle=3 hci_reason=19
124+
125+
I (2679) NimBLE: Disconnect
126+
127+
I (2679) NimBLE: GAP procedure initiated: stop advertising.
128+
129+
I (2679) NimBLE: GAP procedure initiated: advertise;
130+
I (2679) NimBLE: disc_mode=2
131+
I (2689) NimBLE: adv_channel_map=0 own_addr_type=0 adv_filter_policy=0 adv_itvl_min=0 adv_itvl_max=0
132+
I (2699) NimBLE:
133+
134+
I (5329) NimBLE: Server connection established; status=0
135+
I (5329) NimBLE:
136+
137+
I (5329) NimBLE: peer_ota_addr_type=1 peer_ota_addr=
138+
I (5329) NimBLE: 4c:4a:07:8d:4a:15
139+
I (5329) NimBLE: peer_id_addr_type=1 peer_id_addr=
140+
I (5339) NimBLE: 4c:4a:07:8d:4a:15
141+
I (17429) NimBLE: subscribe event; conn_handle=1 attr_handle=29 reason=1 prevn=0 curn=1 previ=0 curi=0
142+
```
143+
144+
145+
## Troubleshooting
146+
147+
For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
set(srcs "main.c")
2+
3+
idf_component_register(SRCS "${srcs}"
4+
INCLUDE_DIRS ".")
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#ifndef H_BLECOEX_
21+
#define H_BLECOEX_
22+
23+
#ifdef __cplusplus
24+
extern "C" {
25+
#endif
26+
27+
#include "esp_central.h"
28+
29+
#define SERVICE_UUID 0x181A
30+
#define CHAR_UUID 0x2A6E
31+
32+
/** GATT server. */
33+
#define BLECOEX_SVC_ALERT_UUID 0x1811
34+
#define BLECOEX_CHR_SUP_NEW_ALERT_CAT_UUID 0x2A47
35+
#define BLECOEX_CHR_UNR_ALERT_STAT_UUID 0x2A45
36+
#define BLECOEX_CHR_ALERT_NOT_CTRL_PT 0x2A44
37+
38+
39+
#ifdef __cplusplus
40+
}
41+
#endif
42+
43+
#endif
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
dependencies:
2+
nimble_central_utils:
3+
path: ${IDF_PATH}/examples/bluetooth/nimble/common/nimble_central_utils
4+
nimble_peripheral_utils:
5+
path: ${IDF_PATH}/examples/bluetooth/nimble/common/nimble_peripheral_utils

0 commit comments

Comments
 (0)