簡體   English   中英

通過藍牙低功耗連接將腕帶心率傳感器的數據檢索到Android應用程序

[英]Retrieve data from wristband heart rate sensor to Android application by Bluetooth low energy connection

在進行藍牙低功耗連接之后,我需要從手環設備的LogBlock特性獲取所有數據。

實際上,我只能通過logblock獲得很少的字節,而不能獲得所有數據。 有誰知道如何同步和緩沖所有數據?

在我的bluethoot服務下面,方法調用connect()

    @Override
    public void onCharacteristicRead(BluetoothGatt gatt,
                                    BluetoothGattCharacteristic characteristic,int status) {
         if (status == BluetoothGatt.GATT_SUCCESS) {
            Log.i("deviceBT","onCharacteristicRead "+characteristic.toString());
            broadcastUpdate(ACTION_DATA_AVAILABLE, characteristic);
        }

    }
   private void broadcastUpdate(final String action,final BluetoothGattCharacteristic characteristic) {
    final Intent intent = new Intent(action);
    if (UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuid())) {
        int flag = characteristic.getProperties();
        int format = -1;
        if ((flag & 0x01) != 0) {
            format = BluetoothGattCharacteristic.FORMAT_UINT16;
            Log.d(TAG, "Heart rate format UINT16.");
        } else {
            format = BluetoothGattCharacteristic.FORMAT_UINT8;
            Log.d(TAG, "Heart rate format UINT8.");
        }
        final int heartRate = characteristic.getIntValue(format, 1);
        Log.d(TAG, String.format("Received heart rate: %d", heartRate));
        intent.putExtra(EXTRA_DATA, String.valueOf(heartRate));

    }
    else if (UUID_LOGBLOCK.equals(characteristic.getUuid())) {

         byte[] value = characteristic.getValue();
        }

提前發送

UPDATE

我沒有從腕部設備獲得任何數據,因為我有一個C程序向它發出sand init命令。

誰能知道如何將bluethoot java連接的套接字發送到C程序?

嘗試獲取原始字節數組( GetValue )而不是getIntValue

問題與通知有關。...順序閱讀特征時,必須小心設置,然后再啟用所有通知,然后再進行第一次寫入。 如果您不遵守該命令,即使我們正確遵守了代碼並閱讀了各個特性的時間,也不會收到任何更改的通知。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM