Adafruit BLE python库不能列出描述符

时间:2016-07-12 15:24:52

标签: python bluetooth-lowenergy adafruit

我试图使用BLE库进行python与一个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

我查看了库的源代码,但无法找到明确获取描述符的接口。任何人都可以帮我吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

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

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

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