From 2240de0085f35d32e7239626753a3121e8d030d1 Mon Sep 17 00:00:00 2001 From: Shin'ichiro Kawasaki Date: Sat, 25 Jan 2020 18:48:10 +0900 Subject: [PATCH] BLESession.matches: Check service adtypes both 16 bits and 128 bits LEGO Boost communicates with a Scratch extension through Scratch-link. It was reported that bluepy-scratch-link fails to connect to LEGO Boost. LEGO Boost advertises adtype 0x7 "Complete List of 128-bit Service Class UUIDs". However, bluepy-scratch-link checks only adtype 0x3 "Complete List of 16-bit Service Class UUIDs" which is valid for micro:bit. To allow bluepy-scratch-link, check both adtypes 0x7 and 0x3. Introduce constants to note those two adtype values. Signed-off-by: Shin'ichiro Kawasaki --- scratch_link.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/scratch_link.py b/scratch_link.py index 372d7b3..67a45cd 100755 --- a/scratch_link.py +++ b/scratch_link.py @@ -109,6 +109,9 @@ class BLESession(Session): CONNECTED = 3 DONE = 4 + ADTYPE_COMP_16B = 0x3 + ADTYPE_COMP_128B = 0x7 + class BLEThread(threading.Thread): """ Separated thread to control notifications to Scratch. @@ -208,9 +211,13 @@ class BLESession(Session): logger.debug(f"sevice to check: {s}") given_uuid = s logger.debug(f"given: {given_uuid}") - service_class_uuid = dev.getValueText(0x3) + service_class_uuid = dev.getValueText(self.ADTYPE_COMP_128B) + logger.debug(f"adtype 128b: {service_class_uuid}") if not service_class_uuid: - continue + service_class_uuid = dev.getValueText(self.ADTYPE_COMP_16B) + logger.debug(f"adtype 16b: {service_class_uuid}") + if not service_class_uuid: + continue dev_uuid = UUID(service_class_uuid) logger.debug(f"dev: {dev_uuid}") logger.debug(given_uuid == dev_uuid)