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
I use to FlutterBleLib 2.3.2
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.
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`
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.
The peculiar thing is that in the case of writeCharacteristic, both Android and IOS work normally.
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?
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
I use to FlutterBleLib 2.3.2
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.
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]
[IOS Log]
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.
The peculiar thing is that in the case of writeCharacteristic, both Android and IOS work normally.
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.