Can't get esp_ble_gattc_read_char to trigger ESP_GATTC_READ_CHAR_EVT

Aussie Susan
Posts: 44
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 Mar 27, 2020 10:59 pm

Thank you for your patch which I have just applied.
I get the text "Inside esp_ble_gattc_read_char" but nothing after that.
Also, what is the point of the call to 'read char' from within the 'write char' function (the 2nd part of the patch)? I'm never calling write char and it does not seem to be called (as I put a printf just before the call that was inserted and it is not triggered).
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 » Sat Mar 28, 2020 4:30 pm

This patch is just a simple way to verify that ESP_GATTC_READ_CHAR_EVT event is triggered when esp_ble_gattc_read_char function is called. Since the default behavior of gatt_client is to write and not to read server's characteristic, I called read_char inside write_char and inserted logs to verify this.
By applying this patch and running gatt_server and gatt_client examples simultaneously on 2 esp32, you should get following logs on gatt_client:

Code: Select all

I (22890) GATTC_DEMO: write descr success 
Inside esp_ble_gattc_read_char
I (22970) GATTC_DEMO: ESP_GATTC_READ_CHAR_EVT called.
I (23050) GATTC_DEMO: write char success 
But as you say,
I get the text "Inside esp_ble_gattc_read_char" but nothing after that.
I'm never calling write char and it does not seem to be called
If this is the case, then you should not see "Inside esp_ble_gattc_read_char" also as esp_ble_gattc_read_char is being called from esp_ble_gattc_write_char only (in the patch). Can you stash your modifications and run default examples for gatt_server and gatt_client to verify the give patch.
Again, this patch does nothing, it is just to verify that ESP_GATTC_READ_CHAR_EVT event is triggered when esp_ble_gattc_read_char function is called.

Aussie Susan
Posts: 44
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 Mar 29, 2020 4:41 am

I think I have found the solution.
In the ESP_GATTC_SEARCH_RES_EVT, if the service was one I was interested in, I was calling esp_ble_gattc_get_all_char and then remembered the characteristic handle fr later on.
In the ESP_GATTC_SEARCH_CMPL_EVT I was reading the queued up characteristic handle and calling esp_ble_gattc_read_char and not getting any return event.
What seems to work is in the ESP_GATTC_SEARCH_RES_EVT code to just remember the start and end handles but that is all.
then in the ESP_GATTC_SEARCH_CMPL_EVT code to call both esp_ble_gattc_get_all_char and then esp_ble_gattc_read_char. The ESP_GATTC_READ_CHAR_EVT is then called and the value made available. After all of the values are read then I close the connection and restart the scan.
This is where the documentation is very poor (in my opinion). It is too granular in that it tells you the functions but (in most cases) not what events are triggered. For each event it tells you almost nothing and certainly not what restrictions there are on calling other BLE functions. The example is too simplistic in that it only reads one characteristic from one service.
Thank you for all who have read this thread and considered it.
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 » Sun Mar 29, 2020 10:04 am

Thanks for your feedback on documentation. We will consider improving it.
Since your issue is resolved, it would be helpful if you post the solution on Github also and close the issue.

adrian-fratila
Posts: 6
Joined: Sat May 15, 2021 2:40 pm

Re: Can't get esp_ble_gattc_read_char to trigger ESP_GATTC_READ_CHAR_EVT

Postby adrian-fratila » Sat May 15, 2021 2:59 pm

Hi Susan, could you please share the solution that you have presented above (on 29th March), as a C code. I have tried to figure out from your explanations what should be done to get the read functionality working but I am a newbie in ESP32, and have already spent quite some time on this issue without success. Thank you!

Who is online

Users browsing this forum: No registered users and 143 guests