【问题标题】:Finishing Bluetooth communication from Android with BLE device完成 Android 与 BLE 设备的蓝牙通信
【发布时间】:2018-01-23 10:06:56
【问题描述】:

从带有外围测量设备的 Android 设备完成 BLE 通信的正确方法是什么?

当前状态:

  1. 如果我对收到的感到满意;写停止测量特性
  2. 写关机请求
  3. 取消订阅 RxBleConnection
  4. 关闭和断开 BluetoothGatt

当前解决方案的问题是,即使我断开并关闭 GATT,它仍然会在设备上再保持连接 30 秒。 (下一次测量不能立即开始)

更新日志:

D/RxBle#ConnectionOperationQueue:   QUEUED CharacteristicWriteOperation(222504075)
D/RxBle#ConnectionOperationQueue:  STARTED CharacteristicWriteOperation(222504075)
I/RxBle#ConnectionOperationQueue: Connection operations queue to be terminated (80:EA:CA:00:00:10)
D/RxBle#ClientOperationQueue:   QUEUED DisconnectOperation(90705849)
D/RxBle#ClientOperationQueue:  STARTED DisconnectOperation(90705849)
D/BluetoothManager: getConnectionState()
D/BluetoothManager: getConnectedDevices
D/BluetoothGatt: cancelOpen() - device: 80:EA:CA:00:00:10
D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=6 device=80:EA:CA:00:00:10
D/RxBle#BluetoothGatt: onConnectionStateChange newState=0 status=0
D/BluetoothGatt: setCharacteristicNotification() - uuid: 3f3e3d3c-3b3a-3938-3736-353433323130 enable: false
E/TestConnection: changeNotificationDisconnected from 80:EA:CA:00:00:10
D/RxBle#ConnectionOperationQueue: FINISHED CharacteristicWriteOperation(222504075)
D/RxBle#Executors$RunnableAdapter: Terminated.
D/BluetoothGatt: close()
D/BluetoothGatt: unregisterApp() - mClientIf=6
D/RxBle#ClientOperationQueue: FINISHED DisconnectOperation(90705849)

【问题讨论】:

  • 通常断开连接(从RxBleDevice.establishConnection()退订)足以完成通信。您似乎希望获得一些不同的结果,例如通过 BLE 命令关闭设备。您的外围设备似乎在没有正确关闭连接的情况下关闭电源,导致 Android 在监督超时后超时。你能展示你的代码和应用程​​序的日志吗?
  • @DariuszSeweryn 用日志更新了帖子。操作 (222504075) 关闭设备。它有效,尽管它从未完成。在代码中,我在几秒钟后超时,所以我避免了默认的 20 秒超时。在 iOS 上,由于不同的 Gatt 实现,这个过程可以正常工作。 :)

标签: android bluetooth bluetooth-lowenergy android-bluetooth rxandroidble


【解决方案1】:

你的方法很好。

问题似乎出在您的外围设备上。它似乎没有发送任何信息表明它正在关闭。如果在外设端正确实施,BluetoothGattCallback 应该收到.onConnectionStateChange()status=19 其中corresponds to

#define GATT_CONN_TERMINATE_PEER_USER       HCI_ERR_PEER_USER               /* 0x13 connection terminate by peer user  */

因为并非如此,Android BLE 堆栈认为通信已停止,它会等待监督超时启动。默认情况下,Supervision Timeout is hardcoded 20 seconds

虽然可以减少监督超时,但它需要由外围设备协商,因此必须对固件进行干预。如果这是必须的,那么适当关闭连接也是一种选择。

【讨论】:

  • 感谢您的回答,也感谢您的时间。 :) 我是这么想的,但我很高兴你证实了这一点。也许这会在将来对某人有所帮助。
猜你喜欢
  • 1970-01-01
  • 2017-08-19
  • 1970-01-01
  • 2012-02-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-04
  • 1970-01-01
相关资源
最近更新 更多