Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added timeout-option/parameter to start_discovery(...) #45

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
5 changes: 4 additions & 1 deletion gatt/gatt_linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down