Bluetooth: Peripheral Status

The peripheral status sample demonstrates how to use the Nordic Status Message Service (NSMS) library.

Requirements

The sample supports the following development kits:

Hardware platforms

PCA

Board name

Board target

Thingy:53

PCA20053

thingy53

thingy53/nrf5340/cpuapp/ns thingy53/nrf5340/cpuapp

nRF54L15 DK

PCA10156

nrf54l15dk

nrf54l15dk/nrf54l15/cpuapp

nRF54H20 DK

PCA10175

nrf54h20dk

nrf54h20dk/nrf54h20/cpuapp

nRF5340 DK

PCA10095

nrf5340dk

nrf5340dk/nrf5340/cpuapp/ns nrf5340dk/nrf5340/cpuapp

nRF52 DK

PCA10040

nrf52dk

nrf52dk/nrf52832

nRF52840 DK

PCA10056

nrf52840dk

nrf52840dk/nrf52840

When built for a board target with the */ns variant, the sample is configured to compile and run as a non-secure application with Cortex-M Security Extensions enabled. Therefore, it automatically includes Trusted Firmware-M that prepares the required peripherals and secure services to be available for the application.

The sample also requires a smartphone or tablet running a compatible application. The Testing instructions refer to nRF Connect for Mobile, but you can also use other similar applications (for example, nRF Toolbox).

Note

If you build this application for Thingy:53, it enables additional features. See Application guide for Thingy:53 for details.

Overview

The sample implements two NSMS instances that result in two NSMS characteristics that describe the button status. Each characteristic has a name set in Characteristic User Description (CUD) that corresponds to the button whose status is shown.

Status related to Button 2 has configurable security settings. When CONFIG_BT_STATUS_SECURITY_ENABLED is configured, the status related to Button 2 has security enabled, thus it can be accessed only when bonded.

User interface

The user interface of the sample depends on the hardware platform you are using.

LED 1:

Blinks with a period of two seconds with the duty cycle set to 50% when the main loop is running and the device is advertising.

LED 2:

Lit when the development kit is connected.

Button 1:

Set Button 1 NSMS Status Characteristic to: “Pressed” or “Released”. Notify the client if notification is enabled.

Button 2 (the one hidden under the cover):

Set Button 2 NSMS Status Characteristic to: “Pressed” or “Released”. Notify the client if notification is enabled. By default, this service requires the connection to be secured to read or notify.

Configuration

See Configuring and building for information about how to permanently or temporarily change the configuration.

Configuration options

Check and configure the following configuration options for the sample:

CONFIG_BT_STATUS_SECURITY_ENABLED - Enable Bluetooth® LE security

This configuration enables Bluetooth® LE security implementation for Nordic Status Message instances. When you enable this option, one of the status messages will be displayed only when the connection is secure.

Building and running

This sample can be found under samples/bluetooth/peripheral_lbs in the nRF Connect SDK folder structure.

When built as firmware image for a board target with the */ns variant, the sample has Cortex-M Security Extensions (CMSE) enabled and separates the firmware between Non-Secure Processing Environment (NSPE) and Secure Processing Environment (SPE). Because of this, it automatically includes the Trusted Firmware-M (TF-M). To read more about CMSE, see Processing environments.

To build the sample, follow the instructions in Building an application for your preferred building environment. See also Programming an application for programming steps and Testing and optimization for general information about testing and debugging in the nRF Connect SDK.

Note

When building repository applications in the SDK repositories, building with sysbuild is enabled by default. If you work with out-of-tree freestanding applications, you need to manually pass the --sysbuild parameter to every build command or configure west to always use it.

Testing

After programming the sample to your dongle or development kit, test it by performing the following steps:

  1. Start the nRF Connect for Mobile application on your smartphone or tablet.

  2. Power on the development kit, or insert your dongle into the USB port.

  3. Connect to the device from the application. The device is advertising as Nordic_Status. The services of the connected device are shown.

  4. Find Nordic Status Message Service by its UUID listed in Nordic Status Message Service (NSMS).

  5. Read its Characteristic User Description to check which button it relates to.

  6. Read Nordic Status Message Service message characteristic to check the initial status - if no button was pressed, it should be “Unknown”.

  7. Enable notification for the characteristic found.

  8. Press the related button and observe the message change between “Pressed” and “Released”.

Note

Performing the same for Button 2 characteristic requires a secured connection.

Dependencies

This sample uses the following nRF Connect SDK libraries:

In addition, it uses the following Zephyr libraries:

  • include/zephyr/types.h

  • lib/libc/minimal/include/errno.h

  • include/sys/printk.h

  • include/sys/byteorder.h

  • GPIO Interface

  • API:

    • include/bluetooth/bluetooth.h

    • include/bluetooth/hci.h

    • include/bluetooth/conn.h

    • include/bluetooth/uuid.h

    • include/bluetooth/gatt.h

The sample also uses the following secure firmware component: