2016-07-12 2 views
0

私はPythonにBLEライブラリを使用して、1つのNordic nrf51844チップセットと通信しようとしています。 1つの特性は通知が有効なので、クライアント側の記述をClient Characteristic Configurationの0x0001に設定することで、クライアント側からの通知を有効にする必要があります。しかし、私はそれを得るために、 "characteristic.find_descriptor()"という呼出しで記述子を得ることに失敗しました。私は発見されたすべてのディスクリプタをプリントアウトしようとしましたが、動作させる運がないように見えます。以下は Adafruit BLE pythonライブラリでは、ディスクリプタを指定できません

は私が特性を発見するために使用しているコードであり、その記述は、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 

ライブラリのソースコードを調べましたが、記述子を明示的に取得するインターフェイスが見つかりませんでした。誰かが私にこれを助けることができますか?

ありがとうございます!

答えて

0

最後に、IOSのAPIをチェックして通知を設定しました。これは、ディスクリプタのwriteValueではなく、特性のsetNotifyを呼び出すことによって設定する必要があります。また、ディスクリプタの場合は、すべてのディスクリプタが検出されて返されるまで待つ必要があることを示しています。 Pythonで実装された問題かもしれません。 IOSネイティブプログラムでは本当に確認されていません。

通知を設定した後、デバイスが通知をクライアントに送信する前にしばらく待つ必要があります。

blueZがうまく機能していることを確認するためのLinuxボックスが表示されます。

関連する問題