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

Parents
  • Hi Toni,

    My apology for taking such a while. I believe the reason the callback was not properly registered is because you put BT_MESH_HB_CB_DEFINE() inside a function instead of outside. See how it's used in the Mesh Demo sample: sdk-zephyr/samples/bluetooth/mesh_demo/src/main.c at v3.5.99-ncs1 · nrfconnect/sdk-zephyr (github.com).

    Regarding your new issue with the Unknown Netkey error log, the error indicates that the BT Mesh stack cannot find the NetKey with index 0x00.
    Given the context, could you check if it can be one of these more likely cases?

    • Calling Hearbeat APIs that requires the NetKey before the NetKey is restored from non-volatile memory, most often with settings_load().
    • The Settings partition being corrupted, most often from accidental/incorrect Settings/NVS flash writes, i.e. when you have custom flash memory write operations.
    • Calling Heartbeat APIs on an unprovisioned node.

    Best,

    Hieu

Reply
  • Hi Toni,

    My apology for taking such a while. I believe the reason the callback was not properly registered is because you put BT_MESH_HB_CB_DEFINE() inside a function instead of outside. See how it's used in the Mesh Demo sample: sdk-zephyr/samples/bluetooth/mesh_demo/src/main.c at v3.5.99-ncs1 · nrfconnect/sdk-zephyr (github.com).

    Regarding your new issue with the Unknown Netkey error log, the error indicates that the BT Mesh stack cannot find the NetKey with index 0x00.
    Given the context, could you check if it can be one of these more likely cases?

    • Calling Hearbeat APIs that requires the NetKey before the NetKey is restored from non-volatile memory, most often with settings_load().
    • The Settings partition being corrupted, most often from accidental/incorrect Settings/NVS flash writes, i.e. when you have custom flash memory write operations.
    • Calling Heartbeat APIs on an unprovisioned node.

    Best,

    Hieu

Children
Related