我正在连接到发现的设备并定期读取 RSSI。我需要确切地知道连接何时丢失。有什么方法可以指定连接超时,之后我会收到RxBleConnectionState.DISCONNECTED
吗?rxBleConnection.readRssi()
现在,即使连接的设备已关闭,我仍然会收到 rssi 。
我应该使用 Proximity 蓝牙配置文件中的 Link Loss 服务而不是连接超时吗?
我的代码:
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 -> { }
);