[TW#12341] BLE characteristics value read/write operations

dperez
Posts: 8
Joined: Wed Jul 27, 2016 8:02 am

[TW#12341] BLE characteristics value read/write operations

Postby dperez » Thu Feb 09, 2017 3:53 pm

Hi,

I am working on the gatt_server example. I have modified the code to define a 'propietary' (128bit UUID) with a characteristic.

When callin esp_ble_gatts_add_char function:
  • Permisions: ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE
  • Properties: ESP_GATT_CHAR_PROP_BIT_READ | ESP_GATT_CHAR_PROP_BIT_WRITE | ESP_GATT_CHAR_PROP_BIT_WRITE_NR
Also in "esp_attr_value_t *char_val" parameter y use "&gatts_char_value" that has been defined:

static uint8_t char_value[10] = {0};
esp_attr_value_t gatts_char_value =
{
.attr_max_len = sizeof(char_value),
.attr_len = sizeof(char_value),
.attr_value = char_value,
};

My problems are that once connected and discovered the services, the characteristic has the correct length, I mean 10 bytes but its value is not zero.

Also when reading (esp_ble_gatts_get_attr_value(...)) or writing (esp_ble_gatts_set_attr_value(...)) to this characteristic value despite I receive a ESP_OK response from the mentioned functions it seems the write doesn't work because after writing 10 bytes to '11' the value I get when reading is the same that I get at the beginning.

So is there any bug in these functions? Is there any example that shows how to set/get values to characteristics? Any help will be appreciated. Thanks in advance.

ESP_Tianhao
Posts: 28
Joined: Thu Jan 05, 2017 10:46 am

Re: BLE characteristics value read/write operations

Postby ESP_Tianhao » Mon Feb 13, 2017 8:44 am

We provide two ways to decide the way of sending response by GATT server. One is sent by application by user, and another way is sent by low-layer stack. If use "esp_ble_gatts_set_attr_value", the low-layer stack will store the attribute value. But if you dont't specify low-layer stack send read/write response automatically, even the low-layer stack know the attribute value, it won't send read/write response.
In the demo, this demo will send read/write response by application. So even you call "esp_ble_gatts_set_attr_value", it will not send the value what you set by "esp_ble_gatts_set_attr_value". I will send response by application when received ESP_GATTS_READ_EVT.
In your case, you should set the "ESP_GATT_AUTO_RSP" when call "esp_ble_gatts_add_char" or send response of your "gatts_char_value" in the event_callback functions when received ESP_GATTS_READ_EVT.

dperez
Posts: 8
Joined: Wed Jul 27, 2016 8:02 am

Re: BLE characteristics value read/write operations

Postby dperez » Thu Feb 16, 2017 11:19 am

Thanks ESP_Tianhao,

Now it is clear!

Once I have set "esp_attr_control_t *control" parameter on "esp_ble_gatts_add_char" function call, read/write operations works ok and autonomously managed.

Without setting this parameter like you said our app has to manage read/write operations with ESP_GATTS_READ_EVT and ESP_GATTS_WRITE_EVT events.

Thanks for your help.

Luca_Guazzaroni
Posts: 4
Joined: Thu Feb 23, 2017 1:12 pm

Re: BLE characteristics value read/write operations

Postby Luca_Guazzaroni » Thu Mar 30, 2017 1:31 pm

HI!
i am having problems with the esp_ble_gatts_set_attr_value function. I setup my service and characteristic by a gatts table and create it with "esp_ble_gatts_create_attr_tab". The thing is that once created the service and characteristic, i cannot change the craracteristic value with "esp_ble_gatts_set_attr_value". I alredy configure the auto responde. Can anyone of you tell me what i am doing wrong?

here the code:

constants declaration:

Code: Select all

static const uint16_t primary_service_uuid     = ESP_GATT_UUID_PRI_SERVICE;
static const uint16_t character_declaration_uuid     = ESP_GATT_UUID_CHAR_DECLARE;
static const uint16_t character_client_config_uuid   = ESP_GATT_UUID_CHAR_CLIENT_CONFIG;
static const uint8_t  char_prop_read_notify 	 	     = ESP_GATT_CHAR_PROP_BIT_NOTIFY|ESP_GATT_CHAR_PROP_BIT_READ;

static const uint16_t IR_Temperature_svc		= 0xD200;
static const uint16_t IR_Temperature_char_uuid 	= 0xD201;
static const uint8_t  char_CCCD_notify[2] 		= {0x00,0x00};

static const uint16_t IR_CHAR_DECL_HANDLE  = 42;
static const uint16_t IR_CHAR_VALUE_HANDLE  = 43;

uint8_t IR_Temperature_value[] = {0x00,0x00};
attr tab declaration:

Code: Select all

static const esp_gatts_attr_db_t IR_Temperature_gatt_db[IR_IDX_NB] =
{
	// IR Temperature service declaration
	[IR_TEMP_IDX_SVC]       =
	{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&primary_service_uuid, ESP_GATT_PERM_READ,
	  sizeof(uint16_t), sizeof(IR_Temperature_svc), (uint8_t *)&IR_Temperature_svc}},

	// IR temperature Characteristic declaration
	[IR_TEMP_IDX_CHAR]  =
	{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&character_declaration_uuid, ESP_GATT_PERM_READ,
	  CHAR_DECLARATION_SIZE,CHAR_DECLARATION_SIZE, (uint8_t *)&char_prop_read_notify}},

	// IR temperature Characteristic value
	[IR_TEMP_IDX_VAL]   =
	{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&IR_Temperature_char_uuid, ESP_GATT_PERM_READ,
	  sizeof(IR_Temperature_value), sizeof(IR_Temperature_value), (uint8_t *)IR_Temperature_value}},

	// Client Characteristic Configuration Descriptor
	[IR_TEMP_IDX_NTF_CFG]     	=
	{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&character_client_config_uuid,  
	   ESP_GATT_PERM_READ|ESP_GATT_PERM_WRITE,
	  sizeof(uint16_t),sizeof(char_CCCD_notify), (uint8_t *)char_CCCD_notify}},
};
With this code the nRFconnect App detects correctly the service and characterist with the initial value. When i want to uptate de characteristic value, i call

