Git Product home page Git Product logo

Comments (2)

chadrockey avatar chadrockey commented on June 16, 2024 1

Thanks! Hopefully this is searchable in the future for those having issues.

from python-bluezero.

ukBaz avatar ukBaz commented on June 16, 2024

Thanks for posting this here.

The dongle.nearby_discovery functionality was added to allow the discovery of nearby devices without the user having to create an eventloop and handle events asynchronously.

The scanner/observer functionality within Bluezero better demonstrates how to scan and get the RSSI values as the devices are discovered:

cls.dongle.on_device_found = cls.on_device_found

This uses the signals within the API PropertiesChanged , InterfacesAdded , and InterfacesRemoved

def _properties_changed(self, interface, changed, invalidated, path):
"""
Handle DBus PropertiesChanged signal and
call appropriate user callback
"""
device_address = dbus_tools.get_device_address_from_dbus_path(path)
adapter_addr = dbus_tools.get_adapter_address_from_dbus_path(path)
if 'Connected' in changed:
if all((changed['Connected'],
self.address == adapter_addr,
self.on_connect)):
if tools.get_fn_parameters(self.on_connect) == 0:
self.on_connect()
elif tools.get_fn_parameters(self.on_connect) == 1:
new_dev = device.Device(
adapter_addr=self.address,
device_addr=device_address)
self.on_connect(new_dev)
elif tools.get_fn_parameters(self.on_connect) == 2:
self.on_connect(adapter_addr, device_address)
elif not changed['Connected'] and self.on_disconnect:
if tools.get_fn_parameters(self.on_disconnect) == 0:
logger.warning("using deprecated version of disconnect "
"callback, move to on_disconnect(dev) "
"with device parameter")
self.on_disconnect()
elif tools.get_fn_parameters(self.on_disconnect) == 1:
new_dev = device.Device(
adapter_addr=self.address,
device_addr=device_address)
self.on_disconnect(new_dev)
elif tools.get_fn_parameters(self.on_disconnect) == 2:
self.on_disconnect(self.address, device_address)
def _interfaces_added(self, path, device_info):
"""
Handle DBus InterfacesAdded signal and
call appropriate user callback
"""
dev_iface = constants.DEVICE_INTERFACE
if constants.DEVICE_INTERFACE in device_info:
dev_addr = device_info[dev_iface].get('Address')
dev_connected = device_info[dev_iface].get('Connected')
if self.on_device_found and dev_addr:
new_dev = device.Device(
adapter_addr=self.address,
device_addr=dev_addr)
self.on_device_found(new_dev)
if all((self.on_connect, dev_connected, dev_addr)):
new_dev = device.Device(
adapter_addr=self.address,
device_addr=dev_addr)
self.on_connect(new_dev)
def _interfaces_removed(self, path, device_info):
"""
Handle DBus InterfacesRemoved signal and
call appropriate user callback
"""

from python-bluezero.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.