首页 > 解决方案 > BLE 与 MiBand 3

问题描述

这是我第一次问,如果我碰巧显示错误,请原谅。

简而言之,我想创建能够与小米手环 3 交互的应用程序。我能够进行的交互只是读取电池信息。我真正想要的是启用实时心率和步数扫描。

我以前做过什么?

首先,我知道我应该把听众放在正确的位置?所以这里的功能

    public void listenHeartRate() {
        BluetoothGattCharacteristic characteristic = bluetoothGatt.getService(UUID.fromString("0000180d-0000-1000-8000-00805f9b34fb")).getCharacteristic(UUID.fromString("00002a37-0000-1000-8000-00805f9b34fb"));
        bluetoothGatt.setCharacteristicNotification(characteristic, true);
        BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"));
        descriptor.setValue(new byte[] {0x01, 0x00});
        if(!bluetoothGatt.writeDescriptor(descriptor)) {
            Log.d(TAG, "tesListenHeartRate: failed");

        }
    }

然后,我用这个开始扫描。

    public void startHeartRate() {
        Log.d(TAG, "tesHeartRate: start");
        BluetoothGattCharacteristic characteristic = bluetoothGatt.getService(UUID.fromString("0000180d-0000-1000-8000-00805f9b34fb")).getCharacteristic(UUID.fromString("00002a39-0000-1000-8000-00805f9b34fb"));
        characteristic.setValue(new byte[]{21, 2, 1});
        if (!bluetoothGatt.writeCharacteristic(characteristic)) {
            Log.d(TAG, "tesStartHeartRate: failed");
        }
    }

问题在于 writeCharacteristic 总是返回状态 3,这意味着 GATT_WRITE_NOT_PERMITTED。

那么,我哪里做错了?非常感谢。

标签: javaandroidbluetooth-lowenergy

解决方案


“(...)我几乎放弃了,但后来意识到我错过了一些东西。身份验证。是的,我错过了身份验证!感谢 Andrey Nikishaev,他很好地解释了 mi band 是如何配对和验证的。这给了我是一个良好的开端。以下是身份验证步骤:(...)"

整篇文章:https ://medium.com/@yogeshojha/i-hacked-xiaomi-miband-3-and-here-is-how-i-did-it-43d68c272391


推荐阅读