Bluetooth: Central DFU SMP

The Central DFU SMP 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.

Overview

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

To send an echo command, press Button 1 on the board. The string that is sent contains a number that is automatically incremented. This way, you can easily verify if the correct response is received. The response is decoded and displayed using the TinyCBOR library (which is part of Zephyr).

Requirements

The sample supports the following development kits:

Hardware platforms

PCA

Board name

Build target

nRF5340 DK

PCA10095

nrf5340dk_nrf5340

nrf5340dk_nrf5340_cpuapp

nrf5340dk_nrf5340_cpuappns

nRF52840 DK

PCA10056

nrf52840dk_nrf52840

nrf52840dk_nrf52840

nRF52840 DK (emulating nRF52811)

PCA10056

nrf52840dk_nrf52811

nrf52840dk_nrf52811

nRF52833 DK

PCA10010

nrf52833dk_nrf52833

nrf52833dk_nrf52833

nRF52833 DK (emulating nRF52820)

PCA10100

nrf52833dk_nrf52820

nrf52833dk_nrf52820

nRF52 DK

PCA10040

nrf52dk_nrf52832

nrf52dk_nrf52832

nRF52 DK (emulating nRF52810)

PCA10040

nrf52dk_nrf52810

nrf52dk_nrf52810

The sample also requires a device running MCUmgr with transport protocol over Bluetooth Low Energy, for example, another board running the SMP Server Sample.

User interface

Button 1:

Send an echo command.

Building and running

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

See Building and programming a sample application for information about how to build and program the application.

Testing

After programming the sample to your board, test it by performing the following steps:

  1. Connect the board to the computer using a USB cable. The board 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, PuTTY). See How to connect with PuTTY for the required settings.

  3. Reset the board.

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

  5. Program the SMP Server Sample to another board. See the documentation for that sample for more information.

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

  7. Press Button 1 on the Client board. 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 board. Observe that the boards automatically reconnect and that it is again possible to send data between the two boards.

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

  • Bluetooth:

    • 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: