def __init__(self, adapter_addr, device_addr): """Default initialiser. Creates object for the specified remote Bluetooth device. This is on the specified adapter specified. :param adapter_addr: Address of the local Bluetooth adapter. :param device_addr: Address of the remote Bluetooth device. """ self.bus = dbus.SystemBus() dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) self.mainloop = GObject.MainLoop() device_path = dbus_tools.get_dbus_path(adapter_addr, device_addr) if not device_path: raise ValueError("Cannot find a device: " + device_addr + " using adapter: " + adapter_addr) self.remote_device_path = device_path self.remote_device_obj = self.bus.get_object( constants.BLUEZ_SERVICE_NAME, self.remote_device_path) self.remote_device_methods = dbus.Interface(self.remote_device_obj, constants.DEVICE_INTERFACE) self.remote_device_props = dbus.Interface(self.remote_device_obj, dbus.PROPERTIES_IFACE)
def _subscribe(self, chrc, cb): chrc.resolve_gatt() uuid = chrc.chrc_uuid path = dbus_tools.get_dbus_path(characteristic=uuid, device=self.device_addr, adapter=self.adapter_addr) obj = dbus_tools.get_dbus_obj(path) iface = dbus_tools.get_dbus_iface(constants.DBUS_PROP_IFACE, obj) iface.connect_to_signal('PropertiesChanged', cb) obj.StartNotify(reply_handler=lambda: logging.debug('subscribed'), error_handler=dbus_tools.generic_error_cb, dbus_interface=constants.GATT_CHRC_IFACE)
def __init__(self, adapter_addr): """ GATT Manager Initialisation. :param manager_path: dbus path to the GATT Manager. """ self.manager_path = dbus_tools.get_dbus_path(adapter_addr) self.bus = dbus.SystemBus() self.manager_obj = self.bus.get_object(constants.BLUEZ_SERVICE_NAME, self.manager_path) self.manager_methods = dbus.Interface(self.manager_obj, constants.GATT_MANAGER_IFACE) self.manager_props = dbus.Interface(self.manager_obj, dbus.PROPERTIES_IFACE)
def __init__(self, adapter_addr): """ GATT Manager Initialisation. :param manager_path: dbus path to the GATT Manager. """ self.manager_path = dbus_tools.get_dbus_path(adapter_addr) self.bus = dbus.SystemBus() self.manager_obj = self.bus.get_object( constants.BLUEZ_SERVICE_NAME, self.manager_path) self.manager_methods = dbus.Interface( self.manager_obj, constants.GATT_MANAGER_IFACE) self.manager_props = dbus.Interface(self.manager_obj, dbus.PROPERTIES_IFACE)
def __init__(self, adapter_addr=None): self.bus = dbus.SystemBus() if adapter_addr is None: adapters = adapter.list_adapters() if len(adapters) > 0: adapter_addr = adapters[0] self.advert_mngr_path = dbus_tools.get_dbus_path(adapter=adapter_addr) self.advert_mngr_obj = self.bus.get_object( constants.BLUEZ_SERVICE_NAME, self.advert_mngr_path) self.advert_mngr_methods = dbus.Interface( self.advert_mngr_obj, constants.LE_ADVERTISING_MANAGER_IFACE) self.advert_mngr_props = dbus.Interface(self.advert_mngr_obj, dbus.PROPERTIES_IFACE)
def __init__(self, adapter_addr=None): """Default initialiser. Creates the interface to the local Bluetooth adapter device. If address is not given then first device is list is used. :param adapter_addr: Address of Bluetooth adapter to use. """ self.bus = dbus.SystemBus() if adapter_addr is None: adapters = list_adapters() if len(adapters) > 0: adapter_addr = adapters[0] self.path = dbus_tools.get_dbus_path(adapter=adapter_addr) self.adapter_object = self.bus.get_object( constants.BLUEZ_SERVICE_NAME, self.path) self.adapter_methods = dbus.Interface(self.adapter_object, constants.ADAPTER_INTERFACE) self.adapter_props = dbus.Interface(self.adapter_object, dbus.PROPERTIES_IFACE) self._nearby_timeout = 10 self._nearby_count = 0 self.mainloop = async_tools.EventLoop() self.on_disconnect = None self.on_connect = None self.on_device_found = None self.bus.add_signal_receiver(self._interfaces_added, dbus_interface=constants.DBUS_OM_IFACE, signal_name='InterfacesAdded') self.bus.add_signal_receiver(self._interfaces_removed, dbus_interface=constants.DBUS_OM_IFACE, signal_name='InterfacesRemoved') self.bus.add_signal_receiver(self._properties_changed, dbus_interface=dbus.PROPERTIES_IFACE, signal_name='PropertiesChanged', arg0=constants.DEVICE_INTERFACE, path_keyword='path')
def __init__(self, adapter_addr=None): self.bus = dbus.SystemBus() if adapter_addr is None: adapters = list(adapter.Adapter.available()) if len(adapters) > 0: use_adapter = adapters[0] adapter_addr = use_adapter.address else: use_adapter = adapter.Adapter(adapter_addr) if not use_adapter.discoverable: use_adapter.discoverable = True self.advert_mngr_path = dbus_tools.get_dbus_path(adapter=adapter_addr) self.advert_mngr_obj = self.bus.get_object( constants.BLUEZ_SERVICE_NAME, self.advert_mngr_path) self.advert_mngr_methods = dbus.Interface( self.advert_mngr_obj, constants.LE_ADVERTISING_MANAGER_IFACE) self.advert_mngr_props = dbus.Interface(self.advert_mngr_obj, dbus.PROPERTIES_IFACE)
def __init__(self, adapter_addr=None): """Default initialiser. Creates the interface to the local Bluetooth adapter device. If address is not given then first device is list is used. :param adapter_addr: Address of Bluetooth adapter to use. """ self.bus = dbus.SystemBus() if adapter_addr is None: adapters = list_adapters() if len(adapters) > 0: adapter_addr = adapters[0] self.path = dbus_tools.get_dbus_path(adapter=adapter_addr) self.adapter_object = self.bus.get_object( constants.BLUEZ_SERVICE_NAME, self.path) self.adapter_methods = dbus.Interface(self.adapter_object, constants.ADAPTER_INTERFACE) self.adapter_props = dbus.Interface(self.adapter_object, dbus.PROPERTIES_IFACE) self._nearby_timeout = 10 self._nearby_count = 0 self.mainloop = async_tools.EventLoop() self.bus.add_signal_receiver(dbus_tools.interfaces_added, dbus_interface=constants.DBUS_OM_IFACE, signal_name='InterfacesAdded') self.bus.add_signal_receiver(dbus_tools.properties_changed, dbus_interface=dbus.PROPERTIES_IFACE, signal_name='PropertiesChanged', arg0=constants.DEVICE_INTERFACE, path_keyword='path')
def __init__(self, adapter_addr, device_addr): """Default initialiser. Creates object for the specified remote Bluetooth device. This is on the specified adapter specified. :param adapter_addr: Address of the local Bluetooth adapter. :param device_addr: Address of the remote Bluetooth device. """ self.bus = dbus.SystemBus() dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) self.mainloop = GObject.MainLoop() device_path = dbus_tools.get_dbus_path(adapter_addr, device_addr) self.remote_device_path = device_path self.remote_device_obj = self.bus.get_object( constants.BLUEZ_SERVICE_NAME, self.remote_device_path) self.remote_device_methods = dbus.Interface( self.remote_device_obj, constants.DEVICE_INTERFACE) self.remote_device_props = dbus.Interface(self.remote_device_obj, dbus.PROPERTIES_IFACE)