0

我正在尝试使用 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

我查看了库的源代码,但找不到显式获取描述符的接口。谁可以帮我这个事?

谢谢!

4

1 回答 1

0

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

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

将获得一个 Linux 机器来验证 blueZ 的实现是否运行良好。

于 2016-07-15T06:31:21.503 回答