Adafruit BLE python 库无法列出描述符

Adafruit BLE python library can't list descriptors

我正在尝试使用 python 的 BLE 库与一个 Nordic nrf51844 芯片组进行通信。因为一个特征是启用通知,我需要通过将描述符客户端特征配置设置为 0x0001 来启用来自客户端的通知。但是我未能通过调用 "characteristic.find_descriptor()" 获取描述符来获取它。我还尝试打印出所有发现的描述符,但看起来没有运气让它工作。

下面是我用来发现特征及其描述符的代码,参考了 Adafruit BLE 库的示例:

def enable_notification(characteristic):
    _enableDesc = characteristic.find_descriptor(CLIENT_CHARACTERISTIC_CONFIG_DESCRIPTOR_UUID)
    _cmd = bytearray([0x01, 0x00])
    _enableDesc.write_value(_cmd)

def handle_device_message(device):
    global _status
    # Once connected do everything else in a try/finally to make sure the device
    # is disconnected when done.

    # Wait for service discovery to complete for at least the specified
    # service and characteristic UUID lists.  Will time out after 60 seconds
    # (specify timeout_sec parameter to override).
    _logger.info('Discovering services...')
    device.discover([HES_SERVICE_UUID], [DATA_CHAR_UUID, STATUS_CHAR_UUID, FACTOR_CHAR_UUID])

    # Find the HES service and its characteristics.
    hes = device.find_service(HES_SERVICE_UUID)
    dataC = hes.find_characteristic(DATA_CHAR_UUID)
    statusC = hes.find_characteristic(STATUS_CHAR_UUID)
    #factorC = hes.find_characteristic(FACTOR_CHAR_UUID)

    dataC.list_descriptors()
    statusC.list_descriptors()

    enable_notification(dataC)
    enable_notification(statusC)

但它总是在 "characteristic.find_descriptor()" 失败并出现以下错误:

_enableDesc =
characteristic.find_descriptor(CLIENT_CHARACTERISTIC_CONFIG_DESCRIPTOR_UUID)
File "build/bdist.macosx-10.11-x86_64/egg/Adafruit_BluefruitLE/interfaces/gatt.py", line 98, in find_descriptor
File "build/bdist.macosx-10.11-x86_64/egg/Adafruit_BluefruitLE/corebluetooth/gatt.py", line 124, in list_descriptors
File "build/bdist.macosx-10.11-x86_64/egg/Adafruit_BluefruitLE/corebluetooth/metadata.py", line 63, in get_all
TypeError: 'NoneType' object is not iterable

我查看了库的源代码,但找不到显式获取描述符的接口。谁能帮我解决这个问题?

谢谢!

最后我通过检查 IOS 的 API 来设置通知。应该通过为特性调用 setNotify 而不是为描述符调用 writeValue 来设置它。对于描述符的东西,它表明我们需要等待一段时间才能发现并返回所有描述符。可能是 Python 实现的问题。未真正用 IOS 本机程序验证。

顺便说一句,设置通知后,我们还需要等待一段时间,设备才会向客户端发送通知。

将得到一个 Linux 框来验证 blueZ 的实施是否正常。