Bluetooth: Peripheral power profiling

The Peripheral power profiling sample can be used to measure power consumption when Bluetooth® Low Energy stack is used for communication. You can measure power consumption during advertising and data transmission. For this purpose, the sample uses the vendor-specific service and demonstrates advertising in a connectable and non-connectable mode.

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

nRF52833 DK

PCA10100

nrf52833dk

nrf52833dk/nrf52833

Note

If you use nRF5340 DK, the additional configuration of the network core will be taken from the child_image directory. For more details, see Image-specific variables.

Optionally, you can use the Power Profiler Kit II (PPK2) for power profiling and optimizing your configuration. You can use also your proprietary solution for measuring the power consumption.

Overview

This sample uses Zephyr’s power management mechanism to implement the low power mode and the system off mode.

Low power mode

The application enters CPU sleep mode when the kernel is in idle state, which means it has nothing to schedule. Wake-up events are interrupts triggered by one of the SoC peripheral modules, such as RTC or SystemTick.

System off mode

This is the deepest power saving mode the system can enter. In this mode, all core functionalities are powered down, and most peripherals are non-functional or non-responsive. The only mechanisms that are functional in this mode are reset and wake-up.

To wake up your development kit from the system off state, you have the following options:

  • Press the RESET button on your development kit.

  • Press Button 1 to start connectable advertising.

  • Press Button 2 to start non-connectable advertising.

  • Approach the NFC field of the development kit antenna.

    The development kit starts advertising automatically. If you use a mobile phone, it connects and bonds with your device.

When you establish a connection with the central device, you can test different connection parameters to optimize the power consumption. When the central device enables the notification characteristic, your development kit starts sending notifications until the timeout expires. The device disconnects from the central and enters the system off mode. You can press a button or bring your phone close to the NFC antenna to wake up the device and continue testing.

For more details about power saving, refer to the Power optimization section.

Power profiling

You can use the Power Profiler Kit II (PPK2) for power profiling with this sample. See the device documentation for details about preparing your development kit for measurements.

The following parameters have an impact on power consumption:

  • Connection interval

  • Advertising duration

  • Latency

  • Notifications data size and interval

You can configure these parameters with the Kconfig options. If your central device is the Bluetooth Low Energy app from nRF Connect for Desktop, you can use it to change the current connection parameters.

Example measurements:

Power consumption measurement

Connection interval 150 ms, the signal peaks on the chart indicate connection event every 150 milliseconds interval.

Non-connectable advertising measurement

Non-connectable advertising setup: Minimal interval - 1000 ms, maximum interval - 1200 ms.

Service UUID

This sample implements the vendor-specific service.

The 128-bit service UUID is 00001630-1212-EFDE-1523-785FEABCD123.

Characteristics

The 128-bit characteristic UUID is 00001630-1212-EFDE-1524-785FEABCD123. This characteristic value can be read or sent by the notification mechanism. The value is an array filled with zeroes. You can configure the length of data using the CONFIG_BT_POWER_PROFILING_DATA_LENGTH Kconfig option.

This characteristic has a CCC descriptor associated with it.

User interface

The sample uses buttons and LEDs to provide a simple user interface.

LED 1:

Blinks, toggling on/off every second, when the main loop is running and the device is advertising. Off when the device is in system off state.

LED 2:

Lit when an NFC field is detected.

Button 1:

Starts connectable advertising and wakes up the SoC from the system off state.

Button 2:

Starts non-connectable advertising and wakes up the SoC from the system off state.

Note

When you use buttons to wake up the SoC from the system off state, the button state is read in the main thread after booting the Zephyr kernel. This causes a delay between the SoC wake up and button press processing. If you want to start advertising on system start, you must keep pressing the button until you see a log message confirming the advertising start on the terminal.

Configuration

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

The Peripheral Power Profiling sample allows configuring some of its settings using Kconfig. You can set different options to monitor the power consumption of your development kit. You can modify the following options (available in the Kconfig file at samples/bluetooth/peripheral_power_profiling):

CONFIG_BT_POWER_PROFILING_DATA_LENGTH - Notification data length

Sets the length of the data sent through notification mechanism.

CONFIG_BT_POWER_PROFILING_NOTIFICATION_INTERVAL - Notification interval

Sets the notification send interval in milliseconds. Notification data is sent on every interval expiration. Notifications are started when the central device enables it by writing to the characteristic CCC descriptor.

