bleak.backends.p4android package
Submodules
bleak.backends.p4android.client module
BLE Client for python-for-android
- class bleak.backends.p4android.client.BleakClientP4Android(address_or_ble_device: BLEDevice | str, services: set[UUID] | None, **kwargs)[source]
Bases:
BaseBleakClient
A python-for-android Bleak Client
- Parameters:
address_or_ble_device – The Bluetooth address of the BLE peripheral to connect to or the
BLEDevice
object representing it.services – Optional set of services UUIDs to filter.
- property is_connected: bool
Check connection status between this client and the server.
- Returns:
Boolean representing connection status.
- property mtu_size: int
Gets the negotiated MTU.
- async pair(*args, **kwargs) None [source]
Pair with the peripheral.
You can use ConnectDevice method if you already know the MAC address of the device. Else you need to StartDiscovery, Trust, Pair and Connect in sequence.
- async read_gatt_char(characteristic: BleakGATTCharacteristic, **kwargs: Any) bytearray [source]
Perform read operation on the specified GATT characteristic.
- Parameters:
characteristic (BleakGATTCharacteristic) – The characteristic to read from.
- Returns:
(bytearray) The read data.
- async read_gatt_descriptor(descriptor: BleakGATTDescriptor, **kwargs: Any) bytearray [source]
Perform read operation on the specified GATT descriptor.
- Parameters:
descriptor – The descriptor to read from.
- Returns:
The read data.
- async start_notify(characteristic: BleakGATTCharacteristic, callback: Callable[[bytearray], None], **kwargs) None [source]
Activate notifications/indications on a characteristic.
- async stop_notify(characteristic: BleakGATTCharacteristic) None [source]
Deactivate notification/indication on a specified characteristic.
- Parameters:
characteristic (BleakGATTCharacteristic) – The characteristic to deactivate notification/indication on,.
- async write_gatt_char(characteristic: BleakGATTCharacteristic, data: bytearray, response: bool) None [source]
Perform a write operation on the specified GATT characteristic.
- Parameters:
characteristic – The characteristic to write to.
data – The data to send.
response – If write-with-response operation should be done.
- async write_gatt_descriptor(desc_specifier: BleakGATTDescriptor | str | UUID, data: bytearray) None [source]
Perform a write operation on the specified GATT descriptor.
- Parameters:
desc_specifier (BleakGATTDescriptor, str or UUID) – The descriptor to write to, specified by either UUID or directly by the BleakGATTDescriptor object representing it.
data (bytes or bytearray) – The data to send.
bleak.backends.p4android.defs module
bleak.backends.p4android.scanner module
- class bleak.backends.p4android.scanner.BleakScannerP4Android(detection_callback: Callable[[BLEDevice, AdvertisementData], Coroutine[Any, Any, None] | None] | None, service_uuids: list[str] | None, scanning_mode: Literal['active', 'passive'], **kwargs)[source]
Bases:
BaseBleakScanner
The python-for-android Bleak BLE Scanner.
- Parameters:
detection_callback – Optional function that will be called each time a device is discovered or advertising data has changed.
service_uuids – Optional list of service UUIDs to filter on. Only advertisements containing this advertising data will be received. Specifying this also enables scanning while the screen is off on Android.
scanning_mode – Set to
"passive"
to avoid the"active"
scanning mode.