Page 1 of 1

esp_ble_gatts_set_attr_value,can not work!

Posted: Tue Mar 14, 2017 8:02 am
by JonathanChenNew
Hi
The function(esp_ble_gatts_set_attr_value) can not change attr_value.It returns OK,but when i use " esp_ble_gatts_get_attr_value",i found that the value has no change.And i have set "ESP_GATT_RSP_BY_APP".
My code:

Code: Select all

case ESP_GATTS_WRITE_EVT: {
		ESP_LOGI(UPDATE_GATTS_TAG, "GATT_WRITE_EVT, conn_id %d, trans_id %d, handle %d\n", param->write.conn_id, param->write.trans_id, param->write.handle);
		ESP_LOGI(UPDATE_GATTS_TAG, "GATT_WRITE_EVT, value len %d, value %08x\n", param->write.len, *(uint32_t *)param->write.value);
		LOG_ERROR("write value = %d\n",param->write.value[0]);
		esp_ble_gatts_set_attr_value(param->write.handle,param->write.len,param->write.value);
		esp_ble_gatts_send_response(gatts_if, param->write.conn_id, param->write.trans_id, ESP_GATT_OK, NULL);

		break;
	}
Thanks!

Re: esp_ble_gatts_set_attr_value,can not work!

Posted: Wed Mar 15, 2017 7:46 am
by ESP_Angus
Hi Jonathan,

Does the discussion in this Github issue apply to your code?
https://github.com/espressif/esp-idf/issues/428


Angus

Re: esp_ble_gatts_set_attr_value,can not work!

Posted: Tue Mar 21, 2017 5:05 am
by JonathanChenNew
ESP_Angus wrote:Hi Jonathan,

Does the discussion in this Github issue apply to your code?
https://github.com/espressif/esp-idf/issues/428


Angus
thank you
but it doesn't work.

Re: esp_ble_gatts_set_attr_value,can not work!

Posted: Wed Mar 29, 2017 2:48 pm
by jesseb
I haven't gotten the esp_ble_gatts_set_attr_value to work either. I can only change the value by remote writes. As far as I understand the esp_ble_gatts_set_attr_value is meant for when you use the attribute table and the control setting is ESP_GATT_AUTO_RSP. If it was ESP_GATT_RSP_BY_APP then you would simply use esp_ble_gatts_send_response when they read the value and cache whatever value passed when they the controller/client performs a write.

Re: esp_ble_gatts_set_attr_value,can not work!

Posted: Wed May 17, 2023 4:55 am
by tamhan
Attention! The handle table is initialized ASYNC, as in, some time after the main stack is inited.

I solved this problem by updating the BLE store only on device connect.

Also, keep in mind that the method returns ESP_OK even if the handle is unitialiyed, in this case it just bins the result.