fix(gateway): replace UUID filter with manufacturer data preamble filter
This commit is contained in:
@@ -113,29 +113,25 @@ class Gateway:
|
|||||||
log.info(f"Published to {topic} : {payload}")
|
log.info(f"Published to {topic} : {payload}")
|
||||||
|
|
||||||
def on_device_found(self, device, adv_data):
|
def on_device_found(self, device, adv_data):
|
||||||
"""BLE scan callback — filters on Thingy:52 service UUID and decodes payload."""
|
"""BLE scan callback — filters on Adrien's preamble (0xffff) in manufacturer data."""
|
||||||
uuids = [str(u).lower() for u in adv_data.service_uuids]
|
if not adv_data.manufacturer_data:
|
||||||
if self.service_uuid.lower() not in uuids:
|
return
|
||||||
return
|
|
||||||
|
|
||||||
# Try manufacturer data first, then service data
|
raw = list(adv_data.manufacturer_data.values())[0]
|
||||||
raw = None
|
|
||||||
if adv_data.manufacturer_data:
|
|
||||||
raw = list(adv_data.manufacturer_data.values())[0]
|
|
||||||
elif adv_data.service_data:
|
|
||||||
raw = list(adv_data.service_data.values())[0]
|
|
||||||
|
|
||||||
if raw is None:
|
# Filter on preamble 0xffff (company id defined in firmware spec)
|
||||||
log.debug(f"{device.address} | no payload data found")
|
if len(raw) < 2 or raw[0] != 0xff or raw[1] != 0xff:
|
||||||
return
|
return
|
||||||
|
|
||||||
data = self.decode_payload(raw)
|
log.debug(f"{device.address} | Thingy detected, raw: {list(raw)}")
|
||||||
if not data:
|
|
||||||
log.warning(f"{device.address} | empty decoded payload")
|
|
||||||
return
|
|
||||||
|
|
||||||
log.debug(f"{device.address} | decoded: {data}")
|
data = self.decode_payload(raw)
|
||||||
self.publish(device.address, data)
|
if not data:
|
||||||
|
log.warning(f"{device.address} | empty decoded payload")
|
||||||
|
return
|
||||||
|
|
||||||
|
log.debug(f"{device.address} | decoded: {data}")
|
||||||
|
self.publish(device.address, data)
|
||||||
|
|
||||||
async def run(self):
|
async def run(self):
|
||||||
"""Start passive BLE scan and run indefinitely."""
|
"""Start passive BLE scan and run indefinitely."""
|
||||||
|
|||||||
Reference in New Issue
Block a user