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 |
---|---|---|---|
PCA20053 |
|
||
PCA10156 |
|
||
PCA10175 |
|
||
PCA10095 |
|
||
PCA10040 |
|
||
PCA10056 |
|
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.
Status related to Button 1 has configurable security settings. When CONFIG_BT_STATUS_SECURITY_ENABLED is configured, the status related to Button 1 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.
- LED 0:
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 1:
Lit when the development kit is connected.
- Button 0:
Set Button 0 NSMS Status Characteristic to: “Pressed” or “Released”. Notify the client if notification is enabled.
- Button 1 (the one hidden under the cover):
Set Button 1 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.
- RGB LED:
The RGB LED channels are used independently to display the following information:
Red - If the main loop is running (that is, the device is advertising). 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.
Green - If the device is connected.
For example, if Thingy:53 is connected over Bluetooth, the LED color toggles between green and yellow. The green LED channel is kept on, and the red LED channel is blinking.
- 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:
Start the nRF Connect for Mobile application on your smartphone or tablet.
Power on the development kit, or insert your dongle into the USB port.
Connect to the device from the application. The device is advertising as
Nordic_Status
. The services of the connected device are shown.Find Nordic Status Message Service by its UUID listed in Nordic Status Message Service (NSMS).
Read its Characteristic User Description to check which button it relates to.
Read Nordic Status Message Service message characteristic to check the initial status - if no button was pressed, it should be “Unknown”.
Enable notification for the characteristic found.
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.
Note
Performing the same for Button 1 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
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: