Adding Bluetooth LE services to Matter application

You can integrate a variety of Bluetooth® Low Energy (LE) services to your Matter-enabled application. The Bluetooth LE services can run next to the Matter stack and the Bluetooth LE Arbiter class can advertise them in a specific prioritization order.

You can add a Bluetooth LE service in one of the following ways:

  • Taking advantage of Bluetooth services and their related samples in the nRF Connect SDK. You can use the library functions for configuring services and follow the available samples to learn how to integrate the services into your application.

  • Using Bluetooth SIG’s Assigned Numbers documentation with predefined characteristics to create your custom implementation.

  • Writing the custom Bluetooth LE service from scratch.

This guide describes the first case and uses Nordic UART Service (NUS) as an example.

Advertising arbiter for Bluetooth LE services

The Bluetooth LE Arbiter is a class implemented in the Zephyr platform within the Matter SDK. It enables easier coexistence of application components that want to advertise their Bluetooth LE services, for example during Device discovery.

When several application services are active, they can define a request to the Arbiter with the desired priority. If the service with the highest priority stops advertising, the Arbiter automatically selects the next service in the queue. If the service that requests advertising has a higher priority than the service that is running when the request is submitted, the advertising is restarted using parameters defined in the new request.

In the Matter implementation in the nRF Connect SDK, the following services are configured by default for all Matter applications:

  • Commissioning for Matter (priority 0)

  • DFU over Bluetooth LE (priority uint8 max)

Lower number has a higher priority. If you implement a custom Bluetooth LE service, you need to prioritize it with the Bluetooth LE Arbiter.

For more information about what the class offers, see the Bluetooth LE Arbiter’s header file.

Adding support for a Bluetooth LE service

To add support for a Bluetooth LE service implemented in the nRF Connect SDK, complete the following steps:

  1. Check the documentation of the Bluetooth service for its characteristics and functions.

  2. Add the application code that instantiates and fills the Bluetooth LE Arbiter’s Request structure, including its priority field:

    struct Request : public sys_snode_t
    {
       uint8_t priority;                     ///< Advertising request priority. Lower value means higher priority
       uint32_t options;                     ///< Advertising options: bitmask of BT_LE_ADV_OPT_XXX constants from Zephyr
       uint16_t minInterval;                 ///< Minimum advertising interval in 0.625 ms units
       uint16_t maxInterval;                 ///< Maximum advertising interval in 0.625 ms units
       Span<const bt_data> advertisingData;  ///< Advertising data fields
       Span<const bt_data> scanResponseData; ///< Scan response data fields
       OnAdvertisingStarted onStarted;       ///< (Optional) Callback invoked when the request becomes top-priority.
       OnAdvertisingStopped onStopped;       ///< (Optional) Callback invoked when the request stops being top-priority.
    };
    
  3. Add the application code that calls the Bluetooth LE Arbiter’s InsertRequest function, with the reference to the Request structure, when the service needs to be advertised:

    CHIP_ERROR InsertRequest(Request & request);
    

    This adds the service to the Arbiter queue.