Skip to main content
Communicate with Bluetooth Low Energy (BLE) devices for scanning, connecting, reading/writing characteristics, and subscribing to notifications.

Import

Classes

Functions

Central Class

The Central class provides BLE scanning and connection initiation.

Central(loop=None)

Create a BLE central instance.
Parameters:

scan(scan_time=5.0, name=None, address=None)

Scan for nearby BLE devices.
Parameters: Returns: list - List of discovered BLE devices

connect(address)

Connect to a BLE device by address.
Parameters: Returns: Client - Connected BLE client

pair(address)

Pair with a BLE device.

Client Class

The Client class provides GATT operations on a connected BLE device.

Creating a Client

connect()

Establish connection to the BLE device.

disconnect()

Disconnect from the BLE device.

pair()

Pair with the connected device.

get_services()

Discover and retrieve all GATT services.
Returns: BleakGATTServiceCollection - Collection of discovered services

has_characteristic(uuid)

Check if a characteristic exists on the device.
Parameters: Returns: bool - True if characteristic exists

read_gatt_char(char_specifier)

Read a characteristic value.
Parameters: Returns: bytearray - Characteristic value

write_gatt_char(char_specifier, data)

Write a value to a characteristic.
Parameters:

start_notify(char_specifier, callback=noop_handler, max_messages=None, timeout=None)

Subscribe to characteristic notifications.
Parameters: Returns: tuple[bool, list] - (timed_out, messages) where timed_out is True if timeout occurred

stop_notify(char_specifier)

Unsubscribe from characteristic notifications.

sleep(timeout)

Sleep for a duration (async-safe).

Helper Functions

noop_handler(handle, data)

A no-op notification handler.

notify_handler(evt, messages, callback, max_messages, handle, data)

Internal notification handler that collects messages and signals completion.

waiter(event, timeout)

Async wait helper for notification events.

Examples

Scan for Devices

Connect and Read Characteristic

Subscribe to Notifications

Write Command and Read Response

Device Firmware Version Check

BLE Production Test

Hardware Requirements

Dependencies

The BLE module uses Bleak as the underlying BLE library, which provides cross-platform BLE support.

Notes

  • BLE operations are synchronous wrappers around async Bleak operations
  • The Client class supports context manager (with statement) for automatic cleanup
  • Notification callbacks receive (handle, data) parameters
  • Use max_messages and timeout together to control notification collection
  • MAC addresses are typically in format AA:BB:CC:DD:EE:FF
  • Some BLE operations may require pairing before they work
  • Signal strength (RSSI) is available on scanned device objects