Import
Classes
Functions
Central Class
TheCentral class provides BLE scanning and connection initiation.
Central(loop=None)
Create a BLE central instance.
scan(scan_time=5.0, name=None, address=None)
Scan for nearby BLE devices.
Returns:
list - List of discovered BLE devices
connect(address)
Connect to a BLE device by address.
Returns:
Client - Connected BLE client
pair(address)
Pair with a BLE device.
Client Class
TheClient 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.
BleakGATTServiceCollection - Collection of discovered services
has_characteristic(uuid)
Check if a characteristic exists on the device.
Returns:
bool - True if characteristic exists
read_gatt_char(char_specifier)
Read a characteristic value.
Returns:
bytearray - Characteristic value
write_gatt_char(char_specifier, data)
Write a value to a characteristic.
start_notify(char_specifier, callback=noop_handler, max_messages=None, timeout=None)
Subscribe to characteristic notifications.
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 (
withstatement) for automatic cleanup - Notification callbacks receive
(handle, data)parameters - Use
max_messagesandtimeouttogether 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

