Battery Service (BAS)

This module implements the Battery Service with the Battery Level characteristic.

Overview

During initialization, the module adds the Battery Service and Battery Level characteristic to the Bluetooth LE stack database. Optionally, it can also add a Report Reference descriptor to the Battery Level characteristic (used when including the Battery Service in the HID service).

If specified, the module will support notification of the Battery Level characteristic through the ble_bas_battery_level_update() function. If an event handler is supplied by the application, the Battery Service will generate Battery Service events to the application.

Configuration

Set the CONFIG_BLE_BAS Kconfig option to enable the service.

Initialization

The service instance is declared using the BLE_BAS_DEF macro, specifying the name of the instance. The service is initialized by calling the ble_bas_init() function. See the ble_bas_config struct for configuration details, in addition to the BAS specification.

Usage

Events from the service are forwarded through the event handler specified during initialization. For a full list of events see the ble_bas_evt_type enum.

The application can update the battery level by calling the ble_bas_battery_level_update() function. If the peer has enabled notifications (CCCD), the function will automatically send a notification.

Dependencies

This service has the following Bare Metal dependencies:

API documentation

Header file: include/bm/bluetooth/services/ble_bas.h
Source files: subsys/bluetooth/services/ble_bas/

Battery Service API reference