def __init__(self): self.bus = dbus.SystemBus() self.app = localGATT.Application() self.srv = localGATT.Service(1, SERVICE_UUID, True) self.charc = localGATT.Characteristic(1, CHAR_UUID, self.srv, [0xBB], True, ['write']) self.charc.service = self.srv.path self.app.add_managed_object(self.srv) self.app.add_managed_object(self.charc) self.srv_mng = GATT.GattManager(adapter.list_adapters()[0]) self.srv_mng.register_application(self.app, {}) self.dongle = adapter.Adapter(adapter.list_adapters()[0]) advert = advertisement.Advertisement(1, 'peripheral') advert.service_UUIDs = [SERVICE_UUID] eddystone_data = tools.url_to_advert(WEB_BLINKT, 0x10, TX_POWER) advert.service_data = {EDDYSTONE: eddystone_data} if not self.dongle.powered: self.dongle.powered = True ad_manager = advertisement.AdvertisingManager(self.dongle.path) ad_manager.register_advertisement(advert, {})
def central(address): dongle = adapter.Adapter(adapter.list_adapters()[0]) if not dongle.powered: dongle.powered = True # Find nearby devices dongle.nearby_discovery() ubit = microbit(address) sense_buttons = True ubit.connect() led2.on() buzz.on() sleep(BEEP_TIME) buzz.off() while sense_buttons: btn_a = ubit.read_button_a() btn_b = ubit.read_button_b() # print('Button states: a={} b={}'.format(btn_a, btn_b)) if btn_a > 0 and btn_b < 1: print('Button A') led1.on() led3.off() elif btn_a < 1 and btn_b > 0: print('Button B') led1.off() led3.on() elif btn_a > 0 and btn_b > 0: sense_buttons = False led1.on() led3.on() buzz.on() sleep(BEEP_TIME) buzz.off() print('Bye bye!!!') elif btn_a < 1 and btn_b < 1: led1.off() led3.off() if not ubit.connected: sense_buttons = False led1.on() led2.on() led3.on() buzz.on() sleep(BEEP_TIME) buzz.off() sleep(0.02) # Disconnect device ubit.disconnect() # Read the connected status property led1.off() led2.off() led3.off() buzz.off()
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 __init__(self): self.bus = dbus.SystemBus() self.app = localGATT.Application() self.srv = localGATT.Service(1, CPU_TMP_SRVC, True) self.charc = TemperatureChrc(self.srv) self.charc.service = self.srv.path cpu_format_value = dbus.Array([dbus.Byte(0x0E), dbus.Byte(0xFE), dbus.Byte(0x2F), dbus.Byte(0x27), dbus.Byte(0x01), dbus.Byte(0x00), dbus.Byte(0x00)]) self.cpu_format = localGATT.Descriptor(4, CPU_FMT_DSCP, self.charc, cpu_format_value, ['read']) self.app.add_managed_object(self.srv) self.app.add_managed_object(self.charc) self.app.add_managed_object(self.cpu_format) self.srv_mng = GATT.GattManager(adapter.list_adapters()[0]) self.srv_mng.register_application(self.app, {}) self.dongle = adapter.Adapter(adapter.list_adapters()[0]) advert = advertisement.Advertisement(1, 'peripheral') advert.service_UUIDs = [CPU_TMP_SRVC] # eddystone_data = tools.url_to_advert(WEB_BLINKT, 0x10, TX_POWER) # advert.service_data = {EDDYSTONE: eddystone_data} if not self.dongle.powered: self.dongle.powered = True ad_manager = advertisement.AdvertisingManager(self.dongle.address) ad_manager.register_advertisement(advert, {})
def __init__(self): self.bus = dbus.SystemBus() self.app = localGATT.Application() self.srv = localGATT.Service(1, SERVICE_UUID, True) self.light = localGATT.Characteristic(1, LIGHT_UUID, self.srv, [0xAA], True, ["read", "notify"]) self.switch = localGATT.Characteristic(2, SWITCH_UUID, self.srv, [0xBB], True, ["read", "write", "notify"]) self.light.service = self.srv.path self.app.add_managed_object(self.srv) self.app.add_managed_object(self.light) self.app.add_managed_object(self.switch) self.srv_mng = GATT.GattManager(adapter.list_adapters()[0]) self.srv_mng.register_application(self.app, {}) self.dongle = adapter.Adapter(adapter.list_adapters()[0]) advert = advertisement.Advertisement(1, "peripheral") advert.service_UUIDs = [SERVICE_UUID] if not self.dongle.powered: self.dongle.powered = True ad_manager = advertisement.AdvertisingManager(self.dongle.path) ad_manager.register_advertisement(advert, {})
def __init__(self, adapter_obj=None): """Default initialiser. Creates the BLE beacon object If an adapter object exists then give it as an optional argument If an adapter object is not given then the first adapter found is used :param adapter_obj: Optional Python adapter object. """ self.dongle = None if adapter_obj is None: self.dongle = adapter.Adapter(adapter.list_adapters()[0]) else: self.dongle = adapter_obj self.broadcaster = advertisement.Advertisement(1, 'broadcast')
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 main(): dongles = adapter.list_adapters() print('dongles available: ', dongles) dongle = adapter.Adapter(dongles[0]) print('address: ', dongle.address) print('name: ', dongle.name) print('alias: ', dongle.alias) print('powered: ', dongle.powered) print('pairable: ', dongle.pairable) print('pairable timeout: ', dongle.pairabletimeout) print('discoverable: ', dongle.discoverable) print('discoverable timeout: ', dongle.discoverabletimeout) print('discovering: ', dongle.discovering) print('Powered: ', dongle.powered) if not dongle.powered: dongle.powered = True print('Now powered: ', dongle.powered) print('Start discovering') dongle.nearby_discovery()
from bluezero import adapter dongles = adapter.list_adapters() print("dongles available: ", dongles) dongle = adapter.Adapter(dongles[0]) print("address: ", dongle.address) print("name: ", dongle.name) print("alias: ", dongle.alias) print("powered: ", dongle.powered) print("pairable: ", dongle.pairable) print("pairable timeout: ", dongle.pairabletimeout) print("discoverable: ", dongle.discoverable) print("discoverable timeout: ", dongle.discoverabletimeout) print("discovering: ", dongle.discovering) print("Powered: ", dongle.powered) if not dongle.powered: dongle.powered = True print("Now powered: ", dongle.powered) print("Start discovering") dongle.nearby_discovery() dongle.powered = False
break else: print("this command is not recognized") if __name__ == '__main__': """ This script considers that your remote device has its bluetooth function on. Since we know that get_managed_objects() methods does keep device objects found earlier in most situation we will use it to retrieve our targeted device adresse""" "Replace the mac address by the targeted device" target_dev_address = '94:87:E0:8A:3B:A1' adapter_adress = list_adapters()[0] bluetooth_adapter = Adapter(adapter_adress) bluetooth_adapter.nearby_discovery() "Find managed devices adresses" dev_obj_path_list = filter_by_interface(dbus_tools.get_managed_objects(), constants.DEVICE_INTERFACE) dev_addr_list = list( map(dbus_tools.get_mac_addr_from_dbus_path, dev_obj_path_list)) print("Managed devices: ", dev_addr_list) "Attempt to connect pair and connect to the device" remote_device = None if target_dev_address in dev_addr_list: remote_device = Device(adapter_adress, target_dev_address)
def test_no_adapters(self): # Check for adapters. with self.assertRaises(AdapterError): out = adapter.list_adapters()