Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Multiple Device Troubleshooting Section #755

Merged
merged 3 commits into from
Feb 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions docs/troubleshooting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,63 @@ Windows Command Prompt::
Then run your Python script in the same terminal.


-----------------------------------------------
Connecting to multiple devices at the same time
-----------------------------------------------

If you're having difficulty connecting to multiple devices, try to do a scan first and
pass the returned ``BLEDevice`` objects to ``BleakClient`` calls.

Python::

import asyncio
from typing import Sequence

from bleak import BleakClient, BleakScanner
from bleak.backends.device import BLEDevice


async def find_all_devices_services()
scanner = BleakScanner()
devices: Sequence[BLEDevice] = scanner.discover(timeout=5.0)
for d in devices:
async with BleakClient(d) as client:
print(await client.get_services())


asyncio.run(find_all_devices_services())


-----------------------------------------
Pass more parameters to a notify callback
-----------------------------------------

If you need a way to pass more parameters to the notify callback, please use
``functools.partial`` to pass in more arguments.

Issue #759 might fix this in the future.

Python::

from functools import partial

from bleak import BleakClient


def my_notification_callback_with_client_input(
client: BleakClient, sender: int, data: bytearray
):
"""Notification callback with client awareness"""
print(
f"Notification from device with address {client.address} and characteristic with handle {client.services.get_characteristic(sender)}. Data: {data}"
)

# [...]

await client.start_notify(
char_specifier, partial(my_notification_callback_with_client_input, client)
)

-------------------------
Capture Bluetooth Traffic
-------------------------
Expand Down