BLE Server attribute value response truncation issue

Ashvajit.P
Posts: 34
Joined: Fri Feb 26, 2021 9:03 am

BLE Server attribute value response truncation issue

Postby Ashvajit.P » Thu Jul 28, 2022 6:45 am

Hello

I am using ESP32 S3 with GATT server example. When I am sending read characteristic request from BLE client (ESP32 S3) then I am getting proper response as shown
ble_c_resp.PNG
BLE client log from ESP32 S3
ble_c_resp.PNG (29.92 KiB) Viewed 2921 times
But same request is sent form mobile app then I am getting same hex value dumped over 4-5 times and getting warning in the logs of my ESP32 S3 GATT SERVER
ble.PNG
BLE Server log in ESP32 S3 when requested from app
ble.PNG (37.64 KiB) Viewed 2921 times
BLE server code snippet :

Code: Select all

#define GATTS_DEMO_CHAR_VAL_LEN_MAX 0xf0
static uint8_t BLE_payload[60] =  { 46, 197, 213, 196, 245,  22,  22,  98,130, 180, 185,  27, 212,  55, 243, 215, 135,  12,   2,  75,  16,  54, 218, 125, 183, 159,  35, 161, 215, 221,  97, 26, 110, 105,  64, 145, 228, 242,  80,  70, 156,  34, 121, 213,  49, 229, 199, 148, 134, 73};
static uint8_t BLE_buffer[22] = { 46, 197, 213, 196, 245, 22, 22, 98, 130, 180, 185, 27, 212, 55, 243, 215, 135, 12, 2, 75, 16 };
static esp_attr_value_t gatts_demo_char1_val =
{
    .attr_max_len = GATTS_DEMO_CHAR_VAL_LEN_MAX,
    .attr_len     = 60,
    .attr_value   = BLE_payload,
};

Code: Select all

  
    case ESP_GATTS_READ_EVT: {
        ESP_LOGI(GATTS_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 = 32;
        rsp.attr_value.value[0] = 0xde;
        rsp.attr_value.value[1] = 0xed;
        rsp.attr_value.value[2] = 0xbe;
        rsp.attr_value.value[3] = 0xef;
	    memcpy(rsp.attr_value.value, BLE_payload, 32);
        esp_ble_gatts_send_response(gatts_if, param->read.conn_id, param->read.trans_id,
                                    ESP_GATT_OK, &rsp);
        break;

Response observed on app
nrf_ss.jpeg
Screenshot from NRF connect app after sending read request
nrf_ss.jpeg (157.7 KiB) Viewed 2921 times

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

Re: BLE Server attribute value response truncation issue

Postby chegewara » Mon Aug 01, 2022 6:09 am

I didnt check your code, but from NRF connect screenshot i can tell that you are sending incorrect value (characteristic value) on CCC descriptor request.

Ashvajit.P
Posts: 34
Joined: Fri Feb 26, 2021 9:03 am

Re: BLE Server attribute value response truncation issue

Postby Ashvajit.P » Mon Aug 01, 2022 6:19 am

Yes, but that is not the case with same data, wen requested from ESP module instead of the app

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

Re: BLE Server attribute value response truncation issue

Postby chegewara » Mon Aug 01, 2022 6:29 am

1. your code is messed in many places, one i mentioned above, another is probably sending response on read request, which is not setting bit which tells its not whole value sent (due to MTU size)
2. i am guessing esp32 BLE client code is exchanging MTU with server code, which you are not doing when using NRF connect app; this has to be done manually

All above are only guessing, because there is not enough info to provide more accurate solution.

Ashvajit.P
Posts: 34
Joined: Fri Feb 26, 2021 9:03 am

Re: BLE Server attribute value response truncation issue

Postby Ashvajit.P » Tue Aug 02, 2022 5:57 am

chegewara wrote:
Mon Aug 01, 2022 6:29 am
1. your code is messed in many places, one i mentioned above, another is probably sending response on read request, which is not setting bit which tells its not whole value sent (due to MTU size)
2. i am guessing esp32 BLE client code is exchanging MTU with server code, which you are not doing when using NRF connect app; this has to be done manually

All above are only guessing, because there is not enough info to provide more accurate solution.
Even if I use GATT server example as it is, I am not able to increase response bytes greater than 22. Or I don't know how to do that properly.
I want to send 60-70 bytes of data, Is there any way to manage this payload size ?

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

Re: BLE Server attribute value response truncation issue

Postby chegewara » Tue Aug 02, 2022 6:29 am

Screenshot_20220802-082708_nRF Connect.jpg
Screenshot_20220802-082708_nRF Connect.jpg (231.93 KiB) Viewed 2761 times

Who is online

Users browsing this forum: No registered users and 89 guests