2017-04-27 4 views
0

バッテリー(RO)、ステータス(RO)、強度(R/W)のフィールドを持つデバイスでBLEを使用しようとしています。 私はデバイスでGattを設定するためのチュートリアルに従った。 私は次のコードを使用します。BLE readCharacteristicsは常にfalseを返します。またはgetvalueがnullです

public void onServicesDiscovered(BluetoothGatt gatt, int status) { 
Log.w(LOGGER + mOwner.get().getName(), "onServicesDiscovered received: " + status); 
if (status == BluetoothGatt.GATT_SUCCESS) { 
    // Save all services 
    for (BluetoothGattService gattService : mBluetoothGatt.getServices()) { 
     for (BluetoothGattCharacteristic charac : gattService 
       .getCharacteristics()) { 
      if (isContained(charac) { 
       mCharacteristics.set(mCharacteristicsUuid.indexOf(charac.getUuid() 
         .toString()), charac); 
        mBluetoothGatt.setCharacteristicNotification(charac, true); 
        // UUID for notification 
        BluetoothGattDescriptor descriptor = charac 
          .getDescriptor(UUID.fromString("00002902-0000-1000-" + 
            "8000-00805f9b34fb")); 
        if (descriptor != null) { 
         descriptor.setValue(BluetoothGattDescriptor 
           .ENABLE_NOTIFICATION_VALUE); 
         mBluetoothGatt.writeDescriptor(descriptor); 
        } 
      } 
     } 
    } 

ので、私はそれらを反復処理を行っている場合、サービスを発見しようとすると、その特性を。 UUIDが正しい場合は、それらをmCharacteristicsに追加します。 この値を読み取り可能な値(ここではそのすべて)に設定すると、通知が有効になります。

は、それが行わだとき、私は最初の読み取りを実行しよう:

Log.e(LOGGER + mOwner.get().getName(), "Reading first charac(index=0) : " + mBluetoothGatt 
      .readCharacteristic(mCharacteristics.get(0))); 
} 

私はAndroidのサービスに追いついて、このすべては、専用スレッド内であることを正確に持っています。 私は、デバイスが接続されていると確信しています。 それぞれの場合、私は(プロパティ& REEADABLE)の値を確認しました。それは常に> 0 ... ですが、読み取り専用の特性の場合、常に読み取り時にfalseになります... 強度(読み取り/書き込み) trueを返しますが、onCharacteristicRead()は呼び出されず、getValue()メソッドはnullを返します。

AndroidでBLEを使用するとかなり新しいです。

誰かがこの問題について考えていますか? ありがとうございます!

編集:私は有効な通知を設定した場合、II後の特性を読み取ることができません... は私が行うことができますどのように私に誰かを伝えることができ、実際には ...私は最終的に解決策を見つけたが、私は期待できないとして次のようになります。

> 1) on discover 
>  a) get all characts + set in list characs I want 
>  b) enable notification for ALL of these charac (if possible, I supposed, because of the descriptor that can be null ?) 
>  c) first read to know starting values 

答えて

関連する問題