Closed vdm97 closed 1 year ago
Logs were too long...
Hi @vdm97,
Please remove the reproduce steps 11, after the first connection has been disconnected, don't call the esp_ble_gattc_app_unregister
API.
Hi, thank you for your time. Where should i put the call to esp_ble_gattc_app_unregister
then? After the clients disconnects i do not need the registered GATT-client anymore.
Also, this does not fix my error because that part of the code never gets called when i try to connect to a second peripheral while there is already a connection present with a first peripheral. Maybe i have missed something?
In fact, you don't need to call esp_ble_gattc_app_unregister
, If you no longer need to use it, you can close the entire stack.
Please try using esp_ble_gattc_close
to terminated the connection.
But I not sure if this will solve your problem, if not, I'll give you an example.
When i want to connect to a peripheral the first thing i do is to register the GATT-client (esp_ble_gattc_app_register
). After a while i want to close the connection so i use esp_ble_gattc_close
and then esp_ble_gap_disconnect
. Because i do not need the GATT-client anymore my thinking was to free the internal resources by calling esp_ble_gattc_app_unregister
. Maybe my reasoning is wrong and esp_ble_gattc_close
or esp_ble_gap_disconnect
already free the internal resources so a call to esp_ble_gattc_app_unregister
is not needed?
I hope this makes clear that i cannot just deinitialize the whole BLE-stack because it is just 1 client that i do not need and i want to connect to other peripherals (with their own call to esp_ble_gattc_app_register
etc.).
And to make things more clear. My problem does not occur when i disconnect from a peripheral, but when i want to connect to a second peripheral while still connected to a first peripheral. In order to achieve that i run the procedure for connecting to a peripheral (steps 2 to 9) for the first peripheral which succeeds and then i run the steps 2 to 9 again (with different data) in order to connect to the second peripheral. This does not succeed because the event ESP_GATTC_SEARCH_RES_EVT
never gets raised for the second peripheral.
As it turned out, this error was a side effect of corrupted memory... Everything works great after fixing that error.
Answers checklist.
IDF version.
v4.4.3
Operating System used.
Windows
How did you build your project?
VS Code IDE
If you are using Windows, please specify command line type.
PowerShell
Development Kit.
ESP32-WROOM-32
Power Supply used.
USB
What is the expected behavior?
While connected to a first peripheral and connecting to a second peripheral via BLE and using
esp_ble_gattc_search_service
to find a service theESP_GATTC_SEARCH_RES_EVT
event should be raised.What is the actual behavior?
The event
ESP_GATTC_SEARCH_RES_EVT
never gets raised.Steps to reproduce.
This is my procedure for connecting to a peripheral and subscribing to a heartrate monitor.
esp_ble_gatt_set_local_mtu(ESP_GATT_MAX_MTU_SIZE)
to allow the maximum MTU.esp_ble_gattc_app_register
.ESP_GATTC_REG_EVT
useesp_ble_gattc_open
to open the connection. BDA is already known so no scanning necessary.ESP_GATTC_CONNECT_EVT
is not used.ESP_GATTC_OPEN_EVT
useesp_ble_gattc_send_mtu_req
to request higher MTU. Gets confirmed in eventESP_GATTC_CFG_MTU_EVT
with a value of 498.ESP_GATTC_DIS_SRVC_CMPL_EVT
useesp_ble_gattc_search_service
to search for known service UUID. The start and end handles are saved in the eventESP_GATTC_SEARCH_RES_EVT
.ESP_GATTC_SEARCH_CMPL_EVT
useesp_ble_gattc_get_attr_count
, thenesp_ble_gattc_get_char_by_uuid
, thenesp_ble_gattc_register_for_notify
to register for notify on a known characteristic.ESP_GATTC_REG_FOR_NOTIFY_EVT
useesp_ble_gattc_get_attr_count
, thenesp_ble_gattc_get_descr_by_char_handle
, thenesp_ble_gattc_write_char_descr
to activate the notify descriptor.ESP_GATTC_WRITE_DESCR_EVT
the connection procedure is finished and the eventESP_GATTC_NOTIFY_EVT
delivers the data from the peripheral.ESP_GATTC_CLOSE_EVT
useesp_ble_gap_disconnect
to close the physical connection.ESP_GATTC_DISCONNECT_EVT
useesp_ble_gattc_app_unregister
to remove the GATT-client.Debug Logs.
No response
More Information.
I run the ESP32 in WiFi and Bluetooth coexistence mode because i need both functionalities and Bluedroid is used as the BLE stack. If i run the connection procedure for the first peripheral, then disconnect from the first peripheral after which i run the connection procedure for the second peripheral, the connection gets established successfully. When i disconnect from the second peripheral i can run the connection procedure for the first peripheral successfully and so on.. But running the connection procedure while connected to the first peripheral fails because the event
ESP_GATTC_SEARCH_RES_EVT
never gets raised. Swapping the first and second peripheral does not help. The peripherals are two nordic nrf52840 DK with a simple heartrate peripheral sample (source) with a removed battery service so i do not suspect the error there. When the sending of the heartrate values is deactivated the eventESP_GATTC_SEARCH_RES_EVT
just never gets raised. If the sending of the heartrate values is present an error is present in the ESP32 logs after which both connections get terminated. I raised allBT DEBUG LOG LEVEL
s toVERBOSE
which does not help me but maybe does provide some information to the maintainers. Because of these changes i had to raise theCONFIG_BTU_TASK_STACK_SIZE
from4096
to8192
and also raised theCONFIG_BTC_TASK_STACK_SIZE
from3072
to6144
just to be sure enough stack is provided. If needed i can translate the german parts in the logs to english...