I have seen a few posts including:
- Change advertised name (Bluetooth) - Nordic Q&A - Nordic DevZone - Nordic DevZone (nordicsemi.com)
- NCS bt_set_name() - Nordic Q&A - Nordic DevZone - Nordic DevZone (nordicsemi.com)
- Setting Bluetooth Device Name in Zephyr - Nordic Q&A - Nordic DevZone - Nordic DevZone (nordicsemi.com)
but I still haven't been able to adapt one of the examples to show the name dynamically.
This is the code:
Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/gap.h>
#include <zephyr/bluetooth/uuid.h>
#include <zephyr/bluetooth/conn.h>
#include <dk_buttons_and_leds.h>
#include <stdio.h> // For snprintf
#include <stdlib.h>
#include "ble_manager.h"
LOG_MODULE_REGISTER(ble_manager, LOG_LEVEL_DBG);
#define DEVICE_NAME CONFIG_BT_DEVICE_NAME
#define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1)
/* STEP 2.1 - Declare the Company identifier (Company ID) */
And this is the prj.conf:
Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Logger module
CONFIG_LOG=y
# Button and LED library
CONFIG_DK_LIBRARY=y
# Bluetooth LE
CONFIG_BT=y
CONFIG_BT_PERIPHERAL=y
#CONFIG_BT_DEVICE_NAME="TEST Peripheral"
CONFIG_BT_DEVICE_NAME_DYNAMIC=y
# Maximum chcaracter of the device name
# (Range: 2 to 248)
CONFIG_BT_DEVICE_NAME_MAX=17
# Increase stack size for the main thread and System Workqueue
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
CONFIG_MAIN_STACK_SIZE=2048
Is there something else I need to do either in the bt_data
or in the bt_le_adv_start
?