Getting "GATTS_SendRsp conn_id: 3 waiting for op_code = 0a"

Rajendra Chhasatiya
Posts: 4
Joined: Thu Aug 26, 2021 4:13 am

Getting "GATTS_SendRsp conn_id: 3 waiting for op_code = 0a"

Postby Rajendra Chhasatiya » Wed May 24, 2023 8:50 am

Hello All,

I am traying to send more then 20byte in chunk using BLE GAP and GATTS profile but getting below error while doing,

ESPIDF: version 3.2
E (24930) BT_GATT: GATTS_SendRsp conn_id: 3 waiting for op_code = 0a

E (24930) BT_APPL: Sending response failed
Sharing snippet code

Code: Select all

    case ESP_GATTS_READ_EVT: {
        ESP_LOGI(GATTS_TAG,"<<<<<<<<<<<<<< Event: %d", event);
        esp_gatt_rsp_t rsp;
        memset(&rsp, 0, sizeof(esp_gatt_rsp_t));
        char ctest[30]={'a','b','b','b','b','b','b','b','b','b','b','b','b','b','b','b','b','b','b','c','c','c','c','c','c','c','c','c'};
        int offset = 0;
        int remaining_len = strlen(ctest);
        ESP_LOGI(GATTS_TAG,"<<<<<<<<<<<<<< remaining_len: %d", remaining_len);
        while (remaining_len > 0)
        {
            int chunk_len = remaining_len > 20 ? 20 : remaining_len;
            ESP_LOGI(GATTS_TAG, "chunk_len:%d",chunk_len);
            ESP_LOGI(GATTS_TAG, "offset:%d",offset);
            ESP_LOGI(GATTS_TAG, "ctest:%s",ctest);
            esp_ble_gatts_send_response(gatts_if, param->read.conn_id, ESP_GATT_OK, offset, (uint8_t *)&ctest[offset]);

            offset += chunk_len;
            remaining_len -= chunk_len;

            vTaskDelay(pdMS_TO_TICKS(1000)); // Delay between sending chunks (adjust as needed)
        }
can anyone tell me that how i can send more then 20 char, i will be thank full if anyone can help me out from this issue.

Thanks.

MicroController
Posts: 1735
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Getting "GATTS_SendRsp conn_id: 3 waiting for op_code = 0a"

Postby MicroController » Wed May 24, 2023 9:03 pm

1. Don't try and send multiple responses to a single read event.
2. Don't vTaskDelay in an event handler.
3. Look at the "how to long read" at https://sankalpb.github.io/bluetooth-lo ... esp32.html

Rajendra Chhasatiya
Posts: 4
Joined: Thu Aug 26, 2021 4:13 am

Re: Getting "GATTS_SendRsp conn_id: 3 waiting for op_code = 0a"

Postby Rajendra Chhasatiya » Thu Jun 01, 2023 7:32 am

MicroController wrote:
Wed May 24, 2023 9:03 pm
1. Don't try and send multiple responses to a single read event.
2. Don't vTaskDelay in an event handler.
3. Look at the "how to long read" at https://sankalpb.github.io/bluetooth-lo ... esp32.html
Hii Thanks for the support, Still i am not able send more then 22 char in single read event, Please below code and let me know am i doing wrong.

Code: Select all

		case ESP_GATTS_READ_EVT: {
			char sourceArray[] = "Hello, World! my name is  testing BLE";
			
			esp_gatt_rsp_t rsp;
			partial_buf buf;
			uint16_t offset = 0;

        	memset(&rsp, 0, sizeof(esp_gatt_rsp_t));
			size_t length = sizeof(sourceArray);
			buf.buf = (uint8_t*)sourceArray;
			buf.len = length;
			ESP_LOGI(GATTS_TAG,"buf.buf:%s",buf.buf);
			if ((param->read.is_long && buf.buf) == 0) {
					rsp.attr_value.handle = param->read.handle;
					int remaining_read = (buf.len - param->read.offset);
					rsp.attr_value.len = (remaining_read) > 22 ? 22: remaining_read;
					memcpy(rsp.attr_value.value, buf.buf + param->read.offset, rsp.attr_value.len);
					if (offset + rsp.attr_value.len >= buf.len) {
						if (buf.buf) {
							free(buf.buf);
							buf.buf = NULL;
						}
						buf.len = 0;
					}
				}
				esp_ble_gatts_send_response(gatts_if, param->read.conn_id, param->read.trans_id,
                                    ESP_GATT_OK, &rsp);
						 break;
			}
you can see that below condition not getting true, its always false

Code: Select all

if(offset + rsp.attr_value.len >= buf.len)

MicroController
Posts: 1735
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Getting "GATTS_SendRsp conn_id: 3 waiting for op_code = 0a"

Postby MicroController » Thu Jun 01, 2023 9:24 am

Code: Select all

rsp.attr_value.len = (remaining_read) > 22 ? 22: remaining_read;
According to this example, attr_value.len should be the total length of the attribute value; this way, the other side knows if it has to read more data or not.

Also, watch out:

Code: Select all

char sourceArray[] = "Hello, World! my name is  testing BLE";
...
buf.buf = (uint8_t*)sourceArray;
...
free(buf.buf);

Who is online

Users browsing this forum: Bing [Bot], snutw_ and 140 guests