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

Use predefined service uuids #706

Merged
merged 1 commit into from
Dec 30, 2021
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
11 changes: 11 additions & 0 deletions examples/detection_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from bleak import BleakScanner
from bleak.backends.device import BLEDevice
from bleak.backends.scanner import AdvertisementData
from bleak.uuids import uuid16_dict, uuid128_dict

logger = logging.getLogger(__name__)

Expand All @@ -24,6 +25,16 @@ def simple_callback(device: BLEDevice, advertisement_data: AdvertisementData):


async def main(service_uuids):
if len(service_uuids) > 0 and service_uuids[0] == "all":
# in Macos Monterey the service_uuids need to be specified.
# Instead of discovering valid uuids with a different tool
# you can add `all` as argument and it will add all defined
# uuid's from bleak/uuids as a starting point.
logger.info("Adding all known service uuids")
service_uuids.pop(0)
for item in uuid16_dict:
service_uuids.append("{0:04x}".format(item))
mkoderer marked this conversation as resolved.
Show resolved Hide resolved
service_uuids.extend(uuid128_dict.keys())
scanner = BleakScanner(service_uuids=service_uuids)
scanner.register_detection_callback(simple_callback)

Expand Down