boskokg / flutter_blue_plus

Flutter plugin for connecting and communicationg with Bluetooth Low Energy devices, on Android and iOS
Other
671 stars 419 forks source link

[Help]: PlatformException(writeCharacteristic, gatt.writeCharacteristic() returned false, null, null) #845

Closed niminui closed 3 months ago

niminui commented 3 months ago

Requirements

Have you checked this problem on the example app?

Yes

FlutterBluePlus Version

1.16.12

Flutter Version

3.16.9

What OS?

Android

OS Version

HarmonyOS 4.0.0.121

Bluetooth Module

flutter_blue_plus

What is your problem?

I encountered this issue while connecting to a ring device, but this error is not always present. Please help me.

Future<void> write(String characteristicUuid, List<int> value) async {
BluetoothCharacteristic? characteristic = _uuidManager.getCharacteristic(characteristicUuid);
await _blueToothIO.write(characteristic, value);
}
#### _blueToothIO
Future<void> write(BluetoothCharacteristic? characteristic, List<int> value) async {
await characteristic?.write(value);
}

Logs

Performing hot restart...
Syncing files to device VOG AL00...
Restarted application in 1,714ms.
I/flutter (22046): checkBlePermissions, isLocationGranted=PermissionStatus.granted
I/flutter (22046): checkBlePermissions, isBleGranted=PermissionStatus.granted
I/flutter (22046): checkBlePermissions, isBleScanGranted=PermissionStatus.granted
I/flutter (22046): checkBlePermissions, isBleConnectGranted=PermissionStatus.granted
I/flutter (22046): checkBlePermissions, isBleAdvertiseGranted=PermissionStatus.granted
D/[FBP-Android](22046): [FBP] onMethodCall: flutterHotRestart
I/BluetoothAdapter(22046): isLeEnabled(): ON
D/[FBP-Android](22046): [FBP] disconnectAllDevices
D/[FBP-Android](22046): [FBP] calling disconnect: CB:00:ED:F0:D2:D2
D/BluetoothGatt(22046): cancelOpen() - device: CB:00:ED:**:**:**
D/[FBP-Android](22046): [FBP] calling close: CB:00:ED:F0:D2:D2
D/BluetoothGatt(22046): close()
D/BluetoothGatt(22046): unregisterApp() - mClientIf=15
D/[FBP-Android](22046): [FBP] connectedPeripherals: 0
D/[FBP-Android](22046): [FBP] onMethodCall: isSupported
D/[FBP-Android](22046): [FBP] onMethodCall: turnOn
D/[FBP-Android](22046): [FBP] onMethodCall: getAdapterState
D/[FBP-Android](22046): [FBP] onMethodCall: connect
D/BluetoothGatt(22046): connect() - device: CB:00:ED:**:**:**, auto: true
D/BluetoothGatt(22046): registerApp()
D/BluetoothGatt(22046): registerApp() - UUID=34358da6-cd14-4983-abd5-b34a012c67c5
D/BluetoothGatt(22046): onClientRegistered() - status=0 clientIf=15
D/BluetoothGatt(22046): onClientConnectionState() - status=0 clientIf=15 device=CB:00:ED:**:**:**
D/[FBP-Android](22046): [FBP] onConnectionStateChange: status: 0 (SUCCESS) newState: connected
I/flutter (22046): >>>>>>> connect success ```````````````````````````
D/[FBP-Android](22046): [FBP] onMethodCall: discoverServices
D/BluetoothGatt(22046): discoverServices() - device: CB:00:ED:**:**:**
D/BluetoothGatt(22046): onConnectionUpdated() - Device=CB:00:ED:**:**:** interval=6 latency=0 timeout=500 status=0
D/BluetoothGatt(22046): onSearchComplete() = Device=CB:00:ED:**:**:** Status=0
D/[FBP-Android](22046): [FBP] onServicesDiscovered: count: 4 status: 0
I/flutter (22046):   BluetoothConnectionState  BluetoothConnectionState.connected 
D/[FBP-Android](22046): [FBP] onMethodCall: setNotification
D/BluetoothGatt(22046): setCharacteristicNotification() - uuid: 000066fe-0000-1000-8000-00805f9b34fb enable: true
D/BluetoothGatt(22046): onConnectionUpdated() - Device=CB:00:ED:**:**:** interval=40 latency=0 timeout=500 status=0
D/BluetoothGatt(22046): writeDescriptor() - uuid: 00002902-0000-1000-8000-00805f9b34fb
D/[FBP-Android](22046): [FBP] onMethodCall: writeCharacteristic
D/BluetoothGatt(22046): writeCharacteristic() - uuid: 000066fe-0000-1000-8000-00805f9b34fb
E/flutter (22046): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(writeCharacteristic, gatt.writeCharacteristic() returned false, null, null)
E/flutter (22046): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:651:7)
E/flutter (22046): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:322:18)
E/flutter (22046): <asynchronous suspension>
E/flutter (22046): #2      FlutterBluePlus._invokeMethod (package:flutter_blue_plus/src/flutter_blue_plus.dart:389:13)
E/flutter (22046): <asynchronous suspension>
E/flutter (22046): #3      BluetoothCharacteristic.write (package:flutter_blue_plus/src/bluetooth_characteristic.dart:189:7)
E/flutter (22046): <asynchronous suspension>
E/flutter (22046): #4      BlueToothIO.write (package:njsd_smart_ring/bluetooth/bluetooth_io.dart:9:5)
E/flutter (22046): <asynchronous suspension>
E/flutter (22046): #5      BlueToothManager.write (package:njsd_smart_ring/bluetooth/bluetooth_manager.dart:161:5)
E/flutter (22046): <asynchronous suspension>
E/flutter (22046): #6      BleData.sendBle (package:njsd_smart_ring/pages_data/health_data.dart:460:5)
E/flutter (22046): <asynchronous suspension>
E/flutter (22046):
chipweinberger commented 3 months ago

update your FBP version.

reopen issue if you still have problems.

niminui commented 3 months ago

The FBP has been updated to version 1.32.1, however, the issue persists. Please find below the updated log. After establishing a successful Bluetooth connection, I initiated the transmission of commands, but encountered this issue.


Performing hot restart...
Syncing files to device VOG AL00...
Restarted application in 1,619ms.
I/flutter (14624): checkBlePermissions, isLocationGranted=PermissionStatus.granted
I/flutter (14624): checkBlePermissions, isBleGranted=PermissionStatus.granted
I/flutter (14624): checkBlePermissions, isBleScanGranted=PermissionStatus.granted
I/flutter (14624): checkBlePermissions, isBleConnectGranted=PermissionStatus.granted
I/flutter (14624): checkBlePermissions, isBleAdvertiseGranted=PermissionStatus.granted
D/[FBP-Android](14624): [FBP] onMethodCall: flutterHotRestart
D/[FBP-Android](14624): [FBP] disconnectAllDevices(flutterHotRestart)
D/[FBP-Android](14624): [FBP] calling disconnect: CB:00:ED:F0:D2:D2
D/BluetoothGatt(14624): cancelOpen() - device: CB:00:ED:**:**:**
D/[FBP-Android](14624): [FBP] calling close: CB:00:ED:F0:D2:D2
D/BluetoothGatt(14624): close()
D/BluetoothGatt(14624): unregisterApp() - mClientIf=15
D/[FBP-Android](14624): [FBP] connectedPeripherals: 0
D/[FBP-Android](14624): [FBP] onMethodCall: isSupported
D/[FBP-Android](14624): [FBP] onMethodCall: turnOn
D/[FBP-Android](14624): [FBP] onMethodCall: connect
D/BluetoothGatt(14624): connect() - device: CB:00:ED:**:**:**, auto: false
D/BluetoothGatt(14624): registerApp()
D/BluetoothGatt(14624): registerApp() - UUID=1331be82-cf1c-49ac-85f0-309db0c5e3d9
D/BluetoothGatt(14624): onClientRegistered() - status=0 clientIf=15
D/BluetoothGatt(14624): onClientConnectionState() - status=0 clientIf=15 device=CB:00:ED:**:**:**
D/[FBP-Android](14624): [FBP] onConnectionStateChange:connected
D/[FBP-Android](14624): [FBP]   status: SUCCESS
D/[FBP-Android](14624): [FBP] onMethodCall: getAdapterState
D/[FBP-Android](14624): [FBP] onMethodCall: requestMtu
D/BluetoothGatt(14624): configureMTU() - device: CB:00:ED:**:**:** mtu: 512
D/BluetoothGatt(14624): onConnectionUpdated() - Device=CB:00:ED:**:**:** interval=6 latency=0 timeout=500 status=0
D/BluetoothGatt(14624): onConfigureMTU() - Device=CB:00:ED:**:**:** mtu=247 status=0
D/[FBP-Android](14624): [FBP] onMtuChanged:
D/[FBP-Android](14624): [FBP]   mtu: 247
D/[FBP-Android](14624): [FBP]   status: GATT_SUCCESS (0)
I/flutter (14624): >>>>>>> connect success ``````````````````````````````
D/[FBP-Android](14624): [FBP] onMethodCall: discoverServices
D/BluetoothGatt(14624): discoverServices() - device: CB:00:ED:**:**:**
D/BluetoothGatt(14624): onSearchComplete() = Device=CB:00:ED:**:**:** Status=0
D/[FBP-Android](14624): [FBP] onServicesDiscovered:
D/[FBP-Android](14624): [FBP]   count: 4
D/[FBP-Android](14624): [FBP]   status: 0GATT_SUCCESS
D/BluetoothGatt(14624): onConnectionUpdated() - Device=CB:00:ED:**:**:** interval=40 latency=0 timeout=500 status=0
D/[FBP-Android](14624): [FBP] onMethodCall: setNotifyValue
D/BluetoothGatt(14624): setCharacteristicNotification() - uuid: 00002a05-0000-1000-8000-00805f9b34fb enable: true
D/BluetoothGatt(14624): writeDescriptor() - uuid: 00002902-0000-1000-8000-00805f9b34fb
D/BluetoothGatt(14624): onDescriptorWrite() - Device=CB:00:ED:**:**:** handle=9
D/[FBP-Android](14624): [FBP] onDescriptorWrite:
D/[FBP-Android](14624): [FBP]   chr: 2a05
D/[FBP-Android](14624): [FBP]   desc: 2902
D/[FBP-Android](14624): [FBP]   status: GATT_SUCCESS (0)
I/flutter (14624):   BluetoothConnectionState  BluetoothConnectionState.connected 
D/[FBP-Android](14624): [FBP] onMethodCall: setNotifyValue
D/BluetoothGatt(14624): setCharacteristicNotification() - uuid: 000066fe-0000-1000-8000-00805f9b34fb enable: true
D/BluetoothGatt(14624): writeDescriptor() - uuid: 00002902-0000-1000-8000-00805f9b34fb
I/InputTransport(14624): Fun_filterMotionEvent reportMoveEvent!
W/HiTouch_PressGestureDetector(14624): Touch pointer move a lot. The moving distance of X is:17.0, limit is:60The moving distance of Y is:76.0, limit is:60
E/flutter (14624): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: FlutterBluePlusException | setNotifyValue | fbp-code: 1 | Timed out after 15s
E/flutter (14624): #0      FutureTimeout.fbpTimeout.<anonymous closure> (package:flutter_blue_plus/src/utils.dart:71:7)
E/flutter (14624): #1      _RootZone.run (dart:async/zone.dart:1655:54)
E/flutter (14624): #2      Future.timeout.<anonymous closure> (dart:async/future_impl.dart:942:34)
E/flutter (14624): #3      Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:18:15)
E/flutter (14624): #4      _Timer._runTimers (dart:isolate-patch/timer_impl.dart:398:19)
E/flutter (14624): #5      _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:429:5)
E/flutter (14624): #6      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
E/flutter (14624): 
D/[FBP-Android](14624): [FBP] onMethodCall: writeCharacteristic
D/BluetoothGatt(14624): writeCharacteristic() - uuid: 000066fe-0000-1000-8000-00805f9b34fb
E/flutter (14624): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(writeCharacteristic, gatt.writeCharacteristic() returned false, null, null)
E/flutter (14624): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:651:7)
E/flutter (14624): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:322:18)
E/flutter (14624): <asynchronous suspension>
E/flutter (14624): #2      FlutterBluePlus._invokeMethod (package:flutter_blue_plus/src/flutter_blue_plus.dart:599:13)
E/flutter (14624): <asynchronous suspension>
E/flutter (14624): #3      BluetoothCharacteristic.write (package:flutter_blue_plus/src/bluetooth_characteristic.dart:204:7)
E/flutter (14624): <asynchronous suspension>
E/flutter (14624): #4      BlueToothIO.write (package:njsd_smart_ring/bluetooth/bluetooth_io.dart:9:5)
E/flutter (14624): <asynchronous suspension>
E/flutter (14624): #5      BlueToothManager.write (package:njsd_smart_ring/bluetooth/bluetooth_manager.dart:161:5)
E/flutter (14624): <asynchronous suspension>
E/flutter (14624): #6      BleData.sendBle (package:njsd_smart_ring/pages_data/health_data.dart:460:5)
E/flutter (14624): <asynchronous suspension>
E/flutter (14624): 
D/[FBP-Android](14624): [FBP] onMethodCall: writeCharacteristic
D/BluetoothGatt(14624): writeCharacteristic() - uuid: 000066fe-0000-1000-8000-00805f9b34fb
E/flutter (14624): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(writeCharacteristic, gatt.writeCharacteristic() returned false, null, null)
E/flutter (14624): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:651:7)
E/flutter (14624): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:322:18)
E/flutter (14624): <asynchronous suspension>
E/flutter (14624): #2      FlutterBluePlus._invokeMethod (package:flutter_blue_plus/src/flutter_blue_plus.dart:599:13)
E/flutter (14624): <asynchronous suspension>
E/flutter (14624): #3      BluetoothCharacteristic.write (package:flutter_blue_plus/src/bluetooth_characteristic.dart:204:7)
E/flutter (14624): <asynchronous suspension>
E/flutter (14624): #4      BlueToothIO.write (package:njsd_smart_ring/bluetooth/bluetooth_io.dart:9:5)
E/flutter (14624): <asynchronous suspension>
E/flutter (14624): #5      BlueToothManager.write (package:njsd_smart_ring/bluetooth/bluetooth_manager.dart:161:5)
E/flutter (14624): <asynchronous suspension>
E/flutter (14624): #6      BleData.sendBle (package:njsd_smart_ring/pages_data/health_data.dart:460:5)
E/flutter (14624): <asynchronous suspension>
E/flutter (14624): 
niminui commented 3 months ago

I have just restarted the mobile device, this problem has been solved, more confused, this may be caused by what