From d5abd660a2df59aef8250db8ed4d2d111cee6c98 Mon Sep 17 00:00:00 2001 From: Victor Chavez Date: Sat, 13 Apr 2024 01:24:31 +0200 Subject: [PATCH] fixed subscription --- test/renode/uptime_central/src/discovery.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/renode/uptime_central/src/discovery.cpp b/test/renode/uptime_central/src/discovery.cpp index 1d27f0b..544902b 100644 --- a/test/renode/uptime_central/src/discovery.cpp +++ b/test/renode/uptime_central/src/discovery.cpp @@ -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; @@ -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;