esp_ble_gatts_send_response doesn't work in the gatts_server_sercive_table demo

klaetze
Posts: 13
Joined: Tue Dec 29, 2020 6:45 pm

esp_ble_gatts_send_response doesn't work in the gatts_server_sercive_table demo

Postby klaetze » Tue Dec 29, 2020 7:11 pm

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?

klaetze
Posts: 13
Joined: Tue Dec 29, 2020 6:45 pm

Re: esp_ble_gatts_send_response doesn't work in the gatts_server_sercive_table demo

Postby klaetze » 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}},

tasun2000
Posts: 1
Joined: Tue Jan 12, 2021 6:53 am

Re: esp_ble_gatts_send_response doesn't work in the gatts_server_sercive_table demo

Postby tasun2000 » Fri Jan 15, 2021 1:51 am

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

klaetze
Posts: 13
Joined: Tue Dec 29, 2020 6:45 pm

Re: esp_ble_gatts_send_response doesn't work in the gatts_server_sercive_table demo

Postby klaetze » Wed Apr 21, 2021 10:43 pm

Hey tasun2000,

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

lpxvcl
Posts: 11
Joined: Mon Jun 07, 2021 12:59 pm

Re: esp_ble_gatts_send_response doesn't work in the gatts_server_sercive_table demo

Postby lpxvcl » Tue Aug 03, 2021 1:33 pm

It indid helps a lot.

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

lambertarthur22
Posts: 1
Joined: Thu Oct 07, 2021 3:39 pm

Re: esp_ble_gatts_send_response doesn't work in the gatts_server_sercive_table demo

Postby lambertarthur22 » Thu Oct 07, 2021 3:41 pm

Thanks for the post. Very helpfull.

Piotrvv
Posts: 2
Joined: Thu Dec 29, 2022 2:32 pm

Re: esp_ble_gatts_send_response doesn't work in the gatts_server_sercive_table demo

Postby Piotrvv » Wed Jan 04, 2023 2:22 pm

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

TristanB
Posts: 4
Joined: Wed Jun 15, 2022 9:53 am

Re: esp_ble_gatts_send_response doesn't work in the gatts_server_sercive_table demo

Postby TristanB » Thu Mar 23, 2023 7:33 pm

Hi everybody,
Thanks a lot for this post, it helps me to fix my communication.
Regards

Who is online

Users browsing this forum: No registered users and 83 guests