Back to Serial Studio

BLE Battery Level Monitor

examples/BLE Battery/README.md

4.0.12.3 KB
Original Source

BLE Battery Level Monitor

This Serial Studio project visualizes the battery level from BLE devices (like iPhones) over Bluetooth Low Energy.

What it does

  • Connects to BLE devices using Serial Studio's native BLE support.
  • Reads the Battery Level characteristic (0x2A19).
  • Shows the battery percentage (0 to 100) on a live gauge and a plot.
  • Parses raw binary data with no delimiters or framing.

The project includes a control loop that selects the service and characteristic for you on connect.

BLE service

Bluetooth Low Energy exposes battery level through the Battery Level characteristic, 0x2A19 (uint8, 0 to 100):

  • Service UUID: 0x180A. This project is wired to the Device Information Service, where the test device (an iPhone) advertises its battery characteristic. Devices that follow the standard expose it under the Battery Service, 0x180F instead; change the service UUID in the control loop to match your hardware.
  • Characteristic UUID: 0x2A19. Battery Level (uint8, 0 to 100).

The bundled control loop picks the configured service, selects its first characteristic, subscribes to notifications (falling back to polling), and decodes the raw value with a 1-byte binary read.

Project configuration

SettingValue
Data ConversionBinary (Direct)
Frame DetectionNo Delimiters
ChecksumNone
Dataset Index1
Value Range0 to 100
WidgetGauge, Plot
Units%
TitleBattery Level

Parser:

js
/**
 * @brief Converts a byte-like iterable into an array of numbers.
 *
 * @param frame An iterable containing byte values (0–255).
 * @return Array of numeric byte values.
 */
function parse(frame) {
    return Array.from(frame);
}

Setup

  1. Open Serial Studio and load BLE Battery Level.ssproj.
  2. Select Bluetooth LE as the input source.
  3. Pick your BLE device (for example your iPhone) and click Connect.
  4. The control loop selects the service (0x180A as shipped) and its battery characteristic (0x2A19) automatically.
  5. Watch the gauge update in real time.