- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 rxandroidble 使用 autoconnect = true 来持续监控来自传感器的数据。该应用会持续扫描它之前连接过的传感器。
即使手机未连接电源,传感器的数据监控和扫描也应持续整夜。
如果传感器在晚上连接,应用程序将整晚保持连接状态,即使它暂时断开连接也是如此。
但是,如果传感器在夜间断开连接 6 小时(因为我拔掉了传感器的电池),然后在早上重新连接传感器电池,手机似乎不会重新连接到传感器。
我每 8 秒不断扫描一次 Android 服务中的新传感器,但它不是 WakefulService,也不是由 WakefulIntent 启动的。应该吗?
知道会发生什么吗? rxandroidble 是否设计为在这种情况下继续扫描传感器(ble 设备连接,超出范围 8 小时,然后返回范围内)?或者我需要在断开连接后手动尝试重新连接,然后 rxandroid 会不断尝试重新连接。
这是我的扫码:
public boolean scanForDevices(boolean on){
if(on){
if (!mBluetoothAdapter.isEnabled()) {
Log.e(TAG, "scanForDevices: bluetooth not enabled, scan failed" );
return false; // bluetooth disabled
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (TheApplication.getInstance().checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
Log.e(TAG, "scanForDevices: ACCESS_COARSE_LOCATION permission not granted, scan failed" );
return false; // App doesn't have permission granted
}
}
if (isScanning()) {
scanSubscription.unsubscribe();
} else {
scanSubscription = RxBleClientSingleton.getInstance().getRxBleClient().scanBleDevices()
.observeOn(AndroidSchedulers.mainThread())
.doOnError(this::onScanFailure)
.doOnUnsubscribe(this::clearSubscription)
.subscribe(this::onScanResult, this::onScanFailure);
//Ensure we won't Scan forever (save battery)
if (EnablePeriodicScan == true) {
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (isScanning())
scanForDevices(false);
}
}, 4000);
}
}
}else{
//Turn scanning off
if(isScanning()){
scanSubscription.unsubscribe();
}
}
return true;
}
这是我的连接代码:
public void RxBleConnect() {
autoConnectSetting = true;
if (false == sensorConnectionState.equals(SensorConnectionState.Disconnected)) {
Log.d(TAG, "RxBleConnect: cannot connect, #" + allowReconnect + " : " + macAddress + " isn't disconnected, currently in " + sensorConnectionState.toString() );
if ((sensorConnectionState.equals(SensorConnectionState.Connected)) && (allowReconnect > 15)) { /// reached our limit even though we are connected?
allowReconnect = 0; // reset count
Disconnect(); // disconnect sensor.
Log.d(TAG, "RxBleConnect: someone keeps knocking, appears that " + macAddress + " isn't as connected as we thought.");
}
allowReconnect ++;
return; // dont reattempt connection if already attempting to connect
}
Log.d(TAG, "RxBleConnect: connecting to sensor....");
SystemClock.sleep(400);
connectionObservable =
bleDevice.establishConnection(TheApplication.getInstance(), autoConnectSetting)
.compose(new ConnectionSharingAdapter())
.observeOn(AndroidSchedulers.mainThread())
.doOnUnsubscribe(this::RxBleDisconnect)
.takeUntil(disconnectTriggerSubject)
.doOnError(throwable -> {
Log.d(TAG, "rxBleConnection doOnError: " + throwable);
Disconnect(); // triggerDisconnect();
});
connectionSubscription = connectionObservable
.flatMap(RxBleConnection::discoverServices)
.subscribe(this::RxBleOnConnectionReceived, this::RxBleOnConnectionFailure);
}
如果连接状态变为断开连接,我不会尝试手动重新连接;扫描或自动连接应该解决这个问题吧?
我已经在 Android 电池设置中为应用程序关闭了“应用程序优化”又名打瞌睡模式,但我不知道这是否有任何作用。
EDIT 1: Here are my logs.... we connect ok the first time, then we attempt connecting, then we immediately disconnect:
>>> FIRST CONNECTION <<<
12-09 21:23:46.904 8992-8992/appName D/PeripheralManager: RxBleConnect: connecting to sensor...., auto connect = false
onConnectionStateChange newState=2 status=0
12-09 21:23:09.298 8992-8992/appName D/PeripheralManager: onConnectionStateChange: new state RxBleConnectionState{CONNECTED}
12-09 21:23:46.831 8992-9004/appName D/BluetoothGatt: onClientConnectionState() - status=8 clientIf=5 device=E0:CF:8D:98:69:6A
12-09 21:23:46.832 8992-9004/appName D/RxBle#BluetoothGatt: onConnectionStateChange newState=0 status=8
12-09 21:23:46.897 8992-8992/appName D/PeripheralManager: onConnectionStateChange: new state RxBleConnectionState{DISCONNECTED}
12-09 21:23:46.897 8992-8992/appName D/Peripheral Manager: setConnectionState: Set e0:cf:8d:98:69:6a connection state to Disconnected
12-09 21:23:46.898 8992-8992/appName E/PeripheralManager: ### sendDisconnectNotification: mid = 2698601
>>> ATTEMPT RECONNECT HERE <<<<
12-09 21:23:46.904 8992-8992/appName D/PeripheralManager: RxBleConnect: connecting to sensor...., auto connect = true
12-09 21:23:46.915 8992-9004/appName D/RxBle#Radio: QUEUED RxBleRadioOperationDisconnect(250971465)
12-09 21:23:46.916 8992-9070/appName D/RxBle#Radio: STARTED RxBleRadioOperationDisconnect(250971465)
12-09 21:23:46.922 8992-9004/appName D/BluetoothGatt: setCharacteristicNotification() - uuid: f8c00003-159f-11e6-92f5-0002a5d5c51b enable: false
12-09 21:23:46.928 8992-9004/appName D/RxBle#Radio: QUEUED RxBleRadioOperationDescriptorWrite(49261423)
12-09 21:23:47.306 8992-8992/appName D/RxBle#Radio: QUEUED RxBleRadioOperationConnect(200794900)
12-09 21:23:47.316 8992-8992/appName D/PeripheralManager: onConnectionStateChange: new state RxBleConnectionState{CONNECTING}
12-09 21:23:47.316 8992-8992/appName D/Peripheral Manager: setConnectionState: Set e0:cf:8d:98:69:6a connection state to Connecting…
12-09 21:23:47.340 8992-8992/appName D/BluetoothManager: getConnectionState()
12-09 21:23:47.340 8992-8992/appName D/BluetoothManager: getConnectedDevices
12-09 21:23:47.347 8992-9070/appName D/RxBle#Radio: FINISHED RxBleRadioOperationDisconnect(250971465)
12-09 21:23:47.348 8992-9070/appName D/RxBle#Radio: STARTED RxBleRadioOperationDescriptorWrite(49261423)
12-09 21:23:47.348 8992-8992/appName D/PeripheralManager: rxBleConnection doOnError: BleGattException{status=8, bleGattOperation=BleGattOperation{description='CONNECTION_STATE'}}
12-09 21:23:47.355 8992-8992/appName D/PeripheralManager: observeConnectionStateChanges FINISHED
12-09 21:23:47.355 8992-8992/appName D/PeripheralManager: rxBleConnection doOnError: BleGattException{status=8, bleGattOperation=BleGattOperation{description='CONNECTION_STATE'}}
谢谢!
2nd EDIT:
消费代码
私有(private)无效 RxBleOnConnectionReceived(RxBleDeviceServices 服务){ //发现服务
connectionsCount ++;
Log.d(TAG, "RxBleOnConnectionReceived: Discovered services");
setConnectionState(SensorConnectionState.Connected);
try {
connectionSubscription = connectionObservable
.flatMap(rxBleConnection -> rxBleConnection.setupNotification(BluetoothLeUart.RX_UUID))
.doOnError(throwable -> {
Log.d(TAG, "RxBleOnConnectionReceived setupNotification doOnError: " + throwable);
Disconnect();
})
.doOnNext(notificationObservable -> {
// Notification has been set up
})
.flatMap(notificationObservable -> notificationObservable) // <-- Notification has been set up, now observe value changes.
.observeOn(AndroidSchedulers.mainThread())
.doOnError(throwable -> {
Log.d(TAG, "RxBleOnConnectionReceived doOnError: " + throwable);
})
.subscribe(
bytes -> {
// Given characteristic has been changes, here is the value.
processReceivedMessage(bytes);
},
throwable -> {
/*handle throwable*/
Log.e(TAG, "RxBleOnConnectionReceived: processReceivedMessage: " + throwable );
}
);
最佳答案
你问了几个问题:
这是一个关于 stackoverflow 的好问题。例如这里:How does doze mode affect background/foreground services, with/without partial/full wakelocks? Cordova 插件 github 页面中还有一个关于在打瞌睡期间使用 BLE 的问题:https://github.com/thaliproject/Thali_CordovaPlugin/issues/413
RxAndroidBle
是否应该在设备断开连接时自动重新连接?没有。连接结束后(无论它是使用 autoconnect
= true 还是 false 启动的)都必须通过再次调用 RxBleDevice.establishConnection
重新建立连接。来自图书馆的描述:
Auto connect
(...)
Auto connect concept may be misleading at first glance. With the autoconnect flag set to false the connection will end up with an error if a BLE device is not advertising when the RxBleDevice#establishConnection method is called. From platform to platform timeout after which the error is emitted differs, but in general it is rather tens of seconds than single seconds.
Setting the auto connect flag to true allows you to wait until the BLE device becomes discoverable. The RxBleConnection instance won't be emitted until the connection is fully set up. From experience it also handles acquiring wake locks, so it's safe to assume that your Android device will be woken up after the connection has been established - but it is not a documented feature and may change in the future system releases.
autoconnect = true
是否会负责重新连接?很难推断是什么触发了 scanForDevices()
函数,但看起来它会在 4 秒后自动完成。如果扫描打开并且用户将调用 scanForDevices(true)
,则无论如何都会停止扫描。
关于android - rxandroidble:ble 设备长时间断开连接:应用程序进入休眠状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40903276/
我正在开发一个使用 BLE Android 到 iOS 的聊天应用程序,现在我正在使用下面两个库作为引用 https://github.com/izumin5210/Bletia https://gi
我正在从 HCI 套接字接收 EVT_LE_ADVERTISING_REPORT。我想区分 BLE 信标和普通 BLE 设备(解析设备名称等)我有点困惑是否所有 BLE 设备都会发出信标或者它们是不同
我正在从 HCI 套接字接收 EVT_LE_ADVERTISING_REPORT。我想区分 BLE 信标和普通 BLE 设备(解析设备名称等)我有点困惑是否所有 BLE 设备都会发出信标或者它们是不同
我在我的 iOS 应用程序项目中使用核心蓝牙框架。我有以下关于蓝牙低功耗的问题 - iOS 中单个中央设备是否可以连接多个外围设备? 多个中央设备可以与单个外围设备连接吗? 单个 iOS 设备可以同时
我正在创建一个 iOS 和一个 Android 应用程序,它们从蓝牙传感器读取一些数据并将它们保存在数据库中。 即使应用程序终止,我也想提供保存传感器数据的能力。 仅供引用。当应用程序在后台时,我已经
我正在使用核心蓝牙框架并扫描一些设备,例如 micromax A250、micromax A116、samsung grand neo、HTC 610 和 ipod 5s,然后我无法扫描 samsun
这个任务的目的是通过BLE设备连接iPhone的BLE,访问iphone的ANCS。请注意,iPhone 中没有安装应用程序来打开 iPhone 的 BLE。那么,如果我们从 iPhone 设置中启用
我在为我的 BLE 设备开发安卓软件时遇到了问题。我的软件可以找到我的设备和 GATT 服务,但在我的服务中找不到任何特征。 我检查了 android-sdk-4.4.2 源码,找到了一些代码。 ht
有什么方法可以从 BleExplr、LightBlue 等通用 BLE 扫描应用程序中隐藏 BLE 设备? 最佳答案 您可以配置外围设备以使用服务请求。在这种模式下,中央为它们提供服务和外设扫描 -
我有 3 个组件。 Activity1 有连接和断开 BLE 连接的按钮 Activity2 需要从 BLE 设备获取数据。 Service 所有连接逻辑(如 getRemoteDevice()、co
我有一个 BLE 设备,它在通过相当标准的用户界面(点击 UITableView 中显示的设备条目)选择后连接到 iOS 设备。 连接非常简单 - 一些内部处理,然后调用 CBCentralManag
我正在尝试使用 Meteor 和这个 Cordova 插件 - https://github.com/don/cordova-plugin-ble-central - 使用 meteor add co
我坚持在 Android Lollipop 智能手机和 BLE 设备(带有 BLE 模块的 TI 实验板)之间实现连接。我使用以下调用进行连接: device.connectGatt(context,
我正在使用 react-native-ble-plx 在我的应用程序中实现蓝牙 蓝牙扫描工作正常,但它在 android 中包含重复项,而在 iOS 中工作正常,因为 allowDuplicates
我正在尝试在我的 Windows 笔记本电脑上设置一个基于 Nodejs 的演示,并使用额外的 BLE 适配器将我的笔记本电脑连接到另一个 BLE 设备 (Anki Overdrive)。我在互联网上
我正在研究基于 Android 的 BLE 接近感应功能,需要一些信息。目前我看到没有适用于 android 的 BLE 信标制造商。到目前为止,我为 iPhone 找到了 2 个。1) http:/
我正在使用 cordova 和 BLE 插件开发一个应用程序。我想通过 BLE 根据硬编码的已知 device.name 自动连接到 ESP32,而无需用户按下连接按钮。 我的想法是: 在设备准备就绪
我正在尝试实现从/向蓝牙设备接收和发送消息的模块。 我一直在寻找可以通过蓝牙搜索、连接和发送消息的 NuGet 包,但找不到适用于 Linux 的任何东西。 我正在使用 .NET Core 2.1 和
我正在尝试寻找一种方法来了解如何在 iOS 中获取 BLE mac??? 这将适用于所有 BLE,不会存在制造商依赖性。我们正在寻找扫描时间的解决方案。我可以在扫描时间内区分 BLE 吗? 如果获取M
我已阅读技术规范并试图了解为什么 BLE 4.2 比 BLE 4.1 更快? 我们能否发送大于 20 字节的数据包或者连接间隔是否更快? 我想了解是什么让 BLE 4.2 更快。 最佳答案 与早期相比
我是一名优秀的程序员,十分优秀!