Code: Select all

//IR_Sensor_read comes from a uart with other data
IR_Temperature_value[0] = IR_Sensor_read[0];
IR_Temperature_value[1] = IR_Sensor_read[1];

esp_err_t rsp;

rsp = esp_ble_gatts_set_attr_value(IR_CHAR_VALUE_HANDLE, sizeof(IR_Temperature_value), (uint8_t *)IR_Temperature_value);

if(rsp==ESP_OK){
    	ESP_LOGI(GATTS_TAG,"esp_ble_gatts_set_attr_value == ESP_OK\n");
 }
 else{
 	ESP_LOGI(GATTS_TAG,"The ERROR: %d\n", rsp);
 }
but when i check the nRFconnect app, the value not change.

PD: i use the gatt_tab because the application i am developing has 3 services one for R/W, other for Read and the las for Read and notification.

davidtrc
Posts: 1
Joined: Wed Sep 06, 2017 2:06 pm

Re: [TW#12341] BLE characteristics value read/write operations

Postby davidtrc » Wed Sep 06, 2017 2:07 pm

Hello, any news?

I have the same problem and cannot find any solution.

Thanks in advance

TVA_VAE
Posts: 5
Joined: Sun Nov 29, 2020 3:15 pm

Re: [TW#12341] BLE characteristics value read/write operations

Postby TVA_VAE » Sun Nov 29, 2020 3:16 pm

Same problem here... (with the table example and auto updates).


Who is online

Users browsing this forum: ESP_Sprite, shraiwi and 120 guests