Can't get esp_ble_gattc_read_char to trigger ESP_GATTC_READ_CHAR_EVT
-
- 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
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
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
-
- 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
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
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
-
- 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
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
Susan
Re: Can't get esp_ble_gattc_read_char to trigger ESP_GATTC_READ_CHAR_EVT
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.
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.
-
- 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
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
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
What is return code from esp_ble_gattc_read_char:
https://docs.espressif.com/projects/esp ... auth_req_t
https://docs.espressif.com/projects/esp ... auth_req_t
-
- 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
The code in that part of the app is:
As nothing triggers the 'ESP_ERROR_CHECK' I take it that it is not returning an error.
Susan
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);
Susan
Re: Can't get esp_ble_gattc_read_char to trigger ESP_GATTC_READ_CHAR_EVT
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).
You can build BLE sniffer with nrf52840 dongle fairly easy and cheap (about $12).
-
- 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
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
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
-
- 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
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.
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 578 times
Who is online
Users browsing this forum: Baidu [Spider] and 82 guests