example/read_write: Implement 'write' using characteristic's UUID

pull/14/head
Olivier Martin 2017-02-22 12:17:53 +01:00
parent 4ab4cddfba
commit e11618bdeb
1 changed files with 23 additions and 1 deletions

View File

@ -82,7 +82,29 @@ int main(int argc, char *argv[]) {
printf("%02x ", buffer[i]);
printf("\n");
} else {
uint16_t handle = 0; //TODO: FIXME
uint16_t handle = 0;
// Look for handle for the corresponding UUID
gattlib_characteristic_t* characteristics;
int characteristic_count;
ret = gattlib_discover_char(connection, &characteristics, &characteristic_count);
if (ret) {
fprintf(stderr, "Fail to discover characteristic.\n");
return 1;
}
for (i = 0; i < characteristic_count; i++) {
if (gattlib_uuid_cmp(&characteristics[i].uuid, &g_uuid) == 0) {
handle = characteristics[i].value_handle;
break;
}
}
if (handle == 0) {
fprintf(stderr, "Fail to find handle for UUID.\n");
return 1;
}
free(characteristics);
ret = gattlib_write_char_by_handle(connection, handle, buffer, sizeof(buffer));
assert(ret == 0);
}