Skip to content

Commit 25cf9fc

Browse files
samples: bluetooth: add Device Name sample
Add a new BLE sample demonstrating how a peer can read and write the GAP Device Name characteristic (UUID 0x2A00) over BLE. The sample: - Advertises with a configurable default device name. - Allows connected peers to write a new name with open permissions. - Updates the SoftDevice GAP name and advertising data immediately. - Persists the new name to flash (BM ZMS) so it survives reboots. - Loads the saved name from storage on boot, falling back to the Kconfig default if none exists. Includes sample documentation and changelog entry. Signed-off-by: Martynas Smilingis <martynas.smilingis@nordicsemi.no>
1 parent 677efd0 commit 25cf9fc

7 files changed

Lines changed: 493 additions & 1 deletion

File tree

doc/nrf-bm/release_notes/release_notes_changelog.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ No changes since the latest nRF Connect SDK Bare Metal release.
9898
Bluetooth LE samples
9999
--------------------
100100

101-
No changes since the latest nRF Connect SDK Bare Metal release.
101+
* Added:
102+
103+
* The :ref:`ble_device_name_sample` sample.
102104

103105
NFC samples
104106
-----------
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#
2+
# Copyright (c) 2026 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
cmake_minimum_required(VERSION 3.20.0)
8+
9+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
10+
project(ble_device_name)
11+
12+
target_sources(app PRIVATE src/main.c)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#
2+
# Copyright (c) 2026 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
menu "Bluetooth LE Device Name sample"
8+
9+
config SAMPLE_BLE_DEVICE_NAME
10+
string "Device name"
11+
default "nRF_BM_Device"
12+
13+
config SAMPLE_BM_ZMS_SECTOR_SIZE
14+
int "Sector size"
15+
default 512
16+
17+
endmenu
18+
19+
module=SAMPLE_BLE_DEVICE_NAME
20+
module-str=BLE Device Name Sample
21+
source "$(ZEPHYR_BASE)/subsys/logging/Kconfig.template.log_config"
22+
23+
source "Kconfig.zephyr"
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
.. _ble_device_name_sample:
2+
3+
Bluetooth: Device name
4+
#################################
5+
6+
.. contents::
7+
:local:
8+
:depth: 2
9+
10+
The device name sample demonstrates how the connected peer can change the Bluetooth LE GAP Device name characteristic using |BMlong| and how to store the name in non-volatile memory.
11+
12+
Requirements
13+
************
14+
15+
The sample supports the following development kits:
16+
17+
.. tabs::
18+
19+
.. group-tab:: Simple board variants
20+
21+
The following board variants do **not** have DFU capabilities:
22+
23+
.. include:: /includes/supported_boards_all_non-mcuboot_variants_s115.txt
24+
25+
.. include:: /includes/supported_boards_all_non-mcuboot_variants_s145.txt
26+
27+
.. group-tab:: MCUboot board variants
28+
29+
The following board variants have DFU capabilities:
30+
31+
.. include:: /includes/supported_boards_all_mcuboot_variants_s115.txt
32+
33+
.. include:: /includes/supported_boards_all_mcuboot_variants_s145.txt
34+
35+
Overview
36+
********
37+
38+
The sample advertises with a configurable device name and allows any connected peer to write a new name to the GAP Device Name characteristic (UUID 0x2A00).
39+
When a new name is written:
40+
41+
* The Bluetooth LE GAP name is updated in both the SoftDevice and in the advertising data.
42+
* The device name is saved to non-volatile memory to persist across reboots and power loss.
43+
44+
During initialization, the sample reads the device name to use from non-volatile memory.
45+
If none exists, it uses the devise name set by the :kconfig:option:`CONFIG_SAMPLE_BLE_DEVICE_NAME` Kconfig option.
46+
47+
User interface
48+
**************
49+
50+
LED 0:
51+
Lit when the device is initialized.
52+
53+
LED 1:
54+
Lit when a device is connected.
55+
56+
Building and running
57+
********************
58+
59+
This sample can be found under :file:`samples/bluetooth/ble_device_name/` in the |BMshort| folder structure.
60+
61+
For details on how to create, configure, and program a sample, see :ref:`getting_started_with_the_samples`.
62+
63+
Testing
64+
=======
65+
66+
1. Compile and program the application.
67+
#. Connect the device to the computer.
68+
#. Connect to the kit with a terminal emulator (for example, the `Serial Terminal app`_).
69+
#. Reset the kit.
70+
#. Observe that ``Advertising as nRF_BM_Device`` is printed in the terminal.
71+
You can configure the default name using :kconfig:option:`CONFIG_SAMPLE_BLE_DEVICE_NAME` Kconfig option.
72+
#. Open the nRF Connect for Mobile or Desktop app and connect to the device.
73+
#. In the GAP service, find the **Device Name** characteristic (UUID 0x2A00).
74+
#. Read the current name to verify it matches the advertised name.
75+
#. Write a new name (for example, ``MyDevice``).
76+
#. Observe that the terminal prints::
77+
78+
Device name updated (8 bytes)
79+
New name
80+
4d 79 44 65 76 69 63 65 |MyDevice
81+
82+
#. Observe that ``Device name persisted to storage`` is printed shortly after.
83+
#. Disconnect from the device.
84+
#. Refresh and scan again using the nRF Connect for Mobile or Desktop.
85+
#. Observe that the device now advertises with the new name ``MyDevice``.
86+
#. Reset the kit and observe that the saved name is loaded from storage and used for advertising.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Logging
2+
CONFIG_LOG=y
3+
CONFIG_LOG_BACKEND_BM_UARTE=y
4+
5+
# SoftDevice
6+
CONFIG_SOFTDEVICE=y
7+
8+
# RNG (required by SoftDevice)
9+
CONFIG_NRF_SECURITY=y
10+
CONFIG_MBEDTLS_PSA_CRYPTO_C=y
11+
CONFIG_PSA_WANT_GENERATE_RANDOM=y
12+
13+
# Advertising library
14+
CONFIG_BLE_ADV=y
15+
16+
# ZMS
17+
CONFIG_BM_ZMS=y
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
sample:
2+
name: Bluetooth LE Device Name Sample
3+
tests:
4+
sample.ble_device_name:
5+
build_only: true
6+
integration_platforms:
7+
- bm_nrf54lv10dk/nrf54lv10a/cpuapp/s115_softdevice
8+
platform_allow:
9+
- bm_nrf54l15dk/nrf54l05/cpuapp/s115_softdevice
10+
- bm_nrf54l15dk/nrf54l05/cpuapp/s115_softdevice/mcuboot
11+
- bm_nrf54l15dk/nrf54l05/cpuapp/s145_softdevice
12+
- bm_nrf54l15dk/nrf54l05/cpuapp/s145_softdevice/mcuboot
13+
- bm_nrf54l15dk/nrf54l10/cpuapp/s115_softdevice
14+
- bm_nrf54l15dk/nrf54l10/cpuapp/s115_softdevice/mcuboot
15+
- bm_nrf54l15dk/nrf54l10/cpuapp/s145_softdevice
16+
- bm_nrf54l15dk/nrf54l10/cpuapp/s145_softdevice/mcuboot
17+
- bm_nrf54l15dk/nrf54l15/cpuapp/s115_softdevice
18+
- bm_nrf54l15dk/nrf54l15/cpuapp/s115_softdevice/mcuboot
19+
- bm_nrf54l15dk/nrf54l15/cpuapp/s145_softdevice
20+
- bm_nrf54l15dk/nrf54l15/cpuapp/s145_softdevice/mcuboot
21+
- bm_nrf54lm20dk/nrf54lm20a/cpuapp/s115_softdevice
22+
- bm_nrf54lm20dk/nrf54lm20a/cpuapp/s115_softdevice/mcuboot
23+
- bm_nrf54lm20dk/nrf54lm20a/cpuapp/s145_softdevice
24+
- bm_nrf54lm20dk/nrf54lm20a/cpuapp/s145_softdevice/mcuboot
25+
- bm_nrf54ls05dk/nrf54ls05b/cpuapp/s115_softdevice
26+
- bm_nrf54ls05dk/nrf54ls05b/cpuapp/s115_softdevice/mcuboot
27+
- bm_nrf54ls05dk/nrf54ls05b/cpuapp/s145_softdevice
28+
- bm_nrf54ls05dk/nrf54ls05b/cpuapp/s145_softdevice/mcuboot
29+
- bm_nrf54lv10dk/nrf54lv10a/cpuapp/s115_softdevice
30+
- bm_nrf54lv10dk/nrf54lv10a/cpuapp/s115_softdevice/mcuboot
31+
- bm_nrf54lv10dk/nrf54lv10a/cpuapp/s145_softdevice
32+
- bm_nrf54lv10dk/nrf54lv10a/cpuapp/s145_softdevice/mcuboot
33+
tags: ci_build

0 commit comments

Comments
 (0)