Skip to content

Commit

Permalink
Merge pull request #706 from mkoderer/all_uuids
Browse files Browse the repository at this point in the history
Use predefined service uuids
  • Loading branch information
dlech authored Dec 30, 2021
2 parents b644ae2 + 7d92ff6 commit 156e8af
Showing 1 changed file with 11 additions and 0 deletions.
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))
service_uuids.extend(uuid128_dict.keys())
scanner = BleakScanner(service_uuids=service_uuids)
scanner.register_detection_callback(simple_callback)

Expand Down

0 comments on commit 156e8af

Please sign in to comment.