OGeek|极客世界-中国程序员成长平台

标题: android - 低功耗蓝牙 : Read Long Characteristics Value using Android/iOS [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 17:21
标题: android - 低功耗蓝牙 : Read Long Characteristics Value using Android/iOS

具有正常特性只读将读取 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 的设备(增加 MTU 是在 API 21 中引入的)



Best Answer-推荐答案


我可以确认 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 设置要读取的偏移量,我假设您只能调用一次 read。

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






欢迎光临 OGeek|极客世界-中国程序员成长平台 (https://ogeek.cn/) Powered by Discuz! X3.4