I am following sample of “gatt_server_service_table” at https://github.com/espressif/esp-id ... vice_table .
My question is how can I change the value of characteristic in the code? I mean if I want to convey changes in temperature value to client, how will I change the characteristic value, so that it could be notified when notification has been enabled by client?
How can I change the value of BLE characteristic in the code?
Re: How can I change the value of BLE characteristic in the code?
Finally I was able to change value of characteristic and also notify to the client.
For anyone stuck like me, while following gatt_server_service_table example:
I defined characteristic value as :
Added characteristic in the table as follows:
Now to give new value to characteristic:
and notify the client:
And that is it!!!
For anyone stuck like me, while following gatt_server_service_table example:
I defined characteristic value as :
Code: Select all
uint8_t char_value[] = "InitialValue";
Code: Select all
[IDX_CHAR_A] =
{{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_write_notify}},
/* Characteristic Value */
[IDX_CHAR_VAL_A] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&GATTS_CHAR_UUID_TEST_A, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE, GATTS_DEMO_CHAR_VAL_LEN_MAX, sizeof(char_value), (uint8_t *)char_value}},
[IDX_CHAR_CFG_A] =
{{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(heart_measurement_ccc), (uint8_t *)heart_measurement_ccc}},
Code: Select all
uint8_t nval[ ] = "NewValue";
esp_ble_gatts_set_attr_value(heart_rate_handle_table[IDX_CHAR_VAL_A], sizeof(nval), nval);
and notify the client:
Code: Select all
esp_ble_gatts_send_indicate(heart_rate_profile_tab[PROFILE_APP_IDX].gatts_if , 0, heart_rate_handle_table[IDX_CHAR_VAL_A],
sizeof(nval), nval, false);
Who is online
Users browsing this forum: Bing [Bot], nopnop2002 and 96 guests