Skip to content

Commit

Permalink
Disable duplicate detection of advertisement data on Linux (#85)
Browse files Browse the repository at this point in the history
Without this, non-compliant devices such as the TP357/8/9 return
multiple keys in manufacturer data and we don't know which is the
most recent data, so the sensor values don't update.
  • Loading branch information
koenvervloesem authored Dec 26, 2022
1 parent cdcbdf0 commit 119f94a
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions TheengsGateway/ble_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,25 @@ async def ble_scan_loop(self):
"""Scan for BLE devices."""
scanner_kwargs = {"scanning_mode": self.scanning_mode}

# Passive scanning with BlueZ needs at least one or_pattern.
# The following matches all devices.
if platform.system() == "Linux" and self.scanning_mode == "passive":
scanner_kwargs["bluez"] = BlueZScannerArgs(
or_patterns=[
OrPattern(0, AdvertisementDataType.FLAGS, b"\x06"),
OrPattern(0, AdvertisementDataType.FLAGS, b"\x1a"),
]
)
if platform.system() == "Linux":
if self.scanning_mode == "passive":
# Passive scanning with BlueZ needs at least one or_pattern.
# The following matches all devices.
scanner_kwargs["bluez"] = BlueZScannerArgs(
or_patterns=[
OrPattern(0, AdvertisementDataType.FLAGS, b"\x06"),
OrPattern(0, AdvertisementDataType.FLAGS, b"\x1a"),
]
)
elif self.scanning_mode == "active":
# Disable duplicate detection of advertisement data.
# Without this parameter non-compliant devices such as the
# TP357/8/9 return multiple keys in manufacturer data and
# we don't know which is the most recent data, so the sensor
# values don't update.
scanner_kwargs["bluez"] = BlueZScannerArgs(
filters=dict(DuplicateData=True)
)

if self.adapter:
scanner_kwargs["adapter"] = self.adapter
Expand Down

0 comments on commit 119f94a

Please sign in to comment.