java - BLE 与 MiBand 3
问题描述
这是我第一次问,如果我碰巧显示错误,请原谅。
简而言之,我想创建能够与小米手环 3 交互的应用程序。我能够进行的交互只是读取电池信息。我真正想要的是启用实时心率和步数扫描。
我以前做过什么?
我已经看过并尝试过https://github.com/pangliang/miband-sdk-android。实际上,正是这个库让我认为从 Android 启用心脏扫描是可能的。我尝试使用我的 Mi Band 3 但失败了:setHeartRateScanListener、startHeartRateScan、getBatteryInfo。
我已经看到、克隆和篡改了一些https://github.com/Freeyourgadget/Gadgetbridge。太棒了,它可以与我的 Mi Band 3 交互,但问题是 Gadgetbridge 没有心率扫描功能,我对代码有点不知所措。
当然,我已经尝试过https://developer.android.com/guide/topics/connectivity/bluetooth-le。在阅读了 Pangliang 和 Gadgetbridge 的代码后,我做了以下心率扫描。
首先,我知道我应该把听众放在正确的位置?所以这里的功能
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。
那么,我哪里做错了?非常感谢。
解决方案
“(...)我几乎放弃了,但后来意识到我错过了一些东西。身份验证。是的,我错过了身份验证!感谢 Andrey Nikishaev,他很好地解释了 mi band 是如何配对和验证的。这给了我是一个良好的开端。以下是身份验证步骤:(...)"
整篇文章:https ://medium.com/@yogeshojha/i-hacked-xiaomi-miband-3-and-here-is-how-i-did-it-43d68c272391
推荐阅读
- javascript - 如何在javascript中获取中间字符
- ios - 从表格单元格触发 Segue 到另一个页面
- android - 自定义 Lint 检查未运行
- php - 来自 homebrew 的 php@7.0 的 PHP 扩展 mosquitto 安装
- wordpress - WordPress 导出/翻译/导入单页
- html-agility-pack - 从 URL 加载 html 的两种方法?
- jquery - 如何在 Laravel 中将数组从 Controller 发送到 JavaScript?
- facebook - Facebook App 域与 localhost 一起使用,但不适用于我的网站
- xpath - 替换xpath中的完整字符串刚刚得到
- amazon-web-services - Fargate 上的 AWS docker - 是否可以选择不同的内核?