android - 蓝牙低功耗: Read Long Characteristics Value using Android/iOS

标签 android ios bluetooth-lowenergy android-bluetooth ios-bluetooth

使用正常的特征读取时,只会读取数据的 MTU 大小(20 字节)。 我的客户将提供更大尺寸(大约 100 字节)的特征。

我看到 BLE 提供了“长读取”功能,可以读取直到达到特征的大小。 (https://bluegiga.zendesk.com/entries/25053373--REFERENCE-BLE-master-slave-GATT-client-server-and-data-RX-TX-basics)

attclient_read_long command - Starts a procedure where the client first sends normal read request to the server, and if the server returns an attribute value with a length equal to the BLE MTU (22 bytes), then the client continues to send "read long" requests until rest of the attribute is read. This only applies if you are reading attributes that are longer than 22 bytes. It is often simpler to construct your GATT server such that there are no long attributes, for simplicity. Note that the BLE protocol still requires that data is packetized into max. 22-byte chunks, so using "read long" does not save transmission time.

但是如何在 Android 中使用此功能呢? BluetoothGatt 类仅提供一个简单的“Read()”——与 iOS 相同。

增加 MTU 是不可能的,因为我们需要支持 AP 级别 < 21 的设备(increaseMTU 是在 API 21 中引入的)

最佳答案

我可以确认 iOS 会首先按照标准进行读取操作。然后,如果服务器返回一个完全填满的 PDU,那么 iOS 设备将继续执行 blob 读取操作。使用运行 iOS 11.2.x 的 iPhone 7 进行测试

对于长属性,您不需要多次调用peripheral.readValue(characteristic)。 CoreBluetooth 在幕后完成所有这些工作。

请参阅蓝牙规范核心 v5.0,特别是第 3 卷,F 部分“长属性值”。

实验证明上述内容。

我有一个 Android Thing 作为服务器,我正在使用它在读取操作期间返回我的 iPhone 的最大长度。 iOS 和我的 RPI3 交换的 MTU 为 185。因此读取响应的长度为 (MTU - 1) 184 字节。然后,服务器 (RPI) 接收偏移量为 184 的新读取请求,然后您可以返回更多数据。一直持续到偏移量 > 512,或者最后读取的响应返回的长度小于 MTU - 1。

基于BluetoothGattServer 支持长属性这一事实,我假设BluetoothGatt 对象也支持长属性。由于无法通过 API 设置要读取的偏移量,因此我假设您只能调用一次读取。

关于android - 蓝牙低功耗: Read Long Characteristics Value using Android/iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38241986/

相关文章:

使用外部支付处理器的 Android 应用计费

bluetooth - 经典蓝牙、BLE 还是...Wifi Direct?

android - BluetoothGattCallBack 函数 onCharacteristicRead 仅调用一次

ios - AFNetworking V 2 是否支持非流式多部分后台上传任务?

ios - 如何删除 UITextView 的默认边框

android - 我应该为跨平台应用程序使用哪个 BLE Beacon?

android - 为什么服务 Intent 需要显式 Intent

Android Dagger2 + OkHttp + Retrofit 依赖循环错误

android - 如何在位图中存储来自 imageView 的背景图像?

ios - 从 Firebase 检索数据期间 UITableView 未更新