Trouble Logging Heartbeat

Hi everyone,

I am curretly struggling with displaying the heartbeat messages trough UART in mesh.

I used the bt mesh sensor example as a starting point. I set up a mesh sensor server on a nrf52840dongle which sends some random data periodically to a mesh sensor client (observer example) which is programmed to a nrf52840DK. Provisioning (trough nrf mesh app) and sending/receiving sensor values is working properly. 

Now i want to display the heartbeat messages. In the nrf mesh app I set up the heartbeat messages as follows:

Sensor Server is publishing heartbeat messages to the sensor client address destination with period of 4 seconds and a count of something above 1024 which is definetly enough time to receive and display the data. Through the nrf mesh app I set up the subscription of the sensor client to the heartbeat message of the sensor server with a period of at least half an hour. When I now click the refresh button I can see the incoming heartbeat messages from the sensor server.

Now my problem:

I want to display the incoming heatbeat messages on the console, so I implemented the heartbeat feature as follows:

// Define callback function to handle heartbeat events
void hb_sub_cb(const struct bt_mesh_hb_sub *sub, uint8_t hops, uint16_t feat) {
    // This function will be called when a heartbeat message is received
    // src: Source address of the heartbeat message
    // dst: Destination address of the heartbeat message
    // hops: Number of hops the message took
    // period: Period of the heartbeat message
    printk("Heartbeat received\n");
    LOG_INF("Heartbeat received from 0x%04x\n", sub->src);
    LOG_INF("\t\t dst      = 0x%04x\n", sub->dst);
    LOG_INF("\t\t hops     = %d\n", hops);
    LOG_INF("\t\t period   = %d\n", sub->period);
}

void hb_sub_end_cb(const struct bt_mesh_hb_sub *sub) {
    // This function will be called when the subscription period ends
    LOG_INF("Heartbeat subscription ended\n");
}

void hb_pub_sent_cb(const struct bt_mesh_hb_pub *pub) {
    // This function will be called when a heartbeat message is sent
    // dst: Destination address of the heartbeat message
    // count: Number of heartbeat messages sent
    // period: Period of the heartbeat message

    printk("Heartbeat published\n");
    LOG_INF("\t\t dst      = 0x%04x\n", pub->dst);
    LOG_INF("\t\t count    = %d\n", pub->count);
    LOG_INF("\t\t period   = %d\n", pub->period);
}

static struct bt_mesh_hb_cb hb_cb = {
    .recv = hb_sub_cb,
    .sub_end = hb_sub_end_cb,
    .pub_sent = hb_pub_sent_cb,
};

I also setup the definition for the heartbeat callback as follows:

const struct bt_mesh_comp *model_handler_init(void)
{
    k_work_init_delayable(&attention_blink_work, attention_blink);

    dk_button_handler_add(&button_handler);
   
    BT_MESH_HB_CB_DEFINE(hb_cb);

    return ∁
}

However when I build the application I get the warning that "'hb_cb' defined but not used [-Wunused-variable]" and nothing from the heartbeat is displayed in the serial monitor although I can see through nrf mesh app that messages are received.

Am I missing something?

I am using nRF Connect SDK v2.6.0

Best,

Toni

Related