我目前正在开发 Android BLE,并遇到了很多 Android BLE 堆栈的问题。

我的开发工具是带有 Android 4.3 的 Samsung Galaxy J。

我想知道如何从 BLE 读取特征并写入特征(就像我验证收到的数据,然后使用 BLE 发送另一个数据)

我有严重的问题理解Android BLE回调的工作原理,我不了解这些5个功能...手册不清楚,任何人都可以以简单的形式解释好的灵魂吗???

onCharacteristicWrite
onCharacteristicRead
onCharacteristicChanged
onDescriptorRead
onDescriptorWrite

我目前的情况是,我设法读取 onCharacteristicChanged() 回调中的数据,然后验证收到的数据,我尝试使用以下方式发送数据

characteristics.setValue(data)
gatt.writeCharacteristic(characteristics)

但是,Android BLE 堆栈没有调用 onCharacteristicsWrite(),事实上,Android 只是挂在那里。

我尝试用 google 搜索 Android BLE,没有太多信息,只有一堆关于 BLE 堆栈不稳定的抱怨......

有帮助吗?

解决方案

来自Android BLE的每个回调都有其功能;

ondescriptorread和ondescriptorwrite

这用于写入/读取BLE设备的配置设置,某些制造商可能需要将一些数据发送到BLE设备并通过读取确认它,然后在连接到BLE设备

之前

on特征术语

这用于将数据发送到BLE设备,通常在BLE设备的数据模式下。 键入

时调用此回调
gatt.writeCharacteristic(characteristics);
.

oncharacteristicread

这用于从BLE设备读取数据 在编写此代码时调用回调

gatt.readCharacteristic(characteristics);
.

on特征突出的

当您尝试使用WriteCharactery(特性)发送数据时调用此回调,并且BLE设备响应某个值。

通常一个ble设备的特点很少,使其简单,我的名字几个特征

  • 写入 - 写特性
  • - 读取特征
要清除,当您发送数据时,您需要使用 write 特性,然后当BLE设备响应Android应用程序时将调用读取特性

要注意的一个非常重要的点是Android BLE堆栈允许您一次写一个特征!!

示例:如果您尝试在同一时间调用写特征,

gatt.writeCharacteristic(characteristics);
gatt.writeCharacteristic(characteristics);
.

android ble堆栈不会发出第二个写特性!

其他提示

setValue:characteristics.setValue(data) 你应该使用 gatt.setCharacteristicNotification(Char,true)setNotification.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top