BLE Battery service. More...
|BatteryService (BLE &_ble, uint8_t level=100)|
|Instantiate a battery service. More...|
|void||updateBatteryLevel (uint8_t newLevel)|
|Update the battery charge level that the service exposes. More...|
|Reference to the underlying BLE instance that this object is attached to. More...|
|The current battery level represented as an integer from 0% to 100%. More...|
|ReadOnlyGattCharacteristic< uint8_t >||batteryLevelCharacteristic|
|The GATT characteristic, which exposes the charge level. More...|
BLE Battery service.
The battery service exposes the charge level of the battery of the device. This information is exposed as a percentage from 0% to 100%; a value of 0% represents a fully discharged battery, and a value of 100% represents a fully charged battery.
Clients can read the current charge level and subscribe to server initiated updates of the charge level. The server delivers these updates to the subscribed client in a notification packet.
The subscription mechanism is useful to save power; it avoids unecessary data traffic between the client and the server, which may be induced by polling the battery level characteristic value.
When this class is instantiated, it adds a battery service in the GattServer.
The application code can use the function updateBatteryLevel() to update the charge level that the service exposes and to notify the subscribed client that the value changed.
Instantiate a battery service.
The construction of a BatteryService adds a GATT battery service in
_ble GattServer and sets the initial charge level of the battery to
|[in]||_ble||BLE device which will host the battery service.|
|[in]||level||Initial charge level of the battery. It is a percentage where 0% means that the battery is fully discharged and 100% means that the battery is fully charged.|
Update the battery charge level that the service exposes.
The server sends a notification of the new value to clients that have subscribed to the battery level characteristic updates, and clients reading the charge level after the update obtain the updated value.
|newLevel||Charge level of the battery. It is a percentage of the remaining charge between 0% and 100%.|