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 __init__(self, name=None, address=None): """ Initialization of an instance of a remote Blinkt BLE device :param name: Will look for a BLE device with this string in its name :param address: Will look for a BLE device with this address (Currently not implemented) """ self.name = name self.address = address self.dongle = adapter.Adapter(adapter.list_adapters()[0]) if not self.dongle.powered: self.dongle.powered = True logger.debug('Adapter powered') logger.debug('Start discovery') self.dongle.nearby_discovery() device_path = None if name is not None: device_path = tools.get_dbus_path( constants.DEVICE_INTERFACE, 'Name', name) elif address is not None: device_path = tools.get_dbus_path( constants.DEVICE_INTERFACE, 'Address', address) self.blnkt = device.Device(device_path[0]) self.blinkt_srv_path = None self.blinkt_chrc_path = None
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 client(): dongle = adapter.Adapter(adapter.list_adapters()[0]) if not dongle.powered: dongle.powered = True dongle.nearby_discovery() cc2650 = device.Device( tools.device_dbus_path(constants.DEVICE_INTERFACE, 'SensorTag')[0]) # Connect to device cc2650.connect() while not cc2650.services_resolved: sleep(0.5) # constants TMP_CONF_PATH = Characteristic( tools.uuid_dbus_path(constants.GATT_CHRC_IFACE, 'F000AA02-0451-4000-B000-000000000000')[0]) TMP_DATA_PATH = Characteristic( tools.uuid_dbus_path(constants.GATT_CHRC_IFACE, 'F000AA01-0451-4000-B000-000000000000')[0]) OPT_CONF_PATH = Characteristic( tools.uuid_dbus_path(constants.GATT_CHRC_IFACE, 'F000AA72-0451-4000-B000-000000000000')[0]) OPT_DATA_PATH = Characteristic( tools.uuid_dbus_path(constants.GATT_CHRC_IFACE, 'F000AA71-0451-4000-B000-000000000000')[0]) BAR_CONF_PATH = Characteristic( tools.uuid_dbus_path(constants.GATT_CHRC_IFACE, 'F000AA42-0451-4000-B000-000000000000')[0]) BAR_DATA_PATH = Characteristic( tools.uuid_dbus_path(constants.GATT_CHRC_IFACE, 'F000AA41-0451-4000-B000-000000000000')[0]) HUM_CONF_PATH = Characteristic( tools.uuid_dbus_path(constants.GATT_CHRC_IFACE, 'F000AA22-0451-4000-B000-000000000000')[0]) HUM_DATA_PATH = Characteristic( tools.uuid_dbus_path(constants.GATT_CHRC_IFACE, 'F000AA21-0451-4000-B000-000000000000')[0]) # Read the connected status property if cc2650.connected: # IR Temperature Sensor print('\nIR Temperature Sensor') read_sensor(TMP_CONF_PATH, TMP_DATA_PATH) # Optical Sensor print('\nOptical Sensor') read_sensor(OPT_CONF_PATH, OPT_DATA_PATH) # Barometric Pressure Sensor print('\nBarometric Pressure Sensor') read_sensor(BAR_CONF_PATH, BAR_DATA_PATH) # Humidity Sensor print('\nHumidity Sensor') read_sensor(HUM_CONF_PATH, HUM_DATA_PATH) # Disconnect device cc2650.disconnect()
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]['Address'] if self.on_device_found is not None and dev_addr: new_dev = device.Device(adapter_addr=self.address, device_addr=dev_addr) self.on_device_found(new_dev)
def __init__(self, device_addr, adapter_addr=None): if adapter_addr is None: self.dongle = adapter.Adapter() logger.debug('Adapter is: {}'.format(self.dongle.address)) else: self.dongle = adapter.Adapter(adapter_addr) if not self.dongle.powered: self.dongle.powered = True logger.debug('Adapter was off, now powered on') self.rmt_device = device.Device(self.dongle.address, device_addr) self._characteristics = []
def get_managed_device_list(self): """Return a list of Devices manageable by this adapter""" device_objects_list = [] managed_devices = dbus_tools.get_managed_objects() for key, dev in managed_devices.items(): remote_device = dev.get("org.bluez.Device1") if remote_device is not None: device_addr = remote_device.get("Address") if device_addr is not None: device_objects_list.append( device.Device(self.address, device_addr)) return device_objects_list
def __init__(self, adapter_addr, device_addr, srv_uuid, chrc_uuid): """ Remote GATT Characteristic Initialisation. :param adapter_addr: Adapter address. :param device_addr: device address. :param srv_uuid: Service UUID. :param chrc_uuid: Characteristic UUID. """ self.adapter_addr = adapter_addr self.device_addr = device_addr self.rmt_device = device.Device(adapter_addr, device_addr) self.srv_uuid = srv_uuid self.chrc_uuid = chrc_uuid self.characteristic_methods = None self.characteristic_props = None
def __init__(self, adapter_addr, device_addr, srv_uuid): """ Remote GATT Service Initialisation. :param adapter_addr: Adapter address. :param device_addr: device address. :param srv_uuid: Service UUID. """ self.adapter_addr = adapter_addr self.device_addr = device_addr self.srv_uuid = srv_uuid self.rmt_device = device.Device(adapter_addr, device_addr) self.service_methods = None self.service_props = None if self.rmt_device.services_resolved: self.resolve_gatt()
def __init__(self, name=None, address=None): """ Initialization of an instance of a remote microbit :param name: Will look for a BLE device with this string in its name :param address: Will look for a BLE device with this address (Currently not implemented) """ self.name = name self.address = address self.dongle = adapter.Adapter(adapter.list_adapters()[0]) if not self.dongle.powered: self.dongle.powered = True logger.debug('Adapter powered') logger.debug('Start discovery') self.dongle.nearby_discovery() self.ubit = device.Device( tools.get_dbus_path(constants.DEVICE_INTERFACE, 'Name', name)[0]) self.accel_srv_path = None self.accel_data_path = None self.aceel_period_path = None self.magneto_srv_path = None self.magneto_data_path = None self.magneto_period_path = None self.magneto_bearing_path = None self.btn_srv_path = None self.btn_a_state_path = None self.btn_b_state_path = None self.io_pin_srv_path = None self.io_pin_data_path = None self.io_ad_config_path = None self.io_pin_config_path = None self.io_pin_pwm_path = None self.led_srv_path = None self.led_state_path = None self.led_text_path = None self.led_scroll_path = None self.temp_srv_path = None self.temp_data_path = None self.temp_period_path = None
def __init__(self, adapter_addr, device_addr, srv_uuid, chrc_uuid, dscr_uuid): """ Remote GATT Descriptor Initialisation. :param adapter_addr: Adapter address. :param device_addr: device address. :param srv_uuid: Service UUID. :param chrc_uuid: Characteristic UUID. :param dscr_uuid: Descriptor UUID. """ self.adapter_addr = adapter_addr self.device_addr = device_addr self.rmt_device = device.Device(adapter_addr, device_addr) self.srv_uuid = srv_uuid self.chrc_uuid = chrc_uuid self.dscr_uuid = dscr_uuid self.descriptor_methods = None self.descriptor_props = None if self.rmt_device.services_resolved: self.resolve_gatt()
if value > 0: global display_on display_on = False print('Off') lights.clear() lights.show() print('power adapter') dongle = adapter.Adapter('/org/bluez/hci0') if not dongle.powered(): dongle.powered(True) print('discovery') dongle.nearby_discovery() ubit = device.Device( tools.device_dbus_path(constants.DEVICE_INTERFACE, 'puteg')[0]) while True: print('connect...') while not ubit.connected(): ubit.connect() while not ubit.services_resolved(): lights.set_pixel(1, 1, 255, 0, 0) sleep(0.1) lights.show() lights.clear() sleep(0.1) print('set up characteristics') ubit_btn_b = Characteristic( tools.uuid_dbus_path(constants.GATT_CHRC_IFACE, 'E95DDA90-251D-470A-A062-FA1922DFA9A8')[0]) ubit_btn_b.add_characteristic_cb(on_button_b)