我正在连接一个已发现的设备,并定期读取RSSI。我需要知道连接中断的确切时间。有没有办法指定连接超时,在超时后我会收到RxBleConnectionState.DISCONNECTED?现在,即使连接的设备关机,我仍然收到来自rxBleConnection.readRssi()的rssi。
我是否应该使用邻近蓝牙配置文件中的链路丢失服务,而不是连接超时?
我的代码:
device1ConnectionSubscription = device.establishConnection(false)
.doOnUnsubscribe(this::clearDevice1Subscription)
.observeOn(AndroidSchedulers.mainThread())
.flatMap(rxBleConnection ->
Observable.interval(500, TimeUnit.MILLISECONDS)
.flatMap(sequence -> rxBleConnection.readRssi())
.observeOn(AndroidSchedulers.mainThread())
)
.subscribe(this::updateDevice1Rssi, this::onConnectionFailure);
device1ConnectionStateChangesSubscription = device.observeConnectionStateChanges()
.doOnUnsubscribe(() -> device1ConnectionStateChangesSubscription = null)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
connectionState -> {
switch(connectionState)
{
case DISCONNECTING:
case DISCONNECTED:
if(device1ConnectionSubscription != null) {
device1ConnectionSubscription.unsubscribe();
}
device1ConnectionStateChangesSubscription.unsubscribe();
break;
}
},
throwable -> { }
);发布于 2017-08-22 15:42:54
您要查找的参数是Connection supervision timeout。此参数由设备控制,我想,不能在您的手机上设置。
https://stackoverflow.com/questions/45811493
复制相似问题