Android Nordic 蓝牙 GATT 超时 Thingy:52
Android Bluetooth GATT timetout with Nordic Thingy:52
我有一个 android 应用程序,在通过库 (thingylib) 连接到 thingy52 后:
BluetoothDevice dev = scanResultList.get(nordicDeviceEntityList.get(pos).getAddress());
thingySdkManager.connectToThingy(getContext(), device, BaseTService.class);
我想读取北欧 thingy:52 数据以及 RSSI 值,所以在另一个 activity 中,当我想收集数据时,我附加了一个新的蓝牙 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 的加速度计事件回调中,我获取数据并调用 GATT 以检索 RSSI 值:
@Override
public void onAccelerometerValueChangedEvent(BluetoothDevice bluetoothDevice, float x, float y, float z) {
gatt.readRemoteRssi();
}
我发现的问题是几秒钟后(不确定,有时是 5/10 秒)设备断开连接并出现 GATT 错误 8(超时错误)。如果我在收集数据之前删除 GATT link,设备不会断开连接并且可以正常工作。
我想知道是否有办法防止连接的 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
问题似乎出在设备的固件方面,如 github 问题所示:https://github.com/NordicSemiconductor/Android-Nordic-Thingy/issues/22
我有一个 android 应用程序,在通过库 (thingylib) 连接到 thingy52 后:
BluetoothDevice dev = scanResultList.get(nordicDeviceEntityList.get(pos).getAddress());
thingySdkManager.connectToThingy(getContext(), device, BaseTService.class);
我想读取北欧 thingy:52 数据以及 RSSI 值,所以在另一个 activity 中,当我想收集数据时,我附加了一个新的蓝牙 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 的加速度计事件回调中,我获取数据并调用 GATT 以检索 RSSI 值:
@Override
public void onAccelerometerValueChangedEvent(BluetoothDevice bluetoothDevice, float x, float y, float z) {
gatt.readRemoteRssi();
}
我发现的问题是几秒钟后(不确定,有时是 5/10 秒)设备断开连接并出现 GATT 错误 8(超时错误)。如果我在收集数据之前删除 GATT link,设备不会断开连接并且可以正常工作。 我想知道是否有办法防止连接的 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
问题似乎出在设备的固件方面,如 github 问题所示:https://github.com/NordicSemiconductor/Android-Nordic-Thingy/issues/22