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 create_mqtt_proxy(client, newline): bus = dbus.SystemBus() app = localGATT.Application() srv = localGATT.Service(1, MQTT_SRVC, True) receive = Receive(srv, MQTT_RX_CHRC, client, newline) transmit = Transmit(srv, MQTT_TX_CHRC, client) app.add_managed_object(srv) app.add_managed_object(receive) app.add_managed_object(transmit) srv_mng = GATT.GattManager(adapter.list_adapters()[0]) srv_mng.register_application(app, {}) dongle = adapter.Adapter(adapter.list_adapters()[0]) if not dongle.powered: # bring hci0 up if down dongle.powered = True advert = advertisement.Advertisement(1, 'peripheral') advert.service_UUIDs = [MQTT_SRVC] ad_manager = advertisement.AdvertisingManager(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.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 test_service_primary(self): """Test the service primary flag.""" # Invoke the bluez GATT library to access the mock GATT service test_service = GATT.Service(self.svc_dpath) # Test for the UUID self.assertEqual(test_service.primary, True)
def test_service_uuid(self): """Test the service UUID.""" # Invoke the bluez GATT library to access the mock GATT service test_service = GATT.Service(self.svc_dpath) # Test for the UUID self.assertEqual(test_service.UUID, '180F')
def __init__(self): self.bus = dbus.SystemBus() self.app = localGATT.Application() self.srv = localGATT.Service(1, SVC_UUID, True) self.idsCharc = DeviceIDsChrc(self.srv) self.attrCharc = DeviceAttrChrc(self.srv) self.idsCharc.service = self.srv.path self.attrCharc.service = self.srv.path self.app.add_managed_object(self.srv) self.app.add_managed_object(self.idsCharc) self.app.add_managed_object(self.attrCharc) 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 = [SVC_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.address) ad_manager.register_advertisement(advert, {})
def __init__(self): self.bus = dbus.SystemBus() self.app = localGATT.Application() self.srv = localGATT.Service( 1, HR_UUID, True) # HR_UUID = '0000180d-0000-1000-8000-00805f9b34fb' self.charc = HeartRateMeasurementChrc(self.srv) 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', 'HeartRate') # advert.appearance = [0x0341] # Actually will give Error: Failed to register advertisement: org.bluez.Error.Failed: Failed to register advertisement advert.service_UUIDs = [HR_UUID] 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() ''' service_id: 1 uuid: VEERING_SRVC primary: True ''' self.srv = localGATT.Service(1, VEERING_SRVC, True) self.charc = VeeringChrc(self.srv) 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]) self.advert = advertisement.Advertisement(1, 'peripheral') self.advert.service_UUIDs = [VEERING_SRVC] if not self.dongle.powered: self.dongle.powered = True self.ad_manager = advertisement.AdvertisingManager(self.dongle.path) self.ad_manager.register_advertisement(self.advert, {})
def __init__(self, reading_callback): self.bus = dbus.SystemBus() self.app = localGATT.Application() self.srv = localGATT.Service(1, AQI_PM_SRVC, True) self.pm_2_5_charc = AQIChrc(1, PM_2_5_CHRC, self.srv, 0.0, 'PM 2.5', reading_callback) self.pm_2_5_charc.service = self.srv.path self.pm_10_charc = AQIChrc(2, PM_10_CHRC, self.srv, 0.0, 'PM 10', reading_callback) self.pm_10_charc.service = self.srv.path pm_2_5_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) ]) pm_10_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.pm_2_5_format = localGATT.Descriptor(4, PM_2_5_FMT_DSCP, self.pm_2_5_charc, pm_2_5_format_value, ['read']) self.pm_10_format = localGATT.Descriptor(5, PM_10_FMT_DSCP, self.pm_10_charc, pm_10_format_value, ['read']) self.app.add_managed_object(self.srv) self.app.add_managed_object(self.pm_2_5_charc) self.app.add_managed_object(self.pm_2_5_format) self.app.add_managed_object(self.pm_10_charc) self.app.add_managed_object(self.pm_10_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 = [AQI_PM_SRVC] if not self.dongle.powered: self.dongle.powered = True ad_manager = advertisement.AdvertisingManager(self.dongle.address) ad_manager.register_advertisement(advert, {})
def test_service_device(self): """Test the service device path.""" # Invoke the bluez GATT library to access the mock GATT service test_service = GATT.Service(self.svc_dpath) # Test for the device path dev_underscore = self.address.replace(':', '_').upper() dev_addr = '{0}/dev_{1}'.format(self.ad_dpath, dev_underscore) self.assertEqual(test_service.device, dev_addr)
def add_characteristic(self, srv_uuid, chrc_uuid): """ Specify a characteristic of interest on the remote device by using the GATT Service UUID and Characteristic UUID :param srv_uuid: 128 bit UUID :param chrc_uuid: 128 bit UUID :return: """ chrc_hndl = GATT.Characteristic(self.dongle.address, self.rmt_device.address, srv_uuid, chrc_uuid) self._characteristics.append(chrc_hndl) return chrc_hndl
def __init__(self, adapter_address, local_name=None, appearance=None): self.app = localGATT.Application() self.srv_mng = GATT.GattManager(adapter_address) self.services = [] self.characteristics = [] self.descriptors = [] self.primary_services = [] self.dongle = adapter.Adapter(adapter_address) self.local_name = local_name self.appearance = appearance self.advert = advertisement.Advertisement(1, 'peripheral') self.ad_manager = advertisement.AdvertisingManager(adapter_address) self.mainloop = async_tools.EventLoop()
def __init__(self): self.mainloop = async_tools.EventLoop() 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] advert.local_name = 'CPU Temp' advert.appearance = 1344 # 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, UART_SRVC, True) self.receive = UartRxChrc(self.srv) self.transmit = UartTxChrc(self.srv, self.receive) self.app.add_managed_object(self.srv) self.app.add_managed_object(self.receive) self.app.add_managed_object(self.transmit) 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 = [UART_SRVC] if not self.dongle.powered: self.dongle.powered = True ad_manager = advertisement.AdvertisingManager(self.dongle.address) ad_manager.register_advertisement(advert, {})
def build_fat_service(): html_string = """<html><head><style> body { background-color: linen; } h1 { color: maroon; margin-left: 40px; } </style><title>FatBeacon Demo</title> <meta charset='UTF-8'><meta name='description' content='FatBeacon Demo'/> </head> <body> <h1>Fat Beacon</h1> <p> A FatBeacon is a beacon that rather than advertising a URL to load a web page from it actually hosts the web page on the device and services it up from the BLE characteristic </p> </body> </html>""" html_ord = [] for char in html_string: html_ord.append(ord(char)) app = localGATT.Application() srv = localGATT.Service(1, FAT_SERVICE, True) fat_html = localGATT.Characteristic(1, HTML_CHRC, srv, html_ord, False, ['read']) fat_html.service = srv.path app.add_managed_object(srv) app.add_managed_object(fat_html) srv_mng = GATT.GattManager('/org/bluez/hci0') srv_mng.register_application(app, {})