[英]Android BLE GATT write data is not being received by BLE Peripheral despite GATT_SUCCESS
After writing, onCharacteristicWrite()
gets called with the status BluetoothGatt.GATT_SUCCESS
, but I don't actually see it on my peripheral.写入后, onCharacteristicWrite()
被调用,状态为BluetoothGatt.GATT_SUCCESS
,但我实际上并没有在我的外围设备上看到它。
I know the issue isn't on the peripheral because it works when I use a generic BLE Scanner app.我知道问题不在外围设备上,因为它在我使用通用 BLE 扫描仪应用程序时有效。
This is what my writeCharacteristic
function looks like:这就是我的writeCharacteristic
函数的样子:
fun writeCharacteristic(characteristic: BluetoothGattCharacteristic, value: String) {
characteristic.writeType = BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT
characteristic.setValue(value)
bluetoothGatt?.writeCharacteristic(characteristic)
?: run {
Log.w(TAG, "BluetoothGatt not initialized")
}
}
I've tried using a String or a ByteArray as the payload.我尝试使用 String 或 ByteArray 作为有效负载。 I've also tried adding the operation to a queue.我也尝试将操作添加到队列中。
The issue remains the same.问题仍然相同。
Well the success status is only reported after the peripheral has actually sent back a Write Response.那么只有在外围设备实际发送回写响应后才会报告成功状态。
So either you write to the wrong characteristic, the wrong device, or you are not correctly detecting at the peripheral when an incoming write has been received.因此,要么您写入错误的特征、错误的设备,要么您在接收到传入写入时未在外围设备上正确检测。
One way to debug this is to use the hci snoop log in Android, or using a BLE sniffer.调试此问题的一种方法是使用 Android 中的 hci snoop 日志,或使用 BLE 嗅探器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.