Exemplo n.º 1
0
    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, {})
Exemplo n.º 2
0
    def add_descriptor(self, srv_id, chr_id, dsc_id, uuid, value, flags):
        """
        Add information for the GATT descriptor.

        :param srv_id: integer of parent service that was added
        :param chr_id: integer of parent characteristic that was added
        :param dsc_id: integer between 0 & 9999 as unique reference
        :param uuid: The Bluetooth uuid number for this characteristic
        :param value: Initial value. list of integers in little endian format
        :param flags: Defines how the descriptor value can be used.
            Possible values:

                - "read"
                - "write"
                - "encrypt-read"
                - "encrypt-write"
                - "encrypt-authenticated-read"
                - "encrypt-authenticated-write"
                - "secure-read" (Server Only)
                - "secure-write" (Server Only)
                - "authorize"

        """
        self.descriptors.append(localGATT.Descriptor(
            srv_id, chr_id, dsc_id, uuid, value, flags
        ))
    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, {})