0

我正在嘗試從藍牙LE設備發送給我的數組中讀取數據。從UUID讀取藍牙LE數組?

該數據流應爲18個字節,並且,作爲一個數組觀察時,我需要字節5,圖6和7

我對servicecharacteristic正確的UUID。但是,我不知道如何從characteristic獲得數組。

現在我只是試圖獲取我認識的數據。但是,下面的日誌語句會生成我無法理解或與數據匹配的隨機字符。

這個函數中唯一真正重要的行是與characteristic.getValue()的日誌,但我想我會包括整個事情的一些上下文。

@Override 
     public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { 
      Log.d(TAG, "characteristic read: "+characteristic.getValue()); 
      gatt.setCharacteristicNotification(characteristic, true); 
      gatt.readRemoteRssi(); 
      runOnUiThread(update_UI); 

      try { 
       Thread.sleep(500); 
      } catch(InterruptedException ex) { 
       Thread.currentThread().interrupt(); 
      } 

      gatt.discoverServices(); 
     } 

回答

0

在陣列末尾加上我想要的字節的括號給了我想要的數據。

Log.d(TAG, "characteristic read: "+characteristic.getValue()[4]);會給我第四個字節。