繁体   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