Can't get esp_ble_gattc_read_char to trigger ESP_GATTC_READ_CHAR_EVT

Aussie Susan
Posts: 45
Joined: Thu Aug 22, 2019 3:48 am

Can't get esp_ble_gattc_read_char to trigger ESP_GATTC_READ_CHAR_EVT

Postby Aussie Susan » Sat Feb 22, 2020 7:05 am

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

Aussie Susan
Posts: 45
Joined: Thu Aug 22, 2019 3:48 am

Re: Can't get esp_ble_gattc_read_char to trigger ESP_GATTC_READ_CHAR_EVT

Postby Aussie Susan » Sun Feb 23, 2020 5:23 am

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

Aussie Susan
Posts: 45
Joined: Thu Aug 22, 2019 3:48 am

Re: Can't get esp_ble_gattc_read_char to trigger ESP_GATTC_READ_CHAR_EVT

Postby Aussie Susan » Thu Feb 27, 2020 2:17 am

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

chegewara
Posts: 2378
Joined: Wed Jun 14, 2017 9:00 pm

Re: Can't get esp_ble_gattc_read_char to trigger ESP_GATTC_READ_CHAR_EVT

Postby chegewara » Thu Feb 27, 2020 3:22 am

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.

Aussie Susan
Posts: 45
Joined: Thu Aug 22, 2019 3:48 am

Re: Can't get esp_ble_gattc_read_char to trigger ESP_GATTC_READ_CHAR_EVT

Postby Aussie Susan » Fri Feb 28, 2020 1:50 am

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

chegewara
Posts: 2378
Joined: Wed Jun 14, 2017 9:00 pm

Re: Can't get esp_ble_gattc_read_char to trigger ESP_GATTC_READ_CHAR_EVT

Postby chegewara » Fri Feb 28, 2020 9:56 am

What is return code from esp_ble_gattc_read_char:
https://docs.espressif.com/projects/esp ... auth_req_t

Aussie Susan
Posts: 45
Joined: Thu Aug 22, 2019 3:48 am

Re: Can't get esp_ble_gattc_read_char to trigger ESP_GATTC_READ_CHAR_EVT

Postby Aussie Susan » Tue Mar 03, 2020 1:12 am

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

chegewara
Posts: 2378
Joined: Wed Jun 14, 2017 9:00 pm

Re: Can't get esp_ble_gattc_read_char to trigger ESP_GATTC_READ_CHAR_EVT

Postby chegewara » Tue Mar 03, 2020 10:22 pm

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).

Aussie Susan
Posts: 45
Joined: Thu Aug 22, 2019 3:48 am

Re: Can't get esp_ble_gattc_read_char to trigger ESP_GATTC_READ_CHAR_EVT

Postby Aussie Susan » Thu Mar 05, 2020 2:23 am

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

ESP_chinmay
Posts: 3
Joined: Tue Jul 02, 2019 5:52 pm

Re: Can't get esp_ble_gattc_read_char to trigger ESP_GATTC_READ_CHAR_EVT

Postby ESP_chinmay » Thu Mar 26, 2020 12:27 pm

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.
Attachments
patch.txt
(1.78 KiB) Downloaded 579 times

Who is online

Users browsing this forum: dzungpv and 99 guests