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

Build target

nRF5340 DK

PCA10095

nrf5340dk_nrf5340

nrf5340dk_nrf5340_cpuapp_ns nrf5340dk_nrf5340_cpuapp

nRF52 DK

PCA10040

nrf52dk_nrf52832

nrf52dk_nrf52832

nRF52840 DK

PCA10056

nrf52840dk_nrf52840

nrf52840dk_nrf52840

nRF52833 DK

PCA10100

nrf52833dk_nrf52833

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 when main loop is running with a period of two seconds, duty cycle 50%.

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

  • CONFIG_BT_POWER_PROFILING_DATA_LENGTH - sets notification data length.

  • CONFIG_BT_POWER_PROFILING_NOTIFICATION_INTERVAL - sets notification sending interval in milliseconds.

    Notifications are started when the central device enables it by writing to the characteristic CCC descriptor.

  • CONFIG_BT_POWER_PROFILING_NOTIFICATION_TIMEOUT - sets notification timeout.

    Notifications are sent until this timeout is fired. After that, the sample disconnects and enters the system off mode.

  • CONFIG_BT_POWER_PROFILING_CONNECTABLE_ADV_DURATION - sets connectable advertising duration in (N * 10) milliseconds.

    If the connection is not established during advertising, the device enters the system off state.

  • CONFIG_BT_POWER_PROFILING_NON_CONNECTABLE_ADV_DURATION - sets non-connectable advertising duration in (N * 10) milliseconds.

    When the advertising ends, the device enters the system off state if there is no outgoing connection.

  • CONFIG_BT_POWER_PROFILING_NFC_ADV_DURATION - sets advertising duration after the NFC field detection in (N * 10) milliseconds.

    If the connection was not established during advertising, the device enters the system off state.

  • CONFIG_BT_POWER_PROFILING_CONNECTABLE_ADV_INTERVAL_MIN - sets connectable advertising minimum interval in (N * 0.625) milliseconds.

  • CONFIG_BT_POWER_PROFILING_CONNECTABLE_ADV_INTERVAL_MAX - sets connectable advertising maximum interval in (N * 0.625) milliseconds.

  • CONFIG_BT_POWER_PROFILING_NON_CONNECTABLE_ADV_INTERVAL_MIN - sets non-connectable advertising minimum interval in (N * 0.625) milliseconds.

  • CONFIG_BT_POWER_PROFILING_NON_CONNECTABLE_ADV_INTERVAL_MAX - sets non-connectable advertising maximum interval in (N * 0.625) milliseconds.

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 with Visual Studio Code, follow the steps listed on the How to build an application page in the nRF Connect for VS Code extension documentation. See Building and programming an application for other building and programming scenarios and Testing and debugging an application for general information about testing and debugging in the nRF Connect SDK.

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. Connect to the kit with a terminal emulator that supports VT100/ANSI escape characters (for example, PuTTY). See How to connect with PuTTY for the required settings.

  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

  • Bluetooth APIs:

    • 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