|
| 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. |
0 commit comments