Skip to content

Commit

Permalink
fixed subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
vChavezB committed Apr 12, 2024
1 parent cbf20de commit d5abd66
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions test/renode/uptime_central/src/discovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ static uint8_t uptime_notify_cb(bt_conn *conn,
bt_gatt_subscribe_params *params,
const void *data, uint16_t length)
{
LOG_INF("Notification cb");
if (conn == NULL) {
return BT_GATT_ITER_CONTINUE;
}

if (!data) {
LOG_INF("[UNSUBSCRIBED]");
params->value_handle = 0U;
Expand Down Expand Up @@ -112,19 +117,21 @@ static uint8_t service_discover_cb(bt_conn *conn,
device_char_cnt = 0;
discover_characteristics(conn, attr, device_char_cnt);
} else if(char_found) {
LOG_INF("attr handle %u",attr->handle);
if (bt_uuid_cmp(params->uuid,
&uptime::uuid::char_notify.uuid) == 0) {
LOG_INF("notify found");
// Subscribe to uptime notification
subscribe_params.notify = uptime_notify_cb;
subscribe_params.value = BT_GATT_CCC_NOTIFY;
subscribe_params.ccc_handle = attr->handle;
subscribe_params.ccc_handle = attr->handle+2;
subscribe_params.value_handle = bt_gatt_attr_value_handle(attr);
const int err = bt_gatt_subscribe(conn, &subscribe_params);
if (err != 0 && err != -EALREADY) {
LOG_ERR("Subscribe failed (err %d)", err);
} else {
LOG_INF("[SUBSCRIBED]");
}
return BT_GATT_ITER_STOP;
}
if (device_char_cnt == TOTAL_CHARACTERISTICS-1) {
device_found = true;
Expand Down

0 comments on commit d5abd66

Please sign in to comment.