diff --git a/android/src/main/java/com/lib/flutter_blue_plus/FlutterBluePlusPlugin.java b/android/src/main/java/com/lib/flutter_blue_plus/FlutterBluePlusPlugin.java index 27869317..4e5b1aa0 100644 --- a/android/src/main/java/com/lib/flutter_blue_plus/FlutterBluePlusPlugin.java +++ b/android/src/main/java/com/lib/flutter_blue_plus/FlutterBluePlusPlugin.java @@ -2279,7 +2279,7 @@ public void onServicesDiscovered(BluetoothGatt gatt, int status) } // called for both notifications & reads - public void onCharacteristicReceived(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, byte[] value, int status) + public void onCharacteristicReceived(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, byte[] value, int status, boolean fromReadOperation) { // GATT Service? if (uuidStr(characteristic.getService().getUuid()) == "1800") { @@ -2306,6 +2306,7 @@ public void onCharacteristicReceived(BluetoothGatt gatt, BluetoothGattCharacteri if (primaryService != null) { response.put("primary_service_uuid", uuidStr(primaryService.getUuid())); } + response.put("from_read_operation", fromReadOperation ? 1 : 0); invokeMethodUIThread("OnCharacteristicReceived", response); } @@ -2318,7 +2319,7 @@ public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteris LogLevel level = LogLevel.DEBUG; log(level, "onCharacteristicChanged:"); log(level, " chr: " + uuidStr(characteristic.getUuid())); - onCharacteristicReceived(gatt, characteristic, value, BluetoothGatt.GATT_SUCCESS); + onCharacteristicReceived(gatt, characteristic, value, BluetoothGatt.GATT_SUCCESS, false); } @Override @@ -2330,7 +2331,7 @@ public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic log(level, "onCharacteristicRead:"); log(level, " chr: " + uuidStr(characteristic.getUuid())); log(level, " status: " + gattErrorString(status) + " (" + status + ")"); - onCharacteristicReceived(gatt, characteristic, value, status); + onCharacteristicReceived(gatt, characteristic, value, status, true); } @Override diff --git a/ios/Classes/FlutterBluePlusPlugin.m b/ios/Classes/FlutterBluePlusPlugin.m index c4f407f0..6ffc957c 100644 --- a/ios/Classes/FlutterBluePlusPlugin.m +++ b/ios/Classes/FlutterBluePlusPlugin.m @@ -1441,6 +1441,8 @@ - (void)peripheral:(CBPeripheral *)peripheral @"success": error == nil ? @(1) : @(0), @"error_string": error ? [error localizedDescription] : @"success", @"error_code": error ? @(error.code) : @(0), + // TODO: How to determine this on iOS / macOS? + @"from_read_operation": @(1), } mutableCopy]; // remove if null diff --git a/lib/src/bluetooth_characteristic.dart b/lib/src/bluetooth_characteristic.dart index 2257145a..bb3db0ea 100644 --- a/lib/src/bluetooth_characteristic.dart +++ b/lib/src/bluetooth_characteristic.dart @@ -124,7 +124,8 @@ class BluetoothCharacteristic { .where((p) => p.remoteId == request.remoteId) .where((p) => p.serviceUuid == request.serviceUuid) .where((p) => p.characteristicUuid == request.characteristicUuid) - .where((p) => p.primaryServiceUuid == request.primaryServiceUuid); + .where((p) => p.primaryServiceUuid == request.primaryServiceUuid) + .where((p) => p.fromReadOperation == true); // Start listening now, before invokeMethod, to ensure we don't miss the response Future futureResponse = responseStream.first; diff --git a/lib/src/bluetooth_msgs.dart b/lib/src/bluetooth_msgs.dart index ebdd9863..f0413130 100644 --- a/lib/src/bluetooth_msgs.dart +++ b/lib/src/bluetooth_msgs.dart @@ -452,6 +452,7 @@ class BmCharacteristicData { final bool success; final int errorCode; final String errorString; + final bool fromReadOperation; BmCharacteristicData({ @@ -463,6 +464,7 @@ class BmCharacteristicData { required this.success, required this.errorCode, required this.errorString, + required this.fromReadOperation, }); factory BmCharacteristicData.fromMap(Map json) { @@ -475,6 +477,7 @@ class BmCharacteristicData { success: json['success'] != 0, errorCode: json['error_code'], errorString: json['error_string'], + fromReadOperation: json.containsKey('from_read_operation') && (json['from_read_operation'] != 0), ); } }