简体   繁体   English

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

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

I need to get all data from LogBlock charateristic of bracelet device, after a bluethooth low energy connection. 在进行蓝牙低功耗连接之后,我需要从手环设备的LogBlock特性获取所有数据。

Actually I get only few byte by logblock and not all data. 实际上,我只能通过logblock获得很少的字节,而不能获得所有数据。 Does anyone know how to syncronyze and buffering all data? 有谁知道如何同步和缓冲所有数据?

Below my bluethoot service after method call connect() 在我的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();
        }

Tnx in advance 提前发送

UPDATE UPDATE

I don't get any data from wristbend device, because I have sand init command to it by a C program. 我没有从腕部设备获得任何数据,因为我有一个C程序向它发出sand init命令。

Can any one know how to send soket of bluethoot java connection, to C program? 谁能知道如何将bluethoot java连接的套接字发送到C程序?

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

The problem was related to notifications ... When you read characteristics in sequence, you must be careful to set before all enables notifications and then make the first writing. 问题与通知有关。...顺序阅读特征时,必须小心设置,然后再启用所有通知,然后再进行第一次写入。 If you do not respect this order will not be notified of any change even if we respect the code correctly and read times on individual characteristics. 如果您不遵守该命令,即使我们正确遵守了代码并阅读了各个特性的时间,也不会收到任何更改的通知。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM