Page 1 of 2

Can't get esp_ble_gattc_read_char to trigger ESP_GATTC_READ_CHAR_EVT

Posted: Sat Feb 22, 2020 7:05 am
by Aussie Susan
I think I'm using the latest released version of ESP-IDF (I must admit that it is very hard to find exactly which version I have installed - all I see is references to the GIT repository but which version actually is 'stable' I have no idea: I think there should be a version number is at least one clearly marked file somewhere).

In the beta version, the 'gattc_client' demo used the 'esp_ble_gattc_read_char' function but this seems to have been replaced by setting up a notify system. Therefore I don't know if what I want to do is still possible.

Ideally what I want to do is to scan for all devices; select the ones I am interested in; connect to them and scan for the services and characteristics it has and read the values (a string and 2 16-bit integers); and then repeat.

My basic problem is that I call esp_ble_gattc_read_char but I never see the ESP_GATTC_READ_CHAR_EVT event called.

In the main loop I set up the ble stack and start a scan.
In the ESP_GAP_BLE_SCAN_RESULT_EVT event and specifically the ESP_GAP_SEARCH_INQ_RES_EVT search event, I see if the device is one of the devices I am interested in and, if so, I stop the scan, see if I've seen the device recently, remember the BDA if I have not and then connect to the device.
When I get the ESP_GATTC_DIS_SRVC_CMPL_EVT event, I call esp_ble_gattc_search_service.
For each ESP_GATTC_SEARCH_RES_EVT event I get, I call esp_ble_gattc_get_all_char and, as I know I only have 1 characteristic of interest, I then call esp_ble_gattc_read_char.
I then wait on a semaphore that I trigger in the ESP_GATTC_READ_CHAR_EVT event code but this is never called.

Can someone please tell how this is supposed to work with V4?

Susan

Re: Can't get esp_ble_gattc_read_char to trigger ESP_GATTC_READ_CHAR_EVT

Posted: Sun Feb 23, 2020 5:23 am
by Aussie Susan
Is the problem that I'm trying to read more than 1 characteristic on a connection?
All of the examples seem to show 1 connection, selecting one service and then reading one characteristic value.
How is the state machine supposed to work when I want 3 services and read the characteristic value form each?
Is there any documentation on how the BLE client state machine is designed?
Susan

Re: Can't get esp_ble_gattc_read_char to trigger ESP_GATTC_READ_CHAR_EVT

Posted: Thu Feb 27, 2020 2:17 am
by Aussie Susan
As I've not received any response here, I've also cross-posted to https://github.com/espressif/esp-idf/issues/4839 which also points back to here.
Susan

Re: Can't get esp_ble_gattc_read_char to trigger ESP_GATTC_READ_CHAR_EVT

Posted: Thu Feb 27, 2020 3:22 am
by chegewara
I see few potential options:
1. Is this characteristic readable? Property ESP_GATT_PERM_READ etc
2. Maybe characteristic is readable only when device is paired/bonded? Property ESP_GATT_PERM_READ_ENCRYPTED etc.

Re: Can't get esp_ble_gattc_read_char to trigger ESP_GATTC_READ_CHAR_EVT

Posted: Fri Feb 28, 2020 1:50 am
by Aussie Susan
1) Yes it is readable
2) No because I've read it from some other devices without bonding
(I wrote the server's code as well so I know how it is configured)
Susan

Re: Can't get esp_ble_gattc_read_char to trigger ESP_GATTC_READ_CHAR_EVT

Posted: Fri Feb 28, 2020 9:56 am
by chegewara
What is return code from esp_ble_gattc_read_char:
https://docs.espressif.com/projects/esp ... auth_req_t

Re: Can't get esp_ble_gattc_read_char to trigger ESP_GATTC_READ_CHAR_EVT

Posted: Tue Mar 03, 2020 1:12 am
by Aussie Susan
The code in that part of the app is:

Code: Select all

				status = esp_ble_gattc_read_char( global_gattc_if, current_conn_id,
								characteristic.char_handle, ESP_GATT_AUTH_REQ_NONE);
				ESP_ERROR_CHECK(status);
As nothing triggers the 'ESP_ERROR_CHECK' I take it that it is not returning an error.
Susan

Re: Can't get esp_ble_gattc_read_char to trigger ESP_GATTC_READ_CHAR_EVT

Posted: Tue Mar 03, 2020 10:22 pm
by chegewara
In that case i can only suggest to get BLE sniffer and see with wireshark whats going on.
You can build BLE sniffer with nrf52840 dongle fairly easy and cheap (about $12).

Re: Can't get esp_ble_gattc_read_char to trigger ESP_GATTC_READ_CHAR_EVT

Posted: Thu Mar 05, 2020 2:23 am
by Aussie Susan
I think it is a bit far off until April Fools day - but that can't be a serious answer!

OK - so is what I'm trying to do - call the 'esp_ble_gattc_read_char()' function from the callback routine - the correct way to do this?

Is it possible to read multiple characteristics in this way?

Are there any code examples where the client reads multiple characteristics from the server using V4?

Susan

Re: Can't get esp_ble_gattc_read_char to trigger ESP_GATTC_READ_CHAR_EVT

Posted: Thu Mar 26, 2020 12:27 pm
by ESP_chinmay
Hello Susan,

As far as I have understood your issue, I have provided a patch to reproduce it by running gatt_server and gatt_client examples of esp-idf at master. After applying this patch ESP_GATTC_READ_CHAR_EVT is getting triggered after esp_ble_gattc_read_char is being called.