Hi, I’m working on an nRF52840DK-based Bluetooth Mesh project derived from the Chat sample on nRF connect SDK extension for VS Code.
The setup involves three types of nodes:
- Setup Overview:
-
Client – Scans BLE devices using scan_cb(), computes the nearest, and sends that info in mesh messages using bt_mes_chat_cli_message_send() and setting the unicast address of gateway. It also occasionally receives messages from the gateway to update application-specific settings, such as the cooldown interval that limits how frequently it sends messages.
-
Relay – Forwards messages across mesh (fewer in number to reduce traffic).
-
Gateway – Receives messages from relays and uploads them to an MQTT broker(sent to esp32 via UART). It can also receive commands from MQTT and send them back to clients or relays.
The message received at the gateway side is handled in model_handler.c in the following manner:static void handle_chat_message(struct bt_mesh_chat_cli *chat, struct bt_mesh_msg_ctx *ctx, const uint8_t *msg) { /* Don't print own messages. */ if (address_is_local(chat->model, ctx->addr)) { return; } char buffer[64] = {0}; snprintf(buffer, sizeof(buffer), "%04X,%s\r\n", ctx->addr, (const char *)msg); print_uart(buffer); // shell_print(chat_shell, "<0x%04X>: %s", ctx->addr, msg); }
-
Goal:
I want to log the full message relay path — which intermediate nodes relayed a given message before it reached its destination (gateway).
Currently, I can log source and destination from the bt_mesh_msg_ctx, but I can’t determine which devices actually relayed it in between. - What I've tried:
What I’ve Tried
Enabled CONFIG_BT_MESH_NET_LOG_LEVEL_INF. added logging in net.c as follows: (inside the bt_mesh_net_recv function)
LOG_INF("=== MESSAGE PASSING THROUGH ===");
LOG_INF("Source: 0x%04x", rx.ctx.addr);
LOG_INF("Destination: 0x%04x", rx.ctx.recv_dst);
LOG_INF("TTL: %u", rx.ctx.recv_ttl);
LOG_INF("Sequence: 0x%06x", rx.seq);
LOG_INF("Control: %u", rx.ctl);
LOG_INF("Subnet: 0x%04x", rx.sub->net_idx);
LOG_INF("Payload (%u bytes): %s", buf.len, bt_hex(buf.data, buf.len));If not, what’s the recommended way to instrument the stack to log this relay trace (for debugging or analysis purposes)?
My prj.conf file is as follows:
# # Copyright (c) 2020 Nordic Semiconductor ASA # # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause # CONFIG_NCS_SAMPLES_DEFAULTS=y # Deferred logging helps improve LPN power consumption # when friendship is established. CONFIG_LOG_MODE_DEFERRED=y # General configuration CONFIG_NCS_APPLICATION_BOOT_BANNER_STRING="Mesh Chat" CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048 CONFIG_FLASH=y CONFIG_FLASH_MAP=y CONFIG_NVS=y CONFIG_SETTINGS=y CONFIG_NVS_LOOKUP_CACHE=y CONFIG_SETTINGS_NVS_NAME_CACHE=y CONFIG_HWINFO=y CONFIG_DK_LIBRARY=y CONFIG_PM_PARTITION_SIZE_SETTINGS_STORAGE=0x8000 CONFIG_SOC_FLASH_NRF_PARTIAL_ERASE=y # Bluetooth configuration CONFIG_BT=y CONFIG_BT_DEVICE_NAME="Gateway" CONFIG_BT_L2CAP_TX_BUF_COUNT=8 CONFIG_BT_OBSERVER=y CONFIG_BT_PERIPHERAL=y CONFIG_BT_SETTINGS=y CONFIG_PRINTK=y # Disable unused Bluetooth features CONFIG_BT_CTLR_LE_ENC=n CONFIG_BT_PHY_UPDATE=n CONFIG_BT_CTLR_CHAN_SEL_2=n CONFIG_BT_CTLR_MIN_USED_CHAN=n CONFIG_BT_CTLR_PRIVACY=n # Bluetooth Mesh configuration CONFIG_BT_MESH=y CONFIG_BT_MESH_RELAY=y CONFIG_BT_MESH_FRIEND=y CONFIG_BT_MESH_RX_SEG_MAX=10 CONFIG_BT_MESH_TX_SEG_MAX=10 CONFIG_BT_MESH_PB_GATT=y CONFIG_BT_MESH_GATT_PROXY=y CONFIG_BT_MESH_DK_PROV=y # Enable Bluetooth Mesh models debug logs CONFIG_BT_MESH_LOG_LEVEL_DBG=y # CONFIG_BT_MESH_NET_LOG_LEVEL_INF=y # Enable Shell module and use UART as a backend CONFIG_SHELL=y CONFIG_SHELL_BACKEND_SERIAL=y CONFIG_FLASH_SHELL=n CONFIG_LOG_BACKEND_RTT=n CONFIG_SHELL_PROMPT_UART="" CONFIG_SERIAL=y CONFIG_UART_NRFX=y
I’d really appreciate any guidance on whether the relay path can be traced via internal mesh structures or hooks. I’m okay with exploring internal APIs or debugging patches if needed, just want to understand the right entry point.
Best Regards.