How to write a client characteristic configuration descriptor in bluez

谁说胖子不能爱 提交于 2019-12-12 03:29:46

问题


I am working with the example-gatt-server.py script that comes with bluez on my linux board. I want to add notification to one of my custom characteristics. For that I need to define the Client Characteristic Configuration Descriptor and add it to my custom characteristic. Here is how I am doing this -

class ClientCharacteristicConfigurationDescriptor(Descriptor):

CCCD_UUID = '2902'

def __init__(self, bus, index, characteristic):
    self.value = array.array('B')
    self.value = self.value.tolist()
    #self.value = []

    Descriptor.__init__(
            self, bus, index,
            self.CCCD_UUID,
            ['read', 'write'],
            characteristic)

def ReadValue(self):
    print("I am reading CCCD value")
    print(self.value)
    return self.value

def WriteValue(self, value):
    print("I am writing CCCD value")
    print type(value)
    #self.value = value
    print(value)

This code was inspired by the CharacteristicUserDescriptionDescriptor class that already comes defined in the example-gatt-server file. The above code gives me errors while reading or writing. It doesn't even print the "I am reading CCCD value" statement. What am I missing here?

Thanks!


回答1:


Bluez handles the Client Characteristic Configuration Descriptor (CCCD). You should not need to define it yourself in your code.
Notification support should transparently be handled by Bluez if you have defined the flag 'notify' for the corresponding characteristic.

As you noticed example-gatt-server defines Characteristic User Description (CUD) and not CCCD.



来源:https://stackoverflow.com/questions/36658513/how-to-write-a-client-characteristic-configuration-descriptor-in-bluez

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!