Skip to content

Commit

Permalink
Use predefined service uuids
Browse files Browse the repository at this point in the history
On macos the service_uuids need to be filled. Main issue for
beginners is to retrieve some valid uuids. Instead of using an
external tool like nRF we could use predefined ones in bleak/uuids.

Implementation works with 128bit and 16bit UUIDs.

Related-to hbldh#635

Signed-off-by: Marc Koderer <marc@koderer.com>
  • Loading branch information
mkoderer committed Dec 30, 2021
1 parent b644ae2 commit a332df5
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 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,13 @@ def simple_callback(device: BLEDevice, advertisement_data: AdvertisementData):


async def main(service_uuids):
if service_uuids[0] == "all":
logger.info("Adding all known service_uuids")
service_uuids.pop(0)
for item in uuid16_dict:
service_uuids.append("{0:04x}".format(item))
for item in uuid128_dict:
service_uuids.append(item)
scanner = BleakScanner(service_uuids=service_uuids)
scanner.register_detection_callback(simple_callback)

Expand Down

0 comments on commit a332df5

Please sign in to comment.