FlutterBleLib icon indicating copy to clipboard operation
FlutterBleLib copied to clipboard

Could not write to the right characteristic

Open NailAgliev opened this issue 5 years ago • 5 comments

I have two different services with different UUIDs that have characteristics with the same UUIDs.

  var chars1 = await peripheral.characteristics(SERVICE1);
  var chars2 = await peripheral.characteristics(SERVICE2);

  var char1 = chars1.firstWhere((element) => element.uuid == MY_CHAR);
  var char2 = chars2.firstWhere((element) => element.uuid == MY_CHAR);

Write to the first service characteristic everything works as expected. Trying to write to second service characteristic results in data will be received in the first characteristic and most of the time data is corrupted.

  await char1.write(Uint8List.fromList([1]), false); //works as expected
  await char2.write(Uint8List.fromList([2]), false); //<-- data will go to char1

NailAgliev avatar Sep 16 '20 13:09 NailAgliev

Hi!

Is it iOS, Android or both?

Can you set log level to verbose and confirm it there? Logs (look through Logcat/XCode, those logged in Flutter run do not contain everything) should print all the data about the characteristic they're writing with.

Can you see whether going through peripheral.services().firstWhere(<your service>).characteristics().firstWhere(<your characteristic>) provides the same result?

Can you compare id (or _id) of both characteristic in the debugger and see what's the reported service for both?

Unfortunately I don't really have time for the library right now and we're stretched thin, but perhaps a temporary workaround with going the long way will work for now.

mikolak avatar Sep 16 '20 15:09 mikolak

I'll check IOS

NailAgliev avatar Sep 16 '20 18:09 NailAgliev

peripheral.services().firstWhere(<your service>).characteristics().firstWhere(<your characteristic>) provides the same result.

There is logcat output

-------------------------------------------------------------------------

Primary Service - Generic Attribute (00001801-0000-1000-8000-00805f9b34fb)
Instance ID: 1
-> Characteristics:
	* Service Changed (00002a05-0000-1000-8000-00805f9b34fb)
	  Properties: [ INDICATE ]
	  -> Descriptors: 
		* Client Characteristic Configuration (00002902-0000-1000-8000-00805f9b34fb)

Primary Service - Generic Access (00001800-0000-1000-8000-00805f9b34fb)
Instance ID: 20
-> Characteristics:
	* Device Name (00002a00-0000-1000-8000-00805f9b34fb)
	  Properties: [ READ ]
	* Appearance (00002a01-0000-1000-8000-00805f9b34fb)
	  Properties: [ READ ]
	* Central Address Resolution (00002aa6-0000-1000-8000-00805f9b34fb)
	  Properties: [ READ ]

Primary Service - Weight Scale (0000181d-0000-1000-8000-00805f9b34fb)
Instance ID: 40
-> Characteristics:
	* Weight (00002a98-0000-1000-8000-00805f9b34fb)
	  Properties: [ READ NOTIFY ]
	  -> Descriptors: 
		* Client Characteristic Configuration (00002902-0000-1000-8000-00805f9b34fb)

Primary Service - Unknown service (db3e25d0-79e9-48fa-a2c3-facc90a3d437)
Instance ID: 55
-> Characteristics:
	* Unknown characteristic (db3e25d1-79e9-48fa-a2c3-facc90a3d437)
	  Properties: [ WRITE NOTIFY ]
	  -> Descriptors: 
		* Client Characteristic Configuration (00002902-0000-1000-8000-00805f9b34fb)

Primary Service - Unknown service (db3e25d6-79e9-48fa-a2c3-facc90a3d437)
Instance ID: 70
-> Characteristics:
	* Unknown characteristic (db3e25d7-79e9-48fa-a2c3-facc90a3d437)
	  Properties: [ WRITE NOTIFY ]
	  -> Descriptors: 
		* Client Characteristic Configuration (00002902-0000-1000-8000-00805f9b34fb)

Primary Service - Unknown service (6e400001-b5a3-f393-e0a9-e50e24dcca9e)
Instance ID: 85
-> Characteristics:
	* Unknown characteristic (6e400003-b5a3-f393-e0a9-e50e24dcca9e)
	  Properties: [ WRITE NOTIFY ]
	  -> Descriptors: 
		* Client Characteristic Configuration (00002902-0000-1000-8000-00805f9b34fb)
	* Unknown characteristic (db3e25d3-79e9-48fa-a2c3-facc90a3d437)
	  Properties: [ WRITE NOTIFY ]
	  -> Descriptors: 
		* Client Characteristic Configuration (00002902-0000-1000-8000-00805f9b34fb)
	* Unknown characteristic (db3e25d4-79e9-48fa-a2c3-facc90a3d437)
	  Properties: [ WRITE NOTIFY ]
	  -> Descriptors: 
		* Client Characteristic Configuration (00002902-0000-1000-8000-00805f9b34fb)

