通过蓝牙低功耗连接从腕带心率传感器检索数据到 Android 应用程序

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

在蓝牙低功耗连接后,我需要从手环设备的 LogBlock 特性中获取所有数据。

实际上我只得到几个字节的日志块,而不是所有数据。有谁知道如何同步和缓冲所有数据?

方法调用 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();
        }

提前发送

更新

我没有从 wristbend 设备获取任何数据,因为我通过 C 程序向它发送了 sand init 命令。

任何人都知道如何将蓝牙 java 连接的套接字发送到 C 程序吗?

尝试获取原始字节数组 (GetValue) 而不是 getIntValue

问题是和notifications有关的... 顺序读取特性的时候一定要注意设置在所有启用notifications之前,然后再写第一个。如果您不遵守此订单,即使我们正确遵守代码并阅读个人特征的次数,也不会收到任何更改通知。