CONFIG_BT_POWER_PROFILING_NOTIFICATION_TIMEOUT - Notification timeout

Sets the notification timeout in milliseconds. When this timeout fires the device will stop sending notifications. After that, the sample disconnects and enters the system off mode.

CONFIG_BT_POWER_PROFILING_CONNECTABLE_ADV_DURATION - Connectable advertising duration

Sets the connectable advertising duration in N*10 milliseconds unit. If the connection is not established during advertising, the device enters the system off state.

CONFIG_BT_POWER_PROFILING_NON_CONNECTABLE_ADV_DURATION - Non-connectable advertising duration

Sets the non-connectable advertising duration in N*10 milliseconds unit. When the advertising ends, the device enters the system off state if there is no outgoing connection.

CONFIG_BT_POWER_PROFILING_NFC_ADV_DURATION - Advertising duration when the NFC field is detected

Sets the advertising duration when the NFC field is detected in N*10 milliseconds unit. If the connection was not established during advertising, the device enters the system off state.

CONFIG_BT_POWER_PROFILING_CONNECTABLE_ADV_INTERVAL_MIN - Connectable advertising minimum interval

Sets the connectable advertising minimum interval in 0.625 milliseconds unit.

CONFIG_BT_POWER_PROFILING_CONNECTABLE_ADV_INTERVAL_MAX - Connectable advertising maximum interval

Sets the connectable advertising maximum interval in 0.625 milliseconds unit.

CONFIG_BT_POWER_PROFILING_NON_CONNECTABLE_ADV_INTERVAL_MIN - Non-connectable advertising minimum interval

Sets the non-connectable advertising minimum interval in 0.625 milliseconds unit.

CONFIG_BT_POWER_PROFILING_NON_CONNECTABLE_ADV_INTERVAL_MAX - Non-connectable advertising maximum interval

Sets the non-connectable advertising maximum interval in 0.625 milliseconds unit.

Building and running

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

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

This testing procedure assumes that you are using nRF Connect for Mobile or nRF Connect for Desktop. After programming the sample to your development kit, you need another device for measuring the power consumption. Power Profiler Kit II (PPK2) is the recommended device for the measurement.

Testing with nRF Connect for Desktop and Power Profiler Kit II (PPK2)

  1. Set up Power Profiler Kit II (PPK2) and prepare your development kit for current measurement.

  2. Run the Power Profiler app from nRF Connect for Desktop.

  3. Open a serial port connection to the kit using a terminal emulator that supports VT100/ANSI escape characters (for example, nRF Connect Serial Terminal). See Testing and optimization for the required settings and steps.

  4. Reset your development kit.

  5. Observe that the sample starts.

    The device enters the system off state after five seconds. Observe a significant power consumption drop when the device enters the system off state.

  6. Use the device buttons to wake up your device and start advertising or approach the NFC field of the kit antenna.

    You can measure power consumption during advertising with different intervals. Use the Kconfig options to change the interval or other parameters.

  7. Connect to the device through the Bluetooth Low Energy app.

    Observe the power consumption on the current connection interval.

  8. Set different connection parameters:

    1. Click Settings for the connected device in the Bluetooth Low Energy app.

    2. Select Update connection.

    3. Set new connection parameters.

    4. Click Update to negotiate new parameters with your device.

  9. Observe the power consumption with the new connection parameters.

  10. In 000016301212EFDE1523785FEABCD123, click Notify for the characteristic.

  11. Observe that notifications are received.

    Monitor the power consumption during notification sending.

  12. After the timeout set by the CONFIG_BT_POWER_PROFILING_NOTIFICATION_TIMEOUT option, your development kit disconnects and enters the system off mode.

  13. Repeat this test using different wake-up methods and different parameters, and monitor the power consumption for your new setup.

Dependencies

This sample uses the following nRF Connect SDK libraries:

It uses the Type 2 Tag library from sdk-nrfxlib:

In addition, it uses the following Zephyr libraries:

  • include/zephyr/sys/kernel.h

  • include/zephyr/sys/atomic.h

  • Settings

  • API:

    • include/zephyr/bluetooth/bluetooth.h

    • include/zephyr/bluetooth/conn.h

    • include/zephyr/bluetooth/uuid.h

    • include/zephyr/bluetooth/gatt.h

  • Power Management:

    • include/zephyr/pm/pm.h

    • include/zephyr/pm/policy.h