Primary Service - Unknown service (db3e25d5-79e9-48fa-a2c3-facc90a3d437)
Instance ID: 100
-> Characteristics:
	* Unknown characteristic (db3e25d1-79e9-48fa-a2c3-facc90a3d437)
	  Properties: [ WRITE NOTIFY ]
	  -> Descriptors: 
		* Client Characteristic Configuration (00002902-0000-1000-8000-00805f9b34fb)
--------------- ====== Finished peripheral content ====== ---------------

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I/flutter: write to 1s
D/BluetoothGatt: onConnectionUpdated() - Device=F0:08:D1:D2:E2:E2 interval=39 latency=0 timeout=500 status=0
D/BluetoothGatt: setCharacteristicNotification() - uuid: db3e25d7-79e9-48fa-a2c3-facc90a3d437 enable: true
W/u.flutter_scal: Accessing hidden method Lsun/misc/Unsafe;->getObjectVolatile(Ljava/lang/Object;J)Ljava/lang/Object; (greylist, linking, allowed)
D/RxBle#ConnectionOperationQueue: QUEUED   DescriptorWriteOperation(2411625)
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin: on native side observed method: writeCharacteristicForIdentifier
D/RxBle#ConnectionOperationQueue: STARTED  DescriptorWriteOperation(2411625)
D/RxBle#ConnectionOperationQueue: QUEUED   CharacteristicWriteOperation(16110586)
W/u.flutter_scal: Accessing hidden method Lsun/misc/Unsafe;->getObjectVolatile(Ljava/lang/Object;J)Ljava/lang/Object; (greylist, linking, allowed)
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin: on native side observed method: monitorCharacteristicForIdentifier
D/BluetoothGatt: setCharacteristicNotification() - uuid: 00002a98-0000-1000-8000-00805f9b34fb enable: true
W/u.flutter_scal: Accessing hidden method Lsun/misc/Unsafe;->getObjectVolatile(Ljava/lang/Object;J)Ljava/lang/Object; (greylist, linking, allowed)
D/RxBle#ConnectionOperationQueue: QUEUED   DescriptorWriteOperation(8831607)
D/RxBle#BluetoothGatt$1: onDescriptorWrite descriptor=00002902-0000-1000-8000-00805f9b34fb status=0
W/u.flutter_scal: Accessing hidden method Lsun/misc/Unsafe;->getObjectVolatile(Ljava/lang/Object;J)Ljava/lang/Object; (greylist, linking, allowed)
W/u.flutter_scal: Accessing hidden method Lsun/misc/Unsafe;->getObjectVolatile(Ljava/lang/Object;J)Ljava/lang/Object; (greylist, linking, allowed)
D/RxBle#ConnectionOperationQueue: FINISHED DescriptorWriteOperation(2411625) in 240 ms
D/RxBle#ConnectionOperationQueue: STARTED  CharacteristicWriteOperation(16110586)
D/RxBle#BluetoothGatt$1: onCharacteristicWrite characteristic=db3e25d1-79e9-48fa-a2c3-facc90a3d437 status=0
V/RxBle#BleModule: Write to Characteristic(uuid: db3e25d1-79e9-48fa-a2c3-facc90a3d437, id: 12, value: 56)
D/RxBle#ConnectionOperationQueue: FINISHED CharacteristicWriteOperation(16110586) in 7 ms
D/RxBle#ConnectionOperationQueue: STARTED  DescriptorWriteOperation(8831607)
W/u.flutter_scal: Accessing hidden method Lsun/misc/Unsafe;->getObjectVolatile(Ljava/lang/Object;J)Ljava/lang/Object; (greylist, linking, allowed)
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin: on native side observed method: services
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin: on native side observed method: characteristicsForService
I/flutter: write to 2nd
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin: on native side observed method: writeCharacteristicForIdentifier
D/RxBle#ConnectionOperationQueue: QUEUED   CharacteristicWriteOperation(254389343)
D/RxBle#BluetoothGatt$1: onDescriptorWrite descriptor=00002902-0000-1000-8000-00805f9b34fb status=0
W/u.flutter_scal: Accessing hidden method Lsun/misc/Unsafe;->getObjectVolatile(Ljava/lang/Object;J)Ljava/lang/Object; (greylist, linking, allowed)
D/RxBle#ConnectionOperationQueue: FINISHED DescriptorWriteOperation(8831607) in 89 ms
D/RxBle#ConnectionOperationQueue: STARTED  CharacteristicWriteOperation(254389343)
D/RxBle#BluetoothGatt$1: onCharacteristicWrite characteristic=db3e25d1-79e9-48fa-a2c3-facc90a3d437 status=0
V/RxBle#BleModule: Write to Characteristic(uuid: db3e25d1-79e9-48fa-a2c3-facc90a3d437, id: 25, value: 56)
D/RxBle#ConnectionOperationQueue: FINISHED CharacteristicWriteOperation(254389343) in 5 ms

I tested write using nRF Connect app and everything works as expected.

NailAgliev avatar Sep 17 '20 06:09 NailAgliev

Any new information?

NailAgliev avatar Dec 12 '20 11:12 NailAgliev

OMG, sorry for the wait. Do you by any chance still have the faulty code/device?

mikolak avatar Apr 12 '21 18:04 mikolak