setting & getting characteristic value to/from connected BLE device
This code snippet focused on getting proper characteristic handle in order to set or get values
void set_attribute(char *svc_uuid, char *chr_uuid, char *desc_uuid)
{
bt_gatt_h svc, chr, desc = NULL;
int ret; ret = bt_gatt_client_get_service(client, svc_uuid, &svc);
ret = bt_gatt_service_get_characteristic(svc, chr_uuid, &chr);
ret = bt_gatt_client_read_value(chr, __bt_gatt_client_read_complete_cb, NULL);
// If setter or getter are added here, probably they will return NULL
// because reading value which is returned by __bt_gatt_client_read_complete_cb must be not completed
// at the moment.
// Not sure how long it takes to complete read value, hence characteristic handle 'chr' used in this function
// won't be updated with read value.
// so simply setter or getter should be defined in __bt_gatt_client_read_complete_cb to ensure reding for the
// characteristic is completed.
}
void __bt_gatt_client_read_complete_cb(int result, bt_gatt_h gatt_handle, void *data)
{
char *uuid = NULL; bt_gatt_get_uuid(gatt_handle, uuid);
g_free(uuid);
// define setter or getter here using 'gatt_handle'.
bt_gatt_get_value(gatt_handle,...);
bt_gatt_set_value(gatt_handle,...);
.
.
.