BLE characteristic size

QuangPhu
Posts: 5
Joined: Wed Feb 22, 2017 2:16 am

BLE characteristic size

Postby QuangPhu » Mon Mar 13, 2017 2:09 am

Hi,
I tried esp32 with gatt server example, I want to set a characteristic with more than 22 bytes, but in both examples(gatt_server and gatt_server_service_table), when I try set more than 22 bytes, esp32 auto set maximum 600 bytes in characteristic, and the data follow is not correct. So SDK supported this or not?
Beside that, where is the bluetooth support team, because many questions of mine and other one have not answered.
Thank you.

heyinling
Posts: 19
Joined: Thu Mar 23, 2017 7:21 am

Re: BLE characteristic size

Postby heyinling » Thu Mar 23, 2017 9:09 am

Hi,

22 bytes is the MTU size of GATT. If you want to read/write more than MTU size, you need to do read long or prepare write.

server handle read long:

Code: Select all

const char DEFAULT_LONG_VALUE[512];


// in gatts callback
esp_gatt_rsp_t *response = malloc(sizeof(esp_gatt_rsp_t));
    
    ...
    
case ESP_GATTS_READ_EVT:
	if (param->read.offset < sizeof(DEFAULT_LONG_VALUE) - 1) {
                response->attr_value.len = sizeof(DEFAULT_LONG_VALUE) - 1 - param->read.offset;
                response->attr_value.offset = param->read.offset;
                memcpy(response->attr_value.value,
                        DEFAULT_LONG_VALUE+param->read.offset, response->attr_value.len);
                esp_ble_gatts_send_response(gatts_if, param->read.conn_id, param->read.trans_id,
                        ESP_GATT_OK, response);
            }
            break;

server handle prepare write:

Code: Select all


// in gatts callback
        case ESP_GATTS_WRITE_EVT:
            if (param->write.is_prep == true) {
                response->attr_value.len = param->write.len;
                response->attr_value.offset = param->write.offset;
                ssc_os_memcpy(response->attr_value.value, param->write.value,
                        param->write.len);
            }
            esp_ble_gatts_send_response(gatts_if, param->write.conn_id, param->write.trans_id,
                    ESP_GATT_OK, response);
            break;
        case ESP_GATTS_EXEC_WRITE_EVT:
            switch (param->exec_write.exec_write_flag) {
                case ESP_GATT_PREP_WRITE_EXEC:
                    // client do want write
                    break;
                case ESP_GATT_PREP_WRITE_CANCEL:
                    // client want to discard all data
                    break;
                default:
                    break;
            }
            esp_ble_gatts_send_response(gatts_if, param->exec_write.conn_id, param->exec_write.trans_id,
                    ESP_GATT_OK, NULL);
If you use table and choose auto reply, just use the data and don't need to call esp_ble_gatts_send_response.

Who is online

Users browsing this forum: gustavoy and 68 guests