fix(gateway): replace UUID filter with manufacturer data preamble filter
This commit is contained in:
@@ -41,6 +41,7 @@ class Gateway:
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Authentication — username from config, password from environment variable
|
# Authentication — username from config, password from environment variable
|
||||||
|
# The password is never stored in config files or source code
|
||||||
username = config["mqtt"].get("username")
|
username = config["mqtt"].get("username")
|
||||||
password = os.environ.get("MQTT_PASSWORD")
|
password = os.environ.get("MQTT_PASSWORD")
|
||||||
if username:
|
if username:
|
||||||
@@ -113,25 +114,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 Adrien's preamble (0xffff) in manufacturer data."""
|
"""BLE scan callback — filters on Adrien's preamble (0xffff) in manufacturer data."""
|
||||||
if not adv_data.manufacturer_data:
|
if not adv_data.manufacturer_data:
|
||||||
return
|
return
|
||||||
|
|
||||||
raw = list(adv_data.manufacturer_data.values())[0]
|
raw = list(adv_data.manufacturer_data.values())[0]
|
||||||
|
|
||||||
# Filter on preamble 0xffff (company id defined in firmware spec)
|
# Filter on preamble 0xffff (company id defined in firmware spec)
|
||||||
if len(raw) < 2 or raw[0] != 0xff or raw[1] != 0xff:
|
if len(raw) < 2 or raw[0] != 0xff or raw[1] != 0xff:
|
||||||
return
|
return
|
||||||
|
|
||||||
log.debug(f"{device.address} | Thingy detected, raw: {list(raw)}")
|
log.debug(f"{device.address} | Thingy detected, raw: {list(raw)}")
|
||||||
|
|
||||||
data = self.decode_payload(raw)
|
data = self.decode_payload(raw)
|
||||||
if not data:
|
if not data:
|
||||||
log.warning(f"{device.address} | empty decoded payload")
|
log.warning(f"{device.address} | empty decoded payload")
|
||||||
return
|
return
|
||||||
|
|
||||||
log.debug(f"{device.address} | decoded: {data}")
|
log.debug(f"{device.address} | decoded: {data}")
|
||||||
self.publish(device.address, 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