diff --git a/examples/discovery.py b/examples/discovery.py index 2b2731e..f3ca021 100644 --- a/examples/discovery.py +++ b/examples/discovery.py @@ -5,5 +5,5 @@ def device_discovered(self, device): print("[%s] Discovered, alias = %s" % (device.mac_address, device.alias())) manager = AnyDeviceManager(adapter_name='hci0') -manager.start_discovery() +manager.start_discovery(timeout=10000) # 10 seconds manager.run() diff --git a/gatt/gatt_linux.py b/gatt/gatt_linux.py index 5fdb9d7..ea0f6a1 100644 --- a/gatt/gatt_linux.py +++ b/gatt/gatt_linux.py @@ -124,11 +124,14 @@ def devices(self): self.update_devices() return self._devices.values() - def start_discovery(self, service_uuids=[]): + def start_discovery(self, service_uuids=[], timeout=10000): """Starts a discovery for BLE devices with given service UUIDs. :param service_uuids: Filters the search to only return devices with given UUIDs. + :param timeout: Stops discovery after a timeout (in milliseconds). If set to 0, no timeout is used. """ + if timeout > 0: + GObject.timeout_add(timeout, self.stop) discovery_filter = {'Transport': 'le'} if service_uuids: # D-Bus doesn't like empty lists, it needs to guess the type