Page 1 of 1

esp_ble_gatts_send_response doesn't work in the gatts_server_sercive_table demo

Posted: Tue Dec 29, 2020 7:11 pm
by klaetze
Hello everyone,

i have some strange problems, using the gatts_server_service_table example and i haven't found any similar posts yet.
In the example i added code to the ESP_GATTS_READ_EVT - Event, to respond to read events, like in the gatts_demo.c file

The read-event in my gatts_profile_event_handler() looks as follows:

Code: Select all

case ESP_GATTS_READ_EVT:{
            ESP_LOGI(GATTS_TABLE_TAG, "GATT_READ_EVT, conn_id %d, trans_id %d, handle %d\n", param->read.conn_id, param->read.trans_id, param->read.handle);
            esp_gatt_rsp_t rsp;
            memset(&rsp, 0, sizeof(esp_gatt_rsp_t));
            rsp.attr_value.handle = param->read.handle;
            rsp.attr_value.len = 4;

            //Hier muss je nach verwendetem Handle ausgelesen werden
            rsp.attr_value.value[0] = 0x16;
            rsp.attr_value.value[1] = 0x54;
            rsp.attr_value.value[2] = 0x32;
            rsp.attr_value.value[3] = 0x61;
            esp_ble_gatts_send_response(gatts_if, param->read.conn_id, param->read.trans_id,
                                        ESP_GATT_OK, &rsp);
            break;
        }
However when I try to send a read command from nRF Connect App i always get the following output:

Code: Select all

I (23582) BMP280-BLE: GATT_READ_EVT, conn_id 0, trans_id 2, handle 45

E (23582) BT_GATT: GATTS_SendRsp conn_id: 3  waiting for op_code = 00

E (23582) BT_APPL: Sending response failed
The problem is, i really don't understand why i get this output. It seems like the send response function trys to send the message to the conn_id: 03. But shouldnt the esp_ble_gatts_send_response() function send the message to conn_id: 0?
Or am i messing this whole thing up due to any other reason?

Re: esp_ble_gatts_send_response doesn't work in the gatts_server_sercive_table demo

Posted: Wed Dec 30, 2020 7:36 pm
by klaetze
Hello again to all,

today is a day to celebrate ;) . I have solved the problem.
It seems I should have read the tutorial more carefully :roll: .

Anyway, the error was that I didn't change the "attr_control" parameter in the service table "gatt_db".
By default it is set to "ESP_GATT_AUTO_RSP" and must be changed to "ESP_GATT_RSP_BY_APP".

Here is the code snippet:

Code: Select all

static const esp_gatts_attr_db_t gatt_db[HRS_IDX_NB] =
{
    // Service Declaration
    [IDX_SVC]        =
    {{ESP_GATT_RSP_BY_APP}, {ESP_UUID_LEN_16, (uint8_t *)&primary_service_uuid, ESP_GATT_PERM_READ,
      sizeof(uint16_t), sizeof(GATTS_SERVICE_UUID_ES), (uint8_t *)&GATTS_SERVICE_UUID_ES}},

Re: esp_ble_gatts_send_response doesn't work in the gatts_server_sercive_table demo

Posted: Fri Jan 15, 2021 1:51 am
by tasun2000
klaetze wrote:
Wed Dec 30, 2020 7:36 pm
Hello again to all,

today is a day to celebrate ;) . I have solved the problem.
It seems I should have read the tutorial more carefully :roll: .

Anyway, the error was that I didn't change the "attr_control" parameter in the service table "gatt_db".
By default it is set to "ESP_GATT_AUTO_RSP" and must be changed to "ESP_GATT_RSP_BY_APP".

Here is the code snippet:

Code: Select all

static const esp_gatts_attr_db_t gatt_db[HRS_IDX_NB] =
{
    // Service Declaration
    [IDX_SVC]        =
    {{ESP_GATT_RSP_BY_APP}, {ESP_UUID_LEN_16, (uint8_t *)&primary_service_uuid, ESP_GATT_PERM_READ,
      sizeof(uint16_t), sizeof(GATTS_SERVICE_UUID_ES), (uint8_t *)&GATTS_SERVICE_UUID_ES}},
following your code ,i can't resolve this problem

Re: esp_ble_gatts_send_response doesn't work in the gatts_server_sercive_table demo

Posted: Wed Apr 21, 2021 10:43 pm
by klaetze
Hey tasun2000,

ita been some time but maybe I can help you out.
what exactly is your problem?

Re: esp_ble_gatts_send_response doesn't work in the gatts_server_sercive_table demo

Posted: Tue Aug 03, 2021 1:33 pm
by lpxvcl
It indid helps a lot.

translate in Chinese:
确实有效,解决了问题。

Re: esp_ble_gatts_send_response doesn't work in the gatts_server_sercive_table demo

Posted: Thu Oct 07, 2021 3:41 pm
by lambertarthur22
Thanks for the post. Very helpfull.

Re: esp_ble_gatts_send_response doesn't work in the gatts_server_sercive_table demo

Posted: Wed Jan 04, 2023 2:22 pm
by Piotrvv
Hello.
I try to create characteristic with my own write response, but I'm not sure how to enable it. I use gatt_server_service_table. Probably after set ESP_GATT_RSP_BY_APP parameter I should set write_need_rsp and write.is_prep. Am I correct? If so, how and when should I do it?

Best regards
PiotrVV

Re: esp_ble_gatts_send_response doesn't work in the gatts_server_sercive_table demo

Posted: Thu Mar 23, 2023 7:33 pm
by TristanB
Hi everybody,
Thanks a lot for this post, it helps me to fix my communication.
Regards