Sending Response Failed

eowesi
Posts: 11
Joined: Sat Jun 09, 2018 8:55 am

Sending Response Failed

Postby eowesi » Sat Jun 09, 2018 9:03 am

I am trying to learn by changing the sample code( esp-idf/examples/bluetooth/gatt_server).I simply copy from ESP_GATTS_READ_EVT and paste to ESP_GATTS_WRITE_EVT.when I want to receive data and send some data to client.The code looks like:

Code: Select all

    case ESP_GATTS_WRITE_EVT: {
        ESP_LOGI(GATTS_TAG, "GATT_WRITE_EVT, conn_id %d, trans_id %d, handle %d", param->write.conn_id, param->write.trans_id, param->write.handle);
        if (!param->write.is_prep){
            ESP_LOGI(GATTS_TAG, "GATT_WRITE_EVT, value len %d, value :", param->write.len);
            esp_log_buffer_hex(GATTS_TAG, param->write.value, param->write.len);
            if (gl_profile_tab[PROFILE_A_APP_ID].descr_handle == param->write.handle && param->write.len == 2){
                uint16_t descr_value = param->write.value[1]<<8 | param->write.value[0];
                if (descr_value == 0x0001){
                    if (a_property & ESP_GATT_CHAR_PROP_BIT_NOTIFY){
                        ESP_LOGI(GATTS_TAG, "notify enable");
                        uint8_t notify_data[15];
                        for (int i = 0; i < sizeof(notify_data); ++i)
                        {
                            notify_data[i] = i%0xff;
                        }
                        //the size of notify_data[] need less than MTU size
                        esp_ble_gatts_send_indicate(gatts_if, param->write.conn_id, gl_profile_tab[PROFILE_A_APP_ID].char_handle,
                                                sizeof(notify_data), notify_data, false);
                    }
                }else if (descr_value == 0x0002){
                    if (a_property & ESP_GATT_CHAR_PROP_BIT_INDICATE){
                        ESP_LOGI(GATTS_TAG, "indicate enable");
                        uint8_t indicate_data[15];
                        for (int i = 0; i < sizeof(indicate_data); ++i)
                        {
                            indicate_data[i] = i%0xff;
                        }
                        //the size of indicate_data[] need less than MTU size
                        esp_ble_gatts_send_indicate(gatts_if, param->write.conn_id, gl_profile_tab[PROFILE_A_APP_ID].char_handle,
                                                sizeof(indicate_data), indicate_data, true);
                    }
                }
                else if (descr_value == 0x0000){
                    ESP_LOGI(GATTS_TAG, "notify/indicate disable ");
                }else{
                    ESP_LOGE(GATTS_TAG, "unknown descr value");
                    esp_log_buffer_hex(GATTS_TAG, param->write.value, param->write.len);
                }

            }
        }

        ////////////NEW/////////////
        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;
        rsp.attr_value.value[0] = 0xde;
        rsp.attr_value.value[1] = 0xed;
        rsp.attr_value.value[2] = 0xbe;
        rsp.attr_value.value[3] = 0xef;
        esp_ble_gatts_send_response(gatts_if, param->read.conn_id, param->read.trans_id,
                                    ESP_GATT_OK, &rsp);

        ////////////NEW/////////////
        break;
    }
The error:
E (16892) BT_GATT: GATTS_SendRsp conn_id: 3 waiting for op_code = 00

E (16892) BT_APPL: Sending response failed

MarkIngle
Posts: 30
Joined: Wed Jan 18, 2017 4:48 am

Re: Sending Response Failed

Postby MarkIngle » Fri Jul 13, 2018 4:29 am

I am having the same problem...

[0;32mI (2143069) SampleNotify: Peripheral is connected to Central. I am now a Slave[0m
[0;31mE (2143983) BT_GATT: GATTS_SendRsp conn_id: 3 waiting for op_code = 00
[0m
[0;31mE (2143984) BT_APPL: Sending response failed
[0m
[0;32mI (2145069) SampleNotify: *** NOTIFY: 0 ***[0m

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

Re: Sending Response Failed

Postby chegewara » Fri Jul 13, 2018 8:27 am

According to my theoretical knowledge you can and you should send response only in case your characteristic is setup to write with response. In case your characteristic is setup only to write you wont get ACK "op_code = 00".
Also you are trying to send response from write event, which means parameters you are trying to retrieve from event are wrong:

Code: Select all

esp_ble_gatts_send_response(gatts_if, param->read.conn_id, param->read.trans_id, ESP_GATT_OK, &rsp);
You need to use param->write instead.

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

Re: Sending Response Failed

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

Hey, I have a similar problem.
I tried to implement the esp_ble_gatts_send_response()-function in the ESP_GATTS_READ_EVT in the gatts_table_demo.
Here is my code:

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->write.conn_id, param->write.trans_id, param->write.handle);
            esp_gatt_rsp_t rsp;
            memset(&rsp, 0, sizeof(esp_gatt_rsp_t));
            rsp.attr_value.handle = param->write.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] = 0x66;
            rsp.attr_value.value[2] = 0x66;
            rsp.attr_value.value[3] = 0x61;
            esp_ble_gatts_send_response(gatts_if, param->write.conn_id, param->write.trans_id,
                                        ESP_GATT_OK, &rsp);
            break;
        }
       
I already tried to use param->read instead of param->write, but i still get the same error output. Do you have already solved this problem?

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

Re: Sending Response Failed

Postby klaetze » Wed Dec 30, 2020 7:38 pm

Hi,

if anyone still has a similar issue, i solved mine in https://www.esp32.com/viewtopic.php?f=13&t=18763

Kind Regards

Who is online

Users browsing this forum: No registered users and 175 guests