dotintent / FlutterBleLib

Bluetooth Low Energy library for Flutter with support for simulating peripherals
Apache License 2.0
530 stars 194 forks source link

In Android, the characteristicUpdates monitor works, but it doesn't seem to work in iOS. #629

Closed classic037 closed 1 year ago

classic037 commented 1 year ago

hi

I connect to a test BLE device and write commands to the BLE device. Then the BLE device sends the commands to the app through the data UUID.

The versions I tested are as follows: Android version: 12 iOS version: 16.4.1

Here's the code: When connecting to the BLE device and entering the AcScreen, I activate the monitor for the ReadCharacteristic UUID to receive commands from the BLE device in the app. Additionally, using WriteCharacteristic, the app can receive commands from the BLE device.

  typedef OperationFunction = Future<void> Function();

  class AcScreen extends StatefulWidget {
    final Device device;

    AcScreen({Key? key, required this.device})
        : assert(device.type == DeviceType.ac),
          super(key: key);

    @override
    State<AcScreen> createState() => _AcScreenState();
  }

  class _AcScreenState extends State<AcScreen> {
    double temp = 1;
    DeviceDetailsBloc? _deviceDetailsBloc;

    StreamSubscription? _appStateSubscription;
    bool _shouldRunOnResume = true;

    String acTransaction = "Ac";
    late final BleManager? _bleManager;

    StreamSubscription<double>? _monitoringStreamSubscription;

    //UUID
    static final String TestService = Platform.isAndroid ? "0000FFF0-0000-1000-8000-00805F9B34FB" : "FFF0";
    static final String ReadCharacteristic = Platform.isAndroid ? "0000FFF1-0000-1000-8000-00805F9B34FB" : "FFF1";
    static final String WrtieCharacteristic = Platform.isAndroid ? "0000FFF2-0000-1000-8000-00805F9B34FB" : "FFF2";

    //Level Control
    Uint8List level_1 = Uint8List.fromList([0x02, 0x31, 0x43, 0xC3, 0x31, 0x36, 0x3A, 0x03]);
    Uint8List level_2 = Uint8List.fromList([0x02, 0x31, 0x43, 0xC3, 0x32, 0x36, 0x3B, 0x03]);
    Uint8List level_3 = Uint8List.fromList([0x02, 0x31, 0x43, 0xC3, 0x33, 0x36, 0x3C, 0x03]);

    @override
    void didChangeDependencies() {
      super.didChangeDependencies();
      Fimber.d("didChangeDependencies");
      if (_deviceDetailsBloc == null) {
        _deviceDetailsBloc = DeviceDetailsBlocProvider.of(context);
        _bleManager = _deviceDetailsBloc?.getBleManager();
        if (_shouldRunOnResume) {
          _shouldRunOnResume = false;
          _onResume();
        }
      }
    }

    void _onResume() {
      Fimber.d("onResume");
      _deviceDetailsBloc?.init();
      _appStateSubscription =
          _deviceDetailsBloc?.disconnectedDevice.listen((bleDevice) async {
            Fimber.d("navigate to details");
            _onPause();
            Navigator.pop(context);
            _shouldRunOnResume = true;
            Fimber.d("back from details");
          });
      readWriteMonitorCharacteristicForTest(TestService,ReadCharacteristic,acTransaction);

      writeCharacter(TestService,WrtieCharacteristic,level_3);
    }

    void _onPause() {
      Fimber.d("onPause");
      _appStateSubscription?.cancel();
      _deviceDetailsBloc?.dispose();
    }

    @override
    void dispose() {
      Fimber.d("dispose");
      _onPause();
      super.dispose();
      print("dispose");
      cancelMonitoring(acTransaction);
    }

    void writeCharacter(String svcUuid, String writeCharacterUuid,Uint8List data) {
      _deviceDetailsBloc?.writeCharacter(svcUuid,writeCharacterUuid,data);
    }

    Future<void> _runWithErrorHandling(OperationFunction Function) async {
      try {
        await Function();
      } on BleError catch (e) {
        print("BleError caught: ${e.errorCode.value} ${e.reason}");
      } catch (e) {
        if (e is Error) {
          //debugPrintStack(stackTrace: e.stackTrace);
        }
        print("${e.runtimeType}: $e");
      }
    }
    Future<void> cancelMonitoring(String transactionId) async {
      _monitoringStreamSubscription?.cancel();
      await _bleManager?.cancelTransaction(transactionId);
    }
    void startMonitoring(
        Stream<Uint8List> characteristicUpdates) async {
      await _monitoringStreamSubscription?.cancel();
      _monitoringStreamSubscription =
      characteristicUpdates.listen(
            (temperature) {
          String hex = temperature.map((byte) => byte.toRadixString(16).padLeft(2, '0')).join(' ');
          print("testWrite Read Data: ${hex}");
        },
        onError: (error) {
          print("Read Data \n$error");
        },
        cancelOnError: true,
      ) as StreamSubscription<double>?;
    }
    Future<void> readWriteMonitorCharacteristicForTest(String svcUuid, String writeCharacterUuid, String transactionId) async {
      await _runWithErrorHandling(() async {
        print("Start monitoring readWriteMonitorCharacteristicFortest");
        var peripheral = _deviceDetailsBloc?.getBleDevice().peripheral;

        startMonitoring(
          peripheral!
              .monitorCharacteristic(svcUuid,
              writeCharacterUuid,
              transactionId: transactionId)
              .map((characteristic) => characteristic.value)
        );
      });
    }

Currently, it is possible to send commands to the BLE device from the app on both Android and iOS. However, on iOS, the commands from the BLE device are not being received.

Please refer to the following Android and iOS logs:

[Android Log]

✓  Built build/app/outputs/flutter-apk/app-debug.apk.
D/FLUTTER_CALL(15956): registered channel:aesDecrypt
D/FLUTTER_CALL(15956): registered channel:aesEncrypt
D/FLUTTER_CALL(15956): registered channel:argon2d
D/FLUTTER_CALL(15956): registered channel:argon2i
D/FLUTTER_CALL(15956): registered channel:argon2id
D/FlutterGeolocator(15956): Attaching Geolocator to activity
W/FlutterActivityAndFragmentDelegate(15956): A splash screen was provided to Flutter, but this is deprecated. See flutter.dev/go/android-splash-migration for migration steps.
D/FlutterGeolocator(15956): Creating service.
D/FlutterGeolocator(15956): Binding to location service.
D/FlutterGeolocator(15956): Geolocator foreground service connected
D/FlutterGeolocator(15956): Initializing Geolocator services
Debug service listening on ws://127.0.0.1:60457/j7H80HbHsp8=/ws
Syncing files to device SM G991N...
I/ble_lib_exampl(15956): Compiler allocated 4632KB to compile void android.view.ViewRootImpl.performTraversals()
I/ViewRootImpl@f13eae4[MainActivity](15956): ViewPostIme pointer 0
I/ViewRootImpl@f13eae4[MainActivity](15956): ViewPostIme pointer 1
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin(15956): on native side observed method: isClientCreated
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin(15956): on native side observed method: createClient
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin(15956): on native side observed method: getState
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin(15956): on native side observed method: startDeviceScan
I/BluetoothAdapter(15956): STATE_ON
I/BluetoothAdapter(15956): STATE_ON
I/BluetoothAdapter(15956): STATE_ON
I/BluetoothAdapter(15956): STATE_ON
D/BluetoothLeScanner(15956): Start Scan with callback
D/BluetoothLeScanner(15956): onScannerRegistered() - status=0 scannerId=11 mScannerId=0
I/flutter (15956): Build row for 0
I/ViewRootImpl@f13eae4[MainActivity](15956): ViewPostIme pointer 0
I/ViewRootImpl@f13eae4[MainActivity](15956): ViewPostIme pointer 1
I/flutter (15956): clicked device: TEST PORTABLE AIR_40449E 
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin(15956): on native side observed method: stopDeviceScan
I/BluetoothAdapter(15956): STATE_ON
I/BluetoothAdapter(15956): STATE_ON
D/BluetoothLeScanner(15956): Stop Scan with callback
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin(15956): on native side observed method: stopDeviceScan
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin(15956): on native side observed method: isDeviceConnected
I/flutter (15956): Build row for 0
I/flutter (15956): didChangeDependencies
I/flutter (15956): onResume
D/CompatibilityChangeReporter(15956): Compat change id reported: 147798919; UID 10396; state: DISABLED
V/Toast   (15956): show: caller = io.github.ponnamkarthik.toast.fluttertoast.MethodCallHandlerImpl.onMethodCall:102 
V/Toast   (15956): show: focusDisplayId = 0, isFocusInDesktop = false mCustomDisplayId=-1 isDexDualMode=false
V/Toast   (15956): show: isActivityContext = false
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin(15956): on native side observed method: stopDeviceScan
I/ViewRootImpl@f4d22d3[Toast](15956): setView = android.widget.FrameLayout@6a64e10 TM=true
I/ViewRootImpl@f4d22d3[Toast](15956): Relayout returned: old=(0,80,1080,2256) new=(227,2031,853,2156) req=(626,125)0 dur=6 res=0x7 s={true 521376462880} ch=true fn=-1
I/ViewRootImpl@f4d22d3[Toast](15956): [DP] dp(1) 0 android.view.ViewRootImpl.reportNextDraw:11233 android.view.ViewRootImpl.performTraversals:4075 android.view.ViewRootImpl.doTraversal:2819 
D/ViewRootImpl@f4d22d3[Toast](15956): Creating frameCompleteCallback mNextDrawUseBlastSync=false mReportNextDraw=true commitCallbacks size=0
I/flutter (15956): PeripheralConnectionState.disconnected
D/ViewRootImpl@f4d22d3[Toast](15956): Received frameCompleteCallback frameNum=1
I/ViewRootImpl@f4d22d3[Toast](15956): [DP] pdf(0) 0 android.view.ViewRootImpl.lambda$createFrameCompleteCallback$3$ViewRootImpl:4833 android.view.ViewRootImpl$$ExternalSyntheticLambda15.run:6 android.os.Handler.handleCallback:938 
I/ViewRootImpl@f4d22d3[Toast](15956): [DP] rdf()
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin(15956): on native side observed method: logLevel
I/flutter (15956): try to get log level from: NONE
I/flutter (15956): Connection_to log level LogLevel.none
I/flutter (15956): Connection_to log level to debug
I/flutter (15956): set log level to debug
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin(15956): on native side observed method: setLogLevel
D/com.polidea.flutter_ble_lib.delegate.LogLevelDelegate(15956): set log level to: debug
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin(15956): on native side observed method: logLevel
I/flutter (15956): try to get log level from: DEBUG
I/flutter (15956): Connection_to log level LogLevel.debug
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin(15956): on native side observed method: observeConnectionState
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin(15956): on native side observed method: connectToDevice
I/flutter (15956): PeripheralConnectionState.disconnected
I/flutter (15956): PeripheralConnectionState.connecting
D/RxBle#ClientOperationQueue(15956): QUEUED   ConnectOperation(137452352)
D/RxBle#ClientOperationQueue(15956): STARTED  ConnectOperation(137452352)
I/BluetoothAdapter(15956): STATE_ON
D/BluetoothGatt(15956): connect() - device: 5C:F2:86:40:44:9E, auto: false
I/BluetoothAdapter(15956): isSecureModeEnabled
D/BluetoothGatt(15956): registerApp()
D/BluetoothGatt(15956): registerApp() - UUID=f42c2506-82a1-4d0a-8847-79f40cf38442
D/BluetoothGatt(15956): onClientRegistered() - status=0 clientIf=11
D/BluetoothGatt(15956): onTimeSync() - eventCount=0 offset=345
D/BluetoothGatt(15956): onClientConnectionState() - status=0 clientIf=11 device=5C:F2:86:40:44:9E
D/RxBle#BluetoothGatt$1(15956): onConnectionStateChange newState=2 status=0
D/RxBle#ClientOperationQueue(15956): FINISHED ConnectOperation(137452352) in 1752 ms
I/flutter (15956): PeripheralConnectionState.connected
V/Toast   (15956): show: caller = io.github.ponnamkarthik.toast.fluttertoast.MethodCallHandlerImpl.onMethodCall:102 
V/Toast   (15956): show: focusDisplayId = 0, isFocusInDesktop = false mCustomDisplayId=-1 isDexDualMode=false
V/Toast   (15956): show: isActivityContext = false
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin(15956): on native side observed method: discoverAllServicesAndCharacteristics
D/RxBle#ConnectionOperationQueue(15956): QUEUED   ServiceDiscoveryOperation(167459844)
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin(15956): on native side observed method: cancelTransaction
D/RxBle#ConnectionOperationQueue(15956): STARTED  ServiceDiscoveryOperation(167459844)
D/BluetoothGatt(15956): discoverServices() - device: 5C:F2:86:40:44:9E
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin(15956): on native side observed method: discoverAllServicesAndCharacteristics
D/BluetoothGatt(15956): onTimeSync() - eventCount=16 offset=385
D/BluetoothGatt(15956): onConnectionUpdated() - Device=5C:F2:86:40:44:9E interval=6 latency=0 timeout=500 status=0
D/BluetoothGatt(15956): onSearchComplete() = Device=5C:F2:86:40:44:9E Status=0
D/RxBle#BluetoothGatt$1(15956): onServicesDiscovered status=0
D/RxBle#ConnectionOperationQueue(15956): FINISHED ServiceDiscoveryOperation(167459844) in 110 ms
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin(15956): on native side observed method: services
I/flutter (15956): PRINTING SERVICES for 
I/flutter (15956): TEST PORTABLE AIR_40449E 
I/flutter (15956): PRINTING CHARACTERISTICS FOR SERVICE 
I/flutter (15956): 00001800-0000-1000-8000-00805f9b34fb
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin(15956): on native side observed method: characteristicsForService
I/flutter (15956): 00002a00-0000-1000-8000-00805f9b34fb
I/flutter (15956): 00002a01-0000-1000-8000-00805f9b34fb
I/flutter (15956): 00002a04-0000-1000-8000-00805f9b34fb
I/flutter (15956): 00002aa6-0000-1000-8000-00805f9b34fb
I/flutter (15956): PRINTING CHARACTERISTICS FROM 
I/flutter (15956): PERIPHERAL for the same service
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin(15956): on native side observed method: characteristics
I/flutter (15956): Found characteristic 
I/flutter (15956):  00002a00-0000-1000-8000-00805f9b34fb
I/flutter (15956): Found characteristic 
I/flutter (15956):  00002a01-0000-1000-8000-00805f9b34fb
I/flutter (15956): Found characteristic 
I/flutter (15956):  00002a04-0000-1000-8000-00805f9b34fb
I/flutter (15956): Found characteristic 
I/flutter (15956):  00002aa6-0000-1000-8000-00805f9b34fb
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin(15956): on native side observed method: descriptorsForDevice
I/flutter (15956): #0      new Characteristic.fromJson (package:flutter_ble_lib/characteristic.dart:48:20)
I/flutter (15956): #1      DiscoveryMixin.descriptorsForPeripheral (package:flutter_ble_lib/src/bridge/discovery_mixin.dart:93:24)
I/flutter (15956): <asynchronous suspension>
I/flutter (15956): #2      PeripheralOperations.discovery.<anonymous closure> (package:flutter_ble_lib_example/test_scenarios/peripheral_operations.dart:70:23)
I/flutter (15956): <asynchronous suspension>
I/flutter (15956): #3      PeripheralOperations._runWithErrorHandling (package:flutter_ble_lib_example/test_scenarios/peripheral_operations.dart:754:7)
I/flutter (15956): <asynchronous suspension>
I/flutter (15956): #4      PeripheralOperations.discovery (package:flutter_ble_lib_example/test_scenarios/peripheral_operations.dart:43:37)
I/flutter (15956): <asynchronous suspension>
I/flutter (15956): Requesting MTU = 512
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin(15956): on native side observed method: requestMtu
D/com.polidea.flutter_ble_lib.delegate.MtuDelegate(15956): Request MTU 512
D/RxBle#ConnectionOperationQueue(15956): QUEUED   MtuRequestOperation(87562539)
D/RxBle#ConnectionOperationQueue(15956): STARTED  MtuRequestOperation(87562539)
D/BluetoothGatt(15956): configureMTU() - device: 5C:F2:86:40:44:9E mtu: 512
D/BluetoothGatt(15956): onTimeSync() - eventCount=29 offset=353
D/BluetoothGatt(15956): onConnectionUpdated() - Device=5C:F2:86:40:44:9E interval=39 latency=0 timeout=500 status=0
I/ViewRootImpl@f4d22d3[Toast](15956): dispatchDetachedFromWindow
D/InputTransport(15956): Input channel destroyed: '53000d6', fd=144
I/ViewRootImpl@ad1b959[Toast](15956): setView = android.widget.FrameLayout@59b391e TM=true
I/ViewRootImpl@ad1b959[Toast](15956): Relayout returned: old=(0,80,1080,2256) new=(258,2031,821,2156) req=(563,125)0 dur=5 res=0x7 s={true 521376480320} ch=true fn=-1
I/ViewRootImpl@ad1b959[Toast](15956): [DP] dp(1) 0 android.view.ViewRootImpl.reportNextDraw:11233 android.view.ViewRootImpl.performTraversals:4075 android.view.ViewRootImpl.doTraversal:2819 
D/ViewRootImpl@ad1b959[Toast](15956): Creating frameCompleteCallback mNextDrawUseBlastSync=false mReportNextDraw=true commitCallbacks size=0
D/ViewRootImpl@ad1b959[Toast](15956): Received frameCompleteCallback frameNum=1
I/ViewRootImpl@ad1b959[Toast](15956): [DP] pdf(0) 0 android.view.ViewRootImpl.lambda$createFrameCompleteCallback$3$ViewRootImpl:4833 android.view.ViewRootImpl$$ExternalSyntheticLambda15.run:6 android.os.Handler.handleCallback:938 
I/ViewRootImpl@ad1b959[Toast](15956): [DP] rdf()
D/BluetoothGatt(15956): onConfigureMTU() - Device=5C:F2:86:40:44:9E mtu=247 status=0
D/RxBle#BluetoothGatt$1(15956): onMtuChanged mtu=247 status=0
I/flutter (15956): SetMtuSize MTU = 247
I/flutter (15956): negotiated MTU 247
D/RxBle#ConnectionOperationQueue(15956): FINISHED MtuRequestOperation(87562539) in 68 ms
I/ViewRootImpl@ad1b959[Toast](15956): dispatchDetachedFromWindow
D/InputTransport(15956): Input channel destroyed: '716669c', fd=172
I/ViewRootImpl@f13eae4[MainActivity](15956): ViewPostIme pointer 0
I/ViewRootImpl@f13eae4[MainActivity](15956): ViewPostIme pointer 1
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin(15956): on native side observed method: isDeviceConnected
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin(15956): on native side observed method: stopDeviceScan
I/flutter (15956): Start monitoring readWriteMonitorCharacteristicForTEST
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin(15956): on native side observed method: monitorCharacteristicForDevice
E/flutter (15956): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: type '_ForwardingStreamSubscription<CharacteristicWithValueAndTransactionId, Uint8List>' is not a subtype of type 'StreamSubscription<double>?' in type cast
E/flutter (15956): #0      _AcScreenState.startMonitoring (package:flutter_ble_lib_example/features/devices/presentation/views/ac.dart:431:7)
E/flutter (15956): <asynchronous suspension>
E/flutter (15956): 
D/BluetoothGatt(15956): setCharacteristicNotification() - uuid: 0000fff1-0000-1000-8000-00805f9b34fb enable: true
D/RxBle#ConnectionOperationQueue(15956): QUEUED   DescriptorWriteOperation(205982959)
D/RxBle#ConnectionOperationQueue(15956): STARTED  DescriptorWriteOperation(205982959)
D/BluetoothGatt(15956): onTimeSync() - eventCount=134 offset=369
D/BluetoothGatt(15956): onConnectionUpdated() - Device=5C:F2:86:40:44:9E interval=30 latency=0 timeout=400 status=0
D/RxBle#BluetoothGatt$1(15956): onDescriptorWrite descriptor=00002902-0000-1000-8000-00805f9b34fb status=0
D/RxBle#ConnectionOperationQueue(15956): FINISHED DescriptorWriteOperation(205982959) in 106 ms
D/RxBle#BluetoothGatt$1(15956): onCharacteristicChanged characteristic=0000fff1-0000-1000-8000-00805f9b34fb
I/flutter (15956): testWrite Read Data: 02 31 52 bf 30 30 3a 34 03
D/RxBle#BluetoothGatt$1(15956): onCharacteristicChanged characteristic=0000fff1-0000-1000-8000-00805f9b34fb
I/flutter (15956): testWrite Read Data: 02 31 52 bf 30 30 3a 34 03
D/RxBle#BluetoothGatt$1(15956): onCharacteristicChanged characteristic=0000fff1-0000-1000-8000-00805f9b34fb
I/flutter (15956): testWrite Read Data: 02 31 52 bf 30 30 3a 34 03
D/RxBle#BluetoothGatt$1(15956): onCharacteristicChanged characteristic=0000fff1-0000-1000-8000-00805f9b34fb
I/flutter (15956): testWrite Read Data: 02 31 52 bf 30 30 3a 34 03
D/RxBle#BluetoothGatt$1(15956): onCharacteristicChanged characteristic=0000fff1-0000-1000-8000-00805f9b34fb
I/flutter (15956): testWrite Read Data: 02 31 52 bf 30 30 3a 34 03
D/RxBle#BluetoothGatt$1(15956): onCharacteristicChanged characteristic=0000fff1-0000-1000-8000-00805f9b34fb
I/flutter (15956): testWrite Read Data: 02 31 52 bf 30 30 3a 34 03
D/RxBle#BluetoothGatt$1(15956): onCharacteristicChanged characteristic=0000fff1-0000-1000-8000-00805f9b34fb
I/flutter (15956): testWrite Read Data: 02 31 52 bf 30 30 3a 34 03
D/RxBle#BluetoothGatt$1(15956): onCharacteristicChanged characteristic=0000fff1-0000-1000-8000-00805f9b34fb
I/flutter (15956): testWrite Read Data: 02 31 52 bf 30 30 3a 34 03
D/RxBle#BluetoothGatt$1(15956): onCharacteristicChanged characteristic=0000fff1-0000-1000-8000-00805f9b34fb
I/flutter (15956): testWrite Read Data: 02 31 52 bf 30 30 3a 34 03`

[IOS Log]

`2023-05-18 11:14:25.617881+0900 Runner[461:11075] flutter: Build row for 0
2023-05-18 11:14:29.860895+0900 Runner[461:11075] flutter: clicked device: TEST PORTABLE AIR_40449E
2023-05-18 11:14:29.901367+0900 Runner[461:11075] flutter: Build row for 0
2023-05-18 11:14:29.922328+0900 Runner[461:11075] flutter: didChangeDependencies
2023-05-18 11:14:29.922519+0900 Runner[461:11075] flutter: onResume
2023-05-18 11:14:29.932295+0900 Runner[461:11075] flutter: PeripheralConnectionState.disconnected
2023-05-18 11:14:29.933561+0900 Runner[461:11075] flutter: try to get log level from: None
2023-05-18 11:14:29.933747+0900 Runner[461:11075] flutter: Connection_to log level LogLevel.none
2023-05-18 11:14:29.933763+0900 Runner[461:11075] flutter: Connection_to log level to debug
2023-05-18 11:14:29.933832+0900 Runner[461:11075] flutter: set log level to debug
2023-05-18 11:14:29.934108+0900 Runner[461:11075] flutter: try to get log level from: Debug
2023-05-18 11:14:29.934140+0900 Runner[461:11075] flutter: Connection_to log level LogLevel.debug
2023-05-18 11:14:29.937005+0900 Runner[461:11075] flutter: PeripheralConnectionState.disconnected
2023-05-18 11:14:29.937122+0900 Runner[461:11075] flutter: PeripheralConnectionState.connecting
[RxBLEKit|DEBG|02:14:29.937]: CentralManager(10757624832) retrievePeripherals(
withIdentifiers: [0A7E41A1-68E8-8194-1D9C-17548EF293C1])
[RxBLEKit|DEBG|02:14:29.938]: CentralManager(10757624832) connect(
peripheral: Peripheral(uuid: 0A7E41A1-68E8-8194-1D9C-17548EF293C1, name: Optional("TEST PORTABLE AIR_40449E\r")),
options: nil)
2023-05-18 11:14:31.223673+0900 Runner[461:11075] flutter: PeripheralConnectionState.connected
[RxBLEKit|DEBG|02:14:31.238]: Peripheral(uuid: 0A7E41A1-68E8-8194-1D9C-17548EF293C1, name: Optional("TEST PORTABLE AIR_40449E\r")) discoverServices(
serviceUUIDs: nil)
[RxBLEKit|DEBG|02:14:31.249]: Peripheral(uuid: 0A7E41A1-68E8-8194-1D9C-17548EF293C1, name: Optional("TEST PORTABLE AIR_40449E\r")) discoverServices(
serviceUUIDs: nil)
[RxBLEKit|DEBG|02:14:31.340]: Peripheral(uuid: 0A7E41A1-68E8-8194-1D9C-17548EF293C1, name: Optional("TEST PORTABLE AIR_40449E\r")) didDiscoverServices(services
: Optional("[Service(uuid: FFF0, id: 10795226240)]"),
error: nil)
[RxBLEKit|DEBG|02:14:31.343]: Peripheral(uuid: 0A7E41A1-68E8-8194-1D9C-17548EF293C1, name: Optional("TEST PORTABLE AIR_40449E\r")) discoverCharacteristics(
characteristicUUIDs: nil,
for: Service(uuid: FFF0, id: 10795226240))
[RxBLEKit|DEBG|02:14:31.343]: Peripheral(uuid: 0A7E41A1-68E8-8194-1D9C-17548EF293C1, name: Optional("TEST PORTABLE AIR_40449E\r")) didDiscoverServices(services
: Optional("[Service(uuid: FFF0, id: 10795226240)]"),
error: nil)
[RxBLEKit|DEBG|02:14:31.459]: Peripheral(uuid: 0A7E41A1-68E8-8194-1D9C-17548EF293C1, name: Optional("TEST PORTABLE AIR_40449E\r")) didDiscoverCharacteristicsFor(for:
Service(uuid: FFF0, id: 10795226240), characteristics:
Optional("[Characteristic(uuid: FFF1, id: 10743800352), Characteristic(uuid: FFF2, id: 10743804672)]"),
error: nil)
[RxBLEKit|DEBG|02:14:31.461]: Peripheral(uuid: 0A7E41A1-68E8-8194-1D9C-17548EF293C1, name: Optional("TEST PORTABLE AIR_40449E\r")) discoverDescriptors(
for: Characteristic(uuid: FFF1, id: 10743800352))
[RxBLEKit|DEBG|02:14:31.461]: Peripheral(uuid: 0A7E41A1-68E8-8194-1D9C-17548EF293C1, name: Optional("TEST PORTABLE AIR_40449E\r")) discoverDescriptors(
for: Characteristic(uuid: FFF2, id: 10743804672))
[RxBLEKit|DEBG|02:14:31.520]: Peripheral(uuid: 0A7E41A1-68E8-8194-1D9C-17548EF293C1, name: Optional("TEST PORTABLE AIR_40449E\r")) didDiscoverDescriptorsFor
(for:Characteristic(uuid: FFF1, id: 10743800352), descriptors:
Optional("[Descriptor(uuid: Client Characteristic Configuration, id: 10784087936)]"),
error: nil)
[RxBLEKit|DEBG|02:14:31.579]: Peripheral(uuid: 0A7E41A1-68E8-8194-1D9C-17548EF293C1, name: Optional("TEST PORTABLE AIR_40449E\r")) didDiscoverDescriptorsFor
(for:Characteristic(uuid: FFF2, id: 10743804672), descriptors:
Optional("[]"),
error: nil)
2023-05-18 11:14:31.581312+0900 Runner[461:11075] flutter: PRINTING SERVICES for 
TEST PORTABLE AIR_40449E
2023-05-18 11:14:31.581530+0900 Runner[461:11075] flutter: PRINTING CHARACTERISTICS FOR SERVICE 
0000fff0-0000-1000-8000-00805f9b34fb
2023-05-18 11:14:31.582915+0900 Runner[461:11075] flutter: 0000fff1-0000-1000-8000-00805f9b34fb
2023-05-18 11:14:31.582952+0900 Runner[461:11075] flutter: 0000fff2-0000-1000-8000-00805f9b34fb
2023-05-18 11:14:31.582974+0900 Runner[461:11075] flutter: PRINTING CHARACTERISTICS FROM 
PERIPHERAL for the same service
2023-05-18 11:14:31.583614+0900 Runner[461:11075] flutter: Found characteristic 
 0000fff1-0000-1000-8000-00805f9b34fb
2023-05-18 11:14:31.583643+0900 Runner[461:11075] flutter: Found characteristic 
 0000fff2-0000-1000-8000-00805f9b34fb
2023-05-18 11:14:31.591657+0900 Runner[461:11075] flutter: #0      new Characteristic.fromJson (package:flutter_ble_lib/characteristic.dart:47:14)
2023-05-18 11:14:31.591702+0900 Runner[461:11075] flutter: #1      DiscoveryMixin.descriptorsForPeripheral (package:flutter_ble_lib/src/bridge/discovery_mixin.dart:93:24)
2023-05-18 11:14:31.591721+0900 Runner[461:11075] flutter: <asynchronous suspension>
2023-05-18 11:14:31.591741+0900 Runner[461:11075] flutter: #2      PeripheralOperations.discovery.<anonymous closure> (package:flutter_ble_lib_example/test_scenarios/peripheral_operations.dart:70:23)
2023-05-18 11:14:31.591758+0900 Runner[461:11075] flutter: <asynchronous suspension>
2023-05-18 11:14:31.591774+0900 Runner[461:11075] flutter: #3      PeripheralOperations._runWithErrorHandling (package:flutter_ble_lib_example/test_scenarios/peripheral_operations.dart:754:7)
2023-05-18 11:14:31.591789+0900 Runner[461:11075] flutter: <asynchronous suspension>
2023-05-18 11:14:31.591832+0900 Runner[461:11075] flutter: #4      PeripheralOperations.discovery (package:flutter_ble_lib_example/test_scenarios/peripheral_operations.dart:43:37)
2023-05-18 11:14:31.591908+0900 Runner[461:11075] flutter: <asynchronous suspension>
2023-05-18 11:14:31.592327+0900 Runner[461:11075] flutter: Requesting MTU = 512
2023-05-18 11:14:31.592800+0900 Runner[461:11075] flutter: SetMtuSize MTU = 247
2023-05-18 11:14:31.592838+0900 Runner[461:11075] flutter: negotiated MTU 247
2023-05-18 11:14:34.897117+0900 Runner[461:11075] flutter: Start monitoring readWriteMonitorCharacteristicForTest
2023-05-18 11:14:34.934725+0900 Runner[461:11075] [VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: type '_ForwardingStreamSubscription<CharacteristicWithValueAndTransactionId, Uint8List>' is not a subtype of type 'StreamSubscription<double>?' in type cast
#0      _AcScreenState.startMonitoring (package:flutter_ble_lib_example/features/devices/presentation/views/ac.dart:431:7)
<asynchronous suspension>
[RxBLEKit|DEBG|02:14:34.937]: Peripheral(uuid: 0A7E41A1-68E8-8194-1D9C-17548EF293C1, name: Optional("TEST PORTABLE AIR_40449E\r")) setNotifyValue(
enabled: true,
for: Characteristic(uuid: FFF1, id: 10743800352))
[RxBLEKit|DEBG|02:14:34.999]: Peripheral(uuid: 0A7E41A1-68E8-8194-1D9C-17548EF293C1, name: Optional("TEST PORTABLE AIR_40449E\r")) didUpdateNotificationStateFor(
for:Characteristic(uuid: FFF1, id: 10743800352), isNotifying: true,
error: nil)
[RxBLEKit|DEBG|02:14:35.148]: Peripheral(uuid: 0A7E41A1-68E8-8194-1D9C-17548EF293C1, name: Optional("TEST PORTABLE AIR_40449E\r")) didUpdateValueFor(for:Characteristic(uuid: FFF1, id: 10743800352),
value: Optional("023152bf30303a3403"),
error: nil)
[RxBLEKit|DEBG|02:14:36.139]: Peripheral(uuid: 0A7E41A1-68E8-8194-1D9C-17548EF293C1, name: Optional("TEST PORTABLE AIR_40449E\r")) didUpdateValueFor(for:Characteristic(uuid: FFF1, id: 10743800352),
value: Optional("023152bf30303a3403"),
error: nil)
[RxBLEKit|DEBG|02:14:37.160]: Peripheral(uuid: 0A7E41A1-68E8-8194-1D9C-17548EF293C1, name: Optional("TEST PORTABLE AIR_40449E\r")) didUpdateValueFor(for:Characteristic(uuid: FFF1, id: 10743800352),
value: Optional("023152bf30303a3403"),
error: nil)
[RxBLEKit|DEBG|02:14:38.149]: Peripheral(uuid: 0A7E41A1-68E8-8194-1D9C-17548EF293C1, name: Optional("TEST PORTABLE AIR_40449E\r")) didUpdateValueFor(for:Characteristic(uuid: FFF1, id: 10743800352),
value: Optional("023152bf30303a3403"),
error: nil)
[RxBLEKit|DEBG|02:14:39.169]: Peripheral(uuid: 0A7E41A1-68E8-8194-1D9C-17548EF293C1, name: Optional("TEST PORTABLE AIR_40449E\r")) didUpdateValueFor(for:Characteristic(uuid: FFF1, id: 10743800352),
value: Optional("023152bf30303a3403"),
error: nil)
[RxBLEKit|DEBG|02:14:40.160]: Peripheral(uuid: 0A7E41A1-68E8-8194-1D9C-17548EF293C1, name: Optional("TEST PORTABLE AIR_40449E\r")) didUpdateValueFor(for:Characteristic(uuid: FFF1, id: 10743800352),
value: Optional("023152bf30303a3403"),
error: nil)
[RxBLEKit|DEBG|02:14:41.148]: Peripheral(uuid: 0A7E41A1-68E8-8194-1D9C-17548EF293C1, name: Optional("TEST PORTABLE AIR_40449E\r")) didUpdateValueFor(for:Characteristic(uuid: FFF1, id: 10743800352),
value: Optional("023152bf30303a3403"),
error: nil)

Based on the logs, we can see that in the case of Android, continuous reception of hex commands is observed from the BLE device. However, in the case of iOS, only the following log is repeatedly occurring, and the code inside the startMonitoring function is not being executed.

[RxBLEKit|DEBG|02:14:41.148]: Peripheral(uuid: 0A7E41A1-68E8-8194-1D9C-17548EF293C1, name: Optional("TEST PORTABLE AIR_40449E\r")) didUpdateValueFor(for:Characteristic(uuid: FFF1, id: 10743800352),
value: Optional("023152bf30303a3403"),
error: nil)
 void startMonitoring(
      Stream<Uint8List> characteristicUpdates) async {
    await _monitoringStreamSubscription?.cancel();
    _monitoringStreamSubscription =
    characteristicUpdates.listen(
          (temperature) {
        String hex = temperature.map((byte) => byte.toRadixString(16).padLeft(2, '0')).join(' ');
        print("CowayWrite Read Data: ${hex}");
      },
      onError: (error) {
        print("Read Data \n$error");
      },
      cancelOnError: true,
    ) as StreamSubscription<double>?;
  }

Am I missing something? Although I can see commands being received from the BLE device in the iOS log, why is the characteristicUpdates.listen function not being executed?

Please help me.