Bluetooth: Central SMP Client

The Central Simple Management Protocol (SMP) Client sample demonstrates how to use the GATT DFU SMP Service Client to connect to an SMP Server and send a simple echo command. The response, which is received as CBOR-encoded data, is decoded and printed.

Note

This sample does not provide the means to program a device using DFU. It demonstrates the communication between SMP Client and SMP Server.

Requirements

The sample supports the following development kits:

Hardware platforms

PCA

Board name

Board target

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 device running mcumgr with transport protocol over Bluetooth® Low Energy, for example, another development kit running the SMP server.

Note

This sample does not program the device using DFU.

Overview

After connecting, the sample starts MTU size negotiation, discovers the GATT database of the server, and configures the DFU SMP Client. When the configuration is complete, the sample is ready to send SMP commands.

To send an echo command, press Button 1 on the development kit. The sent string contains a number that is automatically incremented. This way, you can verify if the correct response is received. The response is decoded using the zcbor library and displayed after that.

User interface

Button 1:

Send an echo command.

Building and running

This sample can be found under samples/bluetooth/central_smp_client 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 Configuring and 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 development kit, complete the following steps to test it:

  1. Connect the kit to the computer using a USB cable. The kit is assigned a COM port (Windows) or ttyACM device (Linux), which is visible in the Device Manager.

  2. Connect to the kit with a terminal emulator (for example, nRF Connect Serial Terminal). See Testing and optimization for the required settings and steps.

  3. Reset the kit.

  4. Observe that the text “Starting Bluetooth Central SMP Client example” is printed on the COM listener running on the computer and the device starts scanning for Peripherals with SMP.

  5. Program the SMP server to another development kit. See the documentation for that sample only in the section “Building the sample application”. When you have built the SMP server, call the following command to program it to the development kit:

    west flash
    
  6. Observe that the kits connect. When service discovery is completed, the event logs are printed on the Central’s terminal. If you connect to the Server with a terminal emulator, you can observe that it prints “connected”.

  7. Press Button 1 on the Client. Observe messages similar to the following:

    Echo test: 1
    Echo response part received, size: 28.
    Total response received - decoding
    {_"r": "Echo message: 1"}
    
  8. Disconnect the devices by, for example, pressing the Reset button on the Central. Observe that the kits automatically reconnect and that it is again possible to send data between the two kits.

Dependencies

This sample uses the following nRF Connect SDK libraries:

It uses the following Zephyr libraries:

  • include/zephyr/types.h

  • boards/arm/nrf*/board.h

  • Kernel Services:

    • include/kernel.h

  • API:

    • include/bluetooth/bluetooth.h

    • include/bluetooth/gatt.h

    • include/bluetooth/hci.h

    • include/bluetooth/uuid.h

In addition, it uses the following external library that is distributed with Zephyr:

The sample also uses the following secure firmware component: