Skip to content

Commit c97710c

Browse files
Carlo Weidingerkartben
authored andcommitted
samples: Bluetooth: Improve printing in NUS sample
Removing the message buffer and printing out the message directly. Creating a message buffer with the size of CONFIG_BT_L2CAP_TX_MTU creates a large empty buffer, which is expensive for the stack and can lead to a stack overflow. This way, the sample can be more easily integrated with other Bluetooth functionalities, such as Bluetooth OTA. Signed-off-by: Carlo Weidinger <[email protected]>
1 parent 4a3ce33 commit c97710c

File tree

1 file changed

+1
-4
lines changed
  • samples/bluetooth/peripheral_nus/src

1 file changed

+1
-4
lines changed

samples/bluetooth/peripheral_nus/src/main.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,10 @@ static void notif_enabled(bool enabled, void *ctx)
2929

3030
static void received(struct bt_conn *conn, const void *data, uint16_t len, void *ctx)
3131
{
32-
char message[CONFIG_BT_L2CAP_TX_MTU + 1] = "";
33-
3432
ARG_UNUSED(conn);
3533
ARG_UNUSED(ctx);
3634

37-
memcpy(message, data, MIN(sizeof(message) - 1, len));
38-
printk("%s() - Len: %d, Message: %s\n", __func__, len, message);
35+
printk("%s() - Len: %d, Message: %.*s\n", __func__, len, len, (char *)data);
3936
}
4037

4138
struct bt_nus_cb nus_listener = {

0 commit comments

Comments
 (0)