我有一个安卓应用程序,通过库(Thingylib)连接到thingy52后:
BluetoothDevice dev = scanResultList.get(nordicDeviceEntityList.get(pos).getAddress());
thingySdkManager.connectToThingy(getContext(), device, BaseTService.class);我想要读取北欧thingy:52数据和RSSI值,因此在另一个活动中,当我想要收集数据时,我附加了一个新的蓝牙GATT:
private void startDataCollection() {
for (BluetoothDevice dev : thingySdkManager.getConnectedDevices()){
thingySdkManager.setConstantLedMode(dev, 1, 100, 1);
ThingyListenerHelper.registerThingyListener(getApplicationContext(), mThingyListener, dev);
//e vents
thingySdkManager.enableMotionNotifications(dev, true);
gatt = dev.connectGatt(getApplicationContext(), true, gattCallback);
}
}之后,在thingylib的Accellerometer事件回调中,我获取数据并调用GATT来检索RSSI值:
@Override
public void onAccelerometerValueChangedEvent(BluetoothDevice bluetoothDevice, float x, float y, float z) {
gatt.readRemoteRssi();
}我发现的问题是,几秒钟后(不确定,有时是5/10s),设备断开连接,GATT上出现错误8(超时错误)。如果我在收集数据之前删除GATT链接,设备不会断开连接,并且工作正常。我想知道是否有一种方法可以防止连接的GATT超时或我做错了什么。
我的android日志:
2020-04-02 13:00:16.607 15336-15396/it.chiarani.beacon_detection D/BluetoothGatt: onClientConnectionState() - status=8 clientIf=9 device=F5:EF:EE:8B:92:7C
2020-04-02 13:00:16.609 15336-15380/it.chiarani.beacon_detection D/BluetoothGatt: onClientConnectionState() - status=8 clientIf=11 device=F5:EF:EE:8B:92:7C
2020-04-02 13:00:16.609 15336-15654/it.chiarani.beacon_detection D/BluetoothGatt: onClientConnectionState() - status=8 clientIf=10 device=F5:EF:EE:8B:92:7C
2020-04-02 13:00:16.610 15336-15654/it.chiarani.beacon_detection V/ThingyConnection: Error 8 : F5:EF:EE:8B:92:7C
2020-04-02 13:00:16.611 15336-15654/it.chiarani.beacon_detection D/BluetoothGatt: close()
2020-04-02 13:00:16.611 15336-15654/it.chiarani.beacon_detection D/BluetoothGatt: unregisterApp() - mClientIf=10
2020-04-02 13:00:16.670 15336-15336/it.chiarani.beacon_detection V/ViewRootImpl: The specified message queue synchronization barrier token has not been posted or has already been removed发布于 2020-12-16 19:38:11
问题似乎出在设备的固件方面,就像github问题所指出的那样:https://github.com/NordicSemiconductor/Android-Nordic-Thingy/issues/22
https://stackoverflow.com/questions/60990978
复制相似问题