yanshouwang / bluetooth_low_energy

A Flutter plugin for controlling the bluetooth low energy.
https://pub.dev/packages/bluetooth_low_energy
MIT License
47 stars 15 forks source link

Cant send write requests to multiple devices on Android/IOS #98

Closed IvanTorres21 closed 1 week ago

IvanTorres21 commented 2 weeks ago

Hello,

I was able to connect two different bluetooth devices to the same app and send write requests to them in the windows version. But when executing the same application within the Android/iOS version an error pops out when trying to write to the first bluetooth device I connected to.

Steps to reproduce: 1.- Connect to one device 2.- Connect to a second device 3.- Send a write request to both 4.- The second device recives the requests, while the first one throws this error:

`flutter: PlatformException(illegalArgument, MyError, Stacktrace: ["0 bluetooth_low_energy_darwin 0x0000000103cf3250 $s27bluetooth_low_energy_darwin9wrapError33_D3FF39C2E9589F2A07964E0F3A1AEE9ELLySayypSgGypF + 1708", "1 bluetooth_low_energy_darwin 0x0000000103d029fc $s27bluetooth_low_energy_darwin28MyCentralManagerHostAPISetupC5setUp15binaryMessenger3api20messageChannelSuffixySo013FlutterBinaryM0_p_AA0efgH3API_pSgSStFZyypSg_yAKctcfU14_ys6ResultOyyts5ErrorpGcfU + 324", "2 bluetooth_low_energy_darwin 0x0000000103d1fa1c $s27bluetooth_low_energy_darwin16MyCentralManagerC19writeCharacteristic8uuidArgs08hashCodeK005valueK004typeK010completionySS_s5Int64VSo24FlutterStandardTypedDataCAA0e27GATTCharacteristicWriteTypeK0Oys6ResultOyyts5Error_pGctF + 1104", "3 bluetooth_low_energy_darwin 0x0000000103d2acb4 $s27bluetooth_low_energy_darwin16MyCentralManagerCAA0efG7HostAPIA2aDP19writeCharacteristic8uuidArgs08hashCodeM005valueM004typeM010completionySS_s5Int64VSo24FlutterStandardTypedDataCAA0e27GATTCharacteristicWriteTypeM0Oys6ResultOyyts5Error_pGctFTW + 32", "4 bluetooth_low_energy_darwin 0x0000000103d02888 $s27bluetooth_low_energy_darwin28MyCentralManagerHostAPISetupC5setUp15binaryMessenger3api20messageChannelSuffixySo013FlutterBinaryM0_p_AA0efgH3API_pSgSStFZyypSgyAKctcfU14 + 1760", "5 bluetooth_low_energy_darwin 0x0000000103cfe278 $sypSgAAIegn_Iegng_yXlSgABIeyBy_IeyByy_TR + 236", "6 Flutter 0x00000001072f84c8 __48-[FlutterBasicMessageChannel setMessageHandler:]_block_invoke + 160", "7 Flutter 0x0000000106d65794 ___ZN7flutter25PlatformMessageHandlerIos21HandlePlatformMessageENSt3_fl10unique_ptrINS_15PlatformMessageENS1_14default_deleteIS3_EEEE_block_invoke + 116", "8 libdispatch.dylib 0x00000001c606e7a8 B51E7CDB-ABC9-35AF-B8BB-2DCE23BC4D6E + 407464", "9 libdispatch.dylib 0x00000001c606f780 B51E7CDB-ABC9-35AF-B8BB-2DCE23BC4D6E + 411520", "10 libdispatch.dylib 0x00000001c601bbdc B51E7CDB-ABC9-35AF-B8BB-2DCE23BC4D6E + 68572", "11 libdispatch.dylib 0x00000001c601b82c B51E7CDB-ABC9-35AF-B8BB-2DCE23BC4D6E + 67628", "12 CoreFoundation 0x00000001bf3519ac 55B9BA28-4C5C-3FE7-9C47-4983337D6E83 + 596396", "13 CoreFoundation 0x00000001bf335648 55B9BA28-4C5C-3FE7-9C47-4983337D6E83 + 480840", "14 CoreFoundation 0x00000001bf339d20 CFRunLoopRunSpecific + 584", "15 GraphicsServices 0x00000001f6b49998 GSEventRunModal + 160", "16 UIKitCore 0x00000001c15cc448 27A9C298-B702-3C39-8C06-07196E4CD16B + 3609672", "17 UIKitCore 0x00000001c15cc0c0 UIApplicationMain + 312", "18 Runner 0x0000000102c7895c main + 64", "19 dyld 0x00000001dcae4344 8A4B89B7-D348-375B-97B1-FC8A84E3E5CE + 82756"], null) flutter:

0 MyCentralManagerHostAPI.writeCharacteristic (package:bluetooth_low_energy_darwin/src/my_api.g.dart:861:7)

#1 MyCentralManager.writeCharacteristic (package:bluetooth_low_energy_darwin/src/my_central_manager.dart:183:5) ` This is my pubsec.yaml. ``` name: TestApp description: "A new Flutter project." publish_to: 'none' # Remove this line if you wish to publish to pub.dev version: 2.6.16+124823265 environment: sdk: '>=3.4.0 <4.0.0' dependencies: flutter: sdk: flutter cupertino_icons: ^1.0.2 change_app_package_name: ^1.1.0 firebase_core: ^2.25.5 firebase_auth: ^4.17.6 firebase_database: ^10.4.7 bluetooth_low_energy: ^6.0.0 udp: ^5.0.3 package_info_plus: ^8.0.0 http: ^1.2.0 intl: ^0.19.0 binary: ^3.0.1 shared_preferences: ^2.2.2 provider: ^6.1.2 firebase_storage: ^11.6.9 fast_cached_network_image: ^1.2.9 path_provider: ^2.1.2 shimmer: ^3.0.0 firebase_crashlytics: ^3.4.18 firebase_analytics: ^10.8.9 webview_windows: ^0.4.0 window_manager: ^0.3.8 webview_flutter: ^4.7.0 firebase_remote_config: ^4.3.17 responsive_sizer: ^3.3.1 flutter_svg: ^2.0.10+1 animations: ^2.0.11 upgrader: ^10.3.0 wakelock_plus: ^1.2.5 json_annotation: ^4.9.0 device_info_plus: ^10.1.0 jiffy: ^6.3.1 url_launcher: ^6.2.6 configcat_client: ^4.1.1 dev_dependencies: flutter_test: sdk: flutter integration_test: sdk: flutter flutter_lints: ^2.0.0 msix: ^3.16.7 flutter: uses-material-design: true ``` And here is the pubsec.lock ``` `# Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: _flutterfire_internals: dependency: transitive description: name: _flutterfire_internals sha256: "37a42d06068e2fe3deddb2da079a8c4d105f241225ba27b7122b37e9865fd8f7" url: "https://pub.dev" source: hosted version: "1.3.35" animations: dependency: "direct main" description: name: animations sha256: d3d6dcfb218225bbe68e87ccf6378bbb2e32a94900722c5f81611dad089911cb url: "https://pub.dev" source: hosted version: "2.0.11" archive: dependency: transitive description: name: archive sha256: cb6a278ef2dbb298455e1a713bda08524a175630ec643a242c399c932a0a1f7d url: "https://pub.dev" source: hosted version: "3.6.1" args: dependency: transitive description: name: args sha256: "7cf60b9f0cc88203c5a190b4cd62a99feea42759a7fa695010eb5de1c0b2252a" url: "https://pub.dev" source: hosted version: "2.5.0" async: dependency: transitive description: name: async sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" url: "https://pub.dev" source: hosted version: "2.11.0" binary: dependency: "direct main" description: name: binary sha256: e40eff285745e241c25b21a464b1437cbf56bad99c681de3783ff36fad52b707 url: "https://pub.dev" source: hosted version: "3.0.1" bluetooth_low_energy: dependency: "direct main" description: name: bluetooth_low_energy sha256: "057c146c3d5378f6a048b6a792cee7029bb185c7b3392dfb1605228325a5e336" url: "https://pub.dev" source: hosted version: "6.0.2" bluetooth_low_energy_android: dependency: transitive description: name: bluetooth_low_energy_android sha256: f8cbef16b980f96c09df5d1d46b61be9f05683866151440e9987796607a4e7d8 url: "https://pub.dev" source: hosted version: "6.0.3" bluetooth_low_energy_darwin: dependency: transitive description: name: bluetooth_low_energy_darwin sha256: "849ba53f7d34845ad7491cd9cdb3784301aa54fe682c91cab804ed55cfd259d5" url: "https://pub.dev" source: hosted version: "6.0.0" bluetooth_low_energy_linux: dependency: transitive description: name: bluetooth_low_energy_linux sha256: "4d1aaaede517f95320dcf9ad271091ab42c4ad8ba5bfa0e822744d850dcf0048" url: "https://pub.dev" source: hosted version: "6.0.0" bluetooth_low_energy_platform_interface: dependency: transitive description: name: bluetooth_low_energy_platform_interface sha256: bc2e8d97c141653e5747bcb3cdc9fe956541b6ecc6e5f158b99a2f3abc2d946a url: "https://pub.dev" source: hosted version: "6.0.0" bluetooth_low_energy_windows: dependency: transitive description: name: bluetooth_low_energy_windows sha256: "4904530cb3e7e1dd7a66919b4c926f8a03ed9924c3c2ce068aef7e0e10ced555" url: "https://pub.dev" source: hosted version: "6.0.0" bluez: dependency: transitive description: name: bluez sha256: "203a1924e818a9dd74af2b2c7a8f375ab8e5edf0e486bba8f90a0d8a17ed9fce" url: "https://pub.dev" source: hosted version: "0.8.2" boolean_selector: dependency: transitive description: name: boolean_selector sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" url: "https://pub.dev" source: hosted version: "2.1.1" change_app_package_name: dependency: "direct main" description: name: change_app_package_name sha256: "494e7943d4e8ba6a70970bf0fac293c866a121c50096dc9e027565bfbfc5c7a1" url: "https://pub.dev" source: hosted version: "1.2.0" characters: dependency: transitive description: name: characters sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" url: "https://pub.dev" source: hosted version: "1.3.0" cli_util: dependency: transitive description: name: cli_util sha256: c05b7406fdabc7a49a3929d4af76bcaccbbffcbcdcf185b082e1ae07da323d19 url: "https://pub.dev" source: hosted version: "0.4.1" clock: dependency: transitive description: name: clock sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf url: "https://pub.dev" source: hosted version: "1.1.1" collection: dependency: transitive description: name: collection sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a url: "https://pub.dev" source: hosted version: "1.18.0" configcat_client: dependency: "direct main" description: name: configcat_client sha256: c40d1c8ac28059b0b82e647903357f8deee83e48f94b9f08ba7ee7882587e3d1 url: "https://pub.dev" source: hosted version: "4.1.1" console: dependency: transitive description: name: console sha256: e04e7824384c5b39389acdd6dc7d33f3efe6b232f6f16d7626f194f6a01ad69a url: "https://pub.dev" source: hosted version: "4.1.0" crypto: dependency: transitive description: name: crypto sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab url: "https://pub.dev" source: hosted version: "3.0.3" csslib: dependency: transitive description: name: csslib sha256: "706b5707578e0c1b4b7550f64078f0a0f19dec3f50a178ffae7006b0a9ca58fb" url: "https://pub.dev" source: hosted version: "1.0.0" cupertino_icons: dependency: "direct main" description: name: cupertino_icons sha256: ba631d1c7f7bef6b729a622b7b752645a2d076dba9976925b8f25725a30e1ee6 url: "https://pub.dev" source: hosted version: "1.0.8" dbus: dependency: transitive description: name: dbus sha256: "365c771ac3b0e58845f39ec6deebc76e3276aa9922b0cc60840712094d9047ac" url: "https://pub.dev" source: hosted version: "0.7.10" device_info_plus: dependency: "direct main" description: name: device_info_plus sha256: eead12d1a1ed83d8283ab4c2f3fca23ac4082f29f25f29dff0f758f57d06ec91 url: "https://pub.dev" source: hosted version: "10.1.0" device_info_plus_platform_interface: dependency: transitive description: name: device_info_plus_platform_interface sha256: d3b01d5868b50ae571cd1dc6e502fc94d956b665756180f7b16ead09e836fd64 url: "https://pub.dev" source: hosted version: "7.0.0" dio: dependency: transitive description: name: dio sha256: "11e40df547d418cc0c4900a9318b26304e665da6fa4755399a9ff9efd09034b5" url: "https://pub.dev" source: hosted version: "5.4.3+1" fake_async: dependency: transitive description: name: fake_async sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" url: "https://pub.dev" source: hosted version: "1.3.1" fast_cached_network_image: dependency: "direct main" description: name: fast_cached_network_image sha256: "91f1d48d10e2916b83a1e7545c1eaf752f85b32acfb1473be1f9fa51d73afef0" url: "https://pub.dev" source: hosted version: "1.2.9" ffi: dependency: transitive description: name: ffi sha256: "493f37e7df1804778ff3a53bd691d8692ddf69702cf4c1c1096a2e41b4779e21" url: "https://pub.dev" source: hosted version: "2.1.2" file: dependency: transitive description: name: file sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c" url: "https://pub.dev" source: hosted version: "7.0.0" firebase_analytics: dependency: "direct main" description: name: firebase_analytics sha256: dbf1e7ab22cfb1f4a4adb103b46a26276b4edc593d4a78ef6fb942bafc92e035 url: "https://pub.dev" source: hosted version: "10.10.7" firebase_analytics_platform_interface: dependency: transitive description: name: firebase_analytics_platform_interface sha256: "3729b74f8cf1d974a27ba70332ecb55ff5ff560edc8164a6469f4a055b429c37" url: "https://pub.dev" source: hosted version: "3.10.8" firebase_analytics_web: dependency: transitive description: name: firebase_analytics_web sha256: "019cd7eee74254d33fbd2e29229367ce33063516bf6b3258a341d89e3b0f1655" url: "https://pub.dev" source: hosted version: "0.5.7+7" firebase_auth: dependency: "direct main" description: name: firebase_auth sha256: cfc2d970829202eca09e2896f0a5aa7c87302817ecc0bdfa954f026046bf10ba url: "https://pub.dev" source: hosted version: "4.20.0" firebase_auth_platform_interface: dependency: transitive description: name: firebase_auth_platform_interface sha256: a0270e1db3b2098a14cb2a2342b3cd2e7e458e0c391b1f64f6f78b14296ec093 url: "https://pub.dev" source: hosted version: "7.3.0" firebase_auth_web: dependency: transitive description: name: firebase_auth_web sha256: "64e067e763c6378b7e774e872f0f59f6812885e43020e25cde08f42e9459837b" url: "https://pub.dev" source: hosted version: "5.12.0" firebase_core: dependency: "direct main" description: name: firebase_core sha256: "26de145bb9688a90962faec6f838247377b0b0d32cc0abecd9a4e43525fc856c" url: "https://pub.dev" source: hosted version: "2.32.0" firebase_core_platform_interface: dependency: transitive description: name: firebase_core_platform_interface sha256: "1003a5a03a61fc9a22ef49f37cbcb9e46c86313a7b2e7029b9390cf8c6fc32cb" url: "https://pub.dev" source: hosted version: "5.1.0" firebase_core_web: dependency: transitive description: name: firebase_core_web sha256: "6643fe3dbd021e6ccfb751f7882b39df355708afbdeb4130fc50f9305a9d1a3d" url: "https://pub.dev" source: hosted version: "2.17.2" firebase_crashlytics: dependency: "direct main" description: name: firebase_crashlytics sha256: "9897c01efaa950d2f6da8317d12452749a74dc45f33b46390a14cfe28067f271" url: "https://pub.dev" source: hosted version: "3.5.7" firebase_crashlytics_platform_interface: dependency: transitive description: name: firebase_crashlytics_platform_interface sha256: "16a71e08fbf6e00382816e1b13397898c29a54fa0ad969c2c2a3b82a704877f0" url: "https://pub.dev" source: hosted version: "3.6.35" firebase_database: dependency: "direct main" description: name: firebase_database sha256: "3b9ca306d26ad243ccbc4c717ff6e8563a080ebe11ee77fa7349b419c894b42d" url: "https://pub.dev" source: hosted version: "10.5.7" firebase_database_platform_interface: dependency: transitive description: name: firebase_database_platform_interface sha256: "5864cc362275465e9bd682b243f19419c9d78b861c2db820241eea596ae3b320" url: "https://pub.dev" source: hosted version: "0.2.5+35" firebase_database_web: dependency: transitive description: name: firebase_database_web sha256: a6008395dd20e8b8dde0691b441c181a1216c3866f89f48dcb6889d34fd35905 url: "https://pub.dev" source: hosted version: "0.2.5+7" firebase_remote_config: dependency: "direct main" description: name: firebase_remote_config sha256: "653bd94b68e2c4e89eca10db90576101f1024151f39f2d4e7c64ae6a90a5f9c5" url: "https://pub.dev" source: hosted version: "4.4.7" firebase_remote_config_platform_interface: dependency: transitive description: name: firebase_remote_config_platform_interface sha256: "24a2c445b15de3af7e4582ebceb2aa9a1e3731d0202cb3e7a1e03012440fa07d" url: "https://pub.dev" source: hosted version: "1.4.35" firebase_remote_config_web: dependency: transitive description: name: firebase_remote_config_web sha256: "525aa3000fd27cd023841c802010a06515e564aab2f147aa964b35f54abbf449" url: "https://pub.dev" source: hosted version: "1.6.7" firebase_storage: dependency: "direct main" description: name: firebase_storage sha256: "2ae478ceec9f458c1bcbf0ee3e0100e4e909708979e83f16d5d9fba35a5b42c1" url: "https://pub.dev" source: hosted version: "11.7.7" firebase_storage_platform_interface: dependency: transitive description: name: firebase_storage_platform_interface sha256: "4e18662e6a66e2e0e181c06f94707de06d5097d70cfe2b5141bf64660c5b5da9" url: "https://pub.dev" source: hosted version: "5.1.22" firebase_storage_web: dependency: transitive description: name: firebase_storage_web sha256: "3a44aacd38a372efb159f6fe36bb4a7d79823949383816457fd43d3d47602a53" url: "https://pub.dev" source: hosted version: "3.9.7" fixnum: dependency: transitive description: name: fixnum sha256: "25517a4deb0c03aa0f32fd12db525856438902d9c16536311e76cdc57b31d7d1" url: "https://pub.dev" source: hosted version: "1.1.0" flutter: dependency: "direct main" description: flutter source: sdk version: "0.0.0" flutter_driver: dependency: transitive description: flutter source: sdk version: "0.0.0" flutter_lints: dependency: "direct dev" description: name: flutter_lints sha256: a25a15ebbdfc33ab1cd26c63a6ee519df92338a9c10f122adda92938253bef04 url: "https://pub.dev" source: hosted version: "2.0.3" flutter_svg: dependency: "direct main" description: name: flutter_svg sha256: "7b4ca6cf3304575fe9c8ec64813c8d02ee41d2afe60bcfe0678bcb5375d596a2" url: "https://pub.dev" source: hosted version: "2.0.10+1" flutter_test: dependency: "direct dev" description: flutter source: sdk version: "0.0.0" flutter_web_plugins: dependency: transitive description: flutter source: sdk version: "0.0.0" fuchsia_remote_debug_protocol: dependency: transitive description: flutter source: sdk version: "0.0.0" get_it: dependency: transitive description: name: get_it sha256: d85128a5dae4ea777324730dc65edd9c9f43155c109d5cc0a69cab74139fbac1 url: "https://pub.dev" source: hosted version: "7.7.0" hive: dependency: transitive description: name: hive sha256: "8dcf6db979d7933da8217edcec84e9df1bdb4e4edc7fc77dbd5aa74356d6d941" url: "https://pub.dev" source: hosted version: "2.2.3" hive_flutter: dependency: transitive description: name: hive_flutter sha256: dca1da446b1d808a51689fb5d0c6c9510c0a2ba01e22805d492c73b68e33eecc url: "https://pub.dev" source: hosted version: "1.1.0" html: dependency: transitive description: name: html sha256: "3a7812d5bcd2894edf53dfaf8cd640876cf6cef50a8f238745c8b8120ea74d3a" url: "https://pub.dev" source: hosted version: "0.15.4" http: dependency: "direct main" description: name: http sha256: "761a297c042deedc1ffbb156d6e2af13886bb305c2a343a4d972504cd67dd938" url: "https://pub.dev" source: hosted version: "1.2.1" http_parser: dependency: transitive description: name: http_parser sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b" url: "https://pub.dev" source: hosted version: "4.0.2" hybrid_logging: dependency: transitive description: name: hybrid_logging sha256: "54248d52ce68c14702a42fbc4083bac5c6be30f6afad8a41be4bbadd197b8af5" url: "https://pub.dev" source: hosted version: "1.0.0" image: dependency: transitive description: name: image sha256: "2237616a36c0d69aef7549ab439b833fb7f9fb9fc861af2cc9ac3eedddd69ca8" url: "https://pub.dev" source: hosted version: "4.2.0" integration_test: dependency: "direct dev" description: flutter source: sdk version: "0.0.0" intl: dependency: "direct main" description: name: intl sha256: d6f56758b7d3014a48af9701c085700aac781a92a87a62b1333b46d8879661cf url: "https://pub.dev" source: hosted version: "0.19.0" jiffy: dependency: "direct main" description: name: jiffy sha256: "3497caaa36d36a29033e66803c9739ce6bccbc7e241ca46070f76ee9e6f6eb0c" url: "https://pub.dev" source: hosted version: "6.3.1" json_annotation: dependency: "direct main" description: name: json_annotation sha256: "1ce844379ca14835a50d2f019a3099f419082cfdd231cd86a142af94dd5c6bb1" url: "https://pub.dev" source: hosted version: "4.9.0" leak_tracker: dependency: transitive description: name: leak_tracker sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a" url: "https://pub.dev" source: hosted version: "10.0.4" leak_tracker_flutter_testing: dependency: transitive description: name: leak_tracker_flutter_testing sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8" url: "https://pub.dev" source: hosted version: "3.0.3" leak_tracker_testing: dependency: transitive description: name: leak_tracker_testing sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3" url: "https://pub.dev" source: hosted version: "3.0.1" lints: dependency: transitive description: name: lints sha256: "0a217c6c989d21039f1498c3ed9f3ed71b354e69873f13a8dfc3c9fe76f1b452" url: "https://pub.dev" source: hosted version: "2.1.1" logging: dependency: transitive description: name: logging sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340" url: "https://pub.dev" source: hosted version: "1.2.0" matan: dependency: transitive description: name: matan sha256: "41e73fe0cd0e20ff22f4cdfdb66b1a02149e80b918fc43f3dc453ca5fb67830c" url: "https://pub.dev" source: hosted version: "1.0.0" matcher: dependency: transitive description: name: matcher sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb url: "https://pub.dev" source: hosted version: "0.12.16+1" material_color_utilities: dependency: transitive description: name: material_color_utilities sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" url: "https://pub.dev" source: hosted version: "0.8.0" meta: dependency: transitive description: name: meta sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136" url: "https://pub.dev" source: hosted version: "1.12.0" msix: dependency: "direct dev" description: name: msix sha256: "519b183d15dc9f9c594f247e2d2339d855cf0eaacc30e19b128e14f3ecc62047" url: "https://pub.dev" source: hosted version: "3.16.7" nested: dependency: transitive description: name: nested sha256: "03bac4c528c64c95c722ec99280375a6f2fc708eec17c7b3f07253b626cd2a20" url: "https://pub.dev" source: hosted version: "1.0.0" os_detect: dependency: transitive description: name: os_detect sha256: faf3bcf39515e64da8ff76b2f2805b20a6ff47ae515393e535f8579ff91d6b7f url: "https://pub.dev" source: hosted version: "2.0.1" package_config: dependency: transitive description: name: package_config sha256: "1c5b77ccc91e4823a5af61ee74e6b972db1ef98c2ff5a18d3161c982a55448bd" url: "https://pub.dev" source: hosted version: "2.1.0" package_info_plus: dependency: "direct main" description: name: package_info_plus sha256: b93d8b4d624b4ea19b0a5a208b2d6eff06004bc3ce74c06040b120eeadd00ce0 url: "https://pub.dev" source: hosted version: "8.0.0" package_info_plus_platform_interface: dependency: transitive description: name: package_info_plus_platform_interface sha256: f49918f3433a3146047372f9d4f1f847511f2acd5cd030e1f44fe5a50036b70e url: "https://pub.dev" source: hosted version: "3.0.0" path: dependency: transitive description: name: path sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" url: "https://pub.dev" source: hosted version: "1.9.0" path_parsing: dependency: transitive description: name: path_parsing sha256: e3e67b1629e6f7e8100b367d3db6ba6af4b1f0bb80f64db18ef1fbabd2fa9ccf url: "https://pub.dev" source: hosted version: "1.0.1" path_provider: dependency: "direct main" description: name: path_provider sha256: c9e7d3a4cd1410877472158bee69963a4579f78b68c65a2b7d40d1a7a88bb161 url: "https://pub.dev" source: hosted version: "2.1.3" path_provider_android: dependency: transitive description: name: path_provider_android sha256: bca87b0165ffd7cdb9cad8edd22d18d2201e886d9a9f19b4fb3452ea7df3a72a url: "https://pub.dev" source: hosted version: "2.2.6" path_provider_foundation: dependency: transitive description: name: path_provider_foundation sha256: f234384a3fdd67f989b4d54a5d73ca2a6c422fa55ae694381ae0f4375cd1ea16 url: "https://pub.dev" source: hosted version: "2.4.0" path_provider_linux: dependency: transitive description: name: path_provider_linux sha256: f7a1fe3a634fe7734c8d3f2766ad746ae2a2884abe22e241a8b301bf5cac3279 url: "https://pub.dev" source: hosted version: "2.2.1" path_provider_platform_interface: dependency: transitive description: name: path_provider_platform_interface sha256: "88f5779f72ba699763fa3a3b06aa4bf6de76c8e5de842cf6f29e2e06476c2334" url: "https://pub.dev" source: hosted version: "2.1.2" path_provider_windows: dependency: transitive description: name: path_provider_windows sha256: "8bc9f22eee8690981c22aa7fc602f5c85b497a6fb2ceb35ee5a5e5ed85ad8170" url: "https://pub.dev" source: hosted version: "2.2.1" petitparser: dependency: transitive description: name: petitparser sha256: c15605cd28af66339f8eb6fbe0e541bfe2d1b72d5825efc6598f3e0a31b9ad27 url: "https://pub.dev" source: hosted version: "6.0.2" platform: dependency: transitive description: name: platform sha256: "12220bb4b65720483f8fa9450b4332347737cf8213dd2840d8b2c823e47243ec" url: "https://pub.dev" source: hosted version: "3.1.4" plugin_platform_interface: dependency: transitive description: name: plugin_platform_interface sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02" url: "https://pub.dev" source: hosted version: "2.1.8" process: dependency: transitive description: name: process sha256: "21e54fd2faf1b5bdd5102afd25012184a6793927648ea81eea80552ac9405b32" url: "https://pub.dev" source: hosted version: "5.0.2" provider: dependency: "direct main" description: name: provider sha256: c8a055ee5ce3fd98d6fc872478b03823ffdb448699c6ebdbbc71d59b596fd48c url: "https://pub.dev" source: hosted version: "6.1.2" pub_semver: dependency: transitive description: name: pub_semver sha256: "40d3ab1bbd474c4c2328c91e3a7df8c6dd629b79ece4c4bd04bee496a224fb0c" url: "https://pub.dev" source: hosted version: "2.1.4" responsive_sizer: dependency: "direct main" description: name: responsive_sizer sha256: "6aefee6065c0883681bc7559147a24d8fa1846d296a216abcda25ff349340712" url: "https://pub.dev" source: hosted version: "3.3.1" screen_retriever: dependency: transitive description: name: screen_retriever sha256: "6ee02c8a1158e6dae7ca430da79436e3b1c9563c8cf02f524af997c201ac2b90" url: "https://pub.dev" source: hosted version: "0.1.9" shared_preferences: dependency: "direct main" description: name: shared_preferences sha256: d3bbe5553a986e83980916ded2f0b435ef2e1893dfaa29d5a7a790d0eca12180 url: "https://pub.dev" source: hosted version: "2.2.3" shared_preferences_android: dependency: transitive description: name: shared_preferences_android sha256: "93d0ec9dd902d85f326068e6a899487d1f65ffcd5798721a95330b26c8131577" url: "https://pub.dev" source: hosted version: "2.2.3" shared_preferences_foundation: dependency: transitive description: name: shared_preferences_foundation sha256: "0a8a893bf4fd1152f93fec03a415d11c27c74454d96e2318a7ac38dd18683ab7" url: "https://pub.dev" source: hosted version: "2.4.0" shared_preferences_linux: dependency: transitive description: name: shared_preferences_linux sha256: "9f2cbcf46d4270ea8be39fa156d86379077c8a5228d9dfdb1164ae0bb93f1faa" url: "https://pub.dev" source: hosted version: "2.3.2" shared_preferences_platform_interface: dependency: transitive description: name: shared_preferences_platform_interface sha256: "22e2ecac9419b4246d7c22bfbbda589e3acf5c0351137d87dd2939d984d37c3b" url: "https://pub.dev" source: hosted version: "2.3.2" shared_preferences_web: dependency: transitive description: name: shared_preferences_web sha256: "9aee1089b36bd2aafe06582b7d7817fd317ef05fc30e6ba14bff247d0933042a" url: "https://pub.dev" source: hosted version: "2.3.0" shared_preferences_windows: dependency: transitive description: name: shared_preferences_windows sha256: "841ad54f3c8381c480d0c9b508b89a34036f512482c407e6df7a9c4aa2ef8f59" url: "https://pub.dev" source: hosted version: "2.3.2" shimmer: dependency: "direct main" description: name: shimmer sha256: "5f88c883a22e9f9f299e5ba0e4f7e6054857224976a5d9f839d4ebdc94a14ac9" url: "https://pub.dev" source: hosted version: "3.0.0" sky_engine: dependency: transitive description: flutter source: sdk version: "0.0.99" source_span: dependency: transitive description: name: source_span sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" url: "https://pub.dev" source: hosted version: "1.10.0" sprintf: dependency: transitive description: name: sprintf sha256: "1fc9ffe69d4df602376b52949af107d8f5703b77cda567c4d7d86a0693120f23" url: "https://pub.dev" source: hosted version: "7.0.0" stack_trace: dependency: transitive description: name: stack_trace sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" url: "https://pub.dev" source: hosted version: "1.11.1" stream_channel: dependency: transitive description: name: stream_channel sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 url: "https://pub.dev" source: hosted version: "2.1.2" string_scanner: dependency: transitive description: name: string_scanner sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" url: "https://pub.dev" source: hosted version: "1.2.0" sync_http: dependency: transitive description: name: sync_http sha256: "7f0cd72eca000d2e026bcd6f990b81d0ca06022ef4e32fb257b30d3d1014a961" url: "https://pub.dev" source: hosted version: "0.3.1" term_glyph: dependency: transitive description: name: term_glyph sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 url: "https://pub.dev" source: hosted version: "1.2.1" test_api: dependency: transitive description: name: test_api sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" url: "https://pub.dev" source: hosted version: "0.7.0" typed_data: dependency: transitive description: name: typed_data sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c url: "https://pub.dev" source: hosted version: "1.3.2" udp: dependency: "direct main" description: name: udp sha256: "50ea45d7ee80ad4c62de4ec0e8ed3ae65c36e9fe8cd0655a2bcd1503d2708e5a" url: "https://pub.dev" source: hosted version: "5.0.3" upgrader: dependency: "direct main" description: name: upgrader sha256: d45483694620883107c2f5ca1dff7cdd4237b16810337a9c9c234203eb79eb5f url: "https://pub.dev" source: hosted version: "10.3.0" url_launcher: dependency: "direct main" description: name: url_launcher sha256: "21b704ce5fa560ea9f3b525b43601c678728ba46725bab9b01187b4831377ed3" url: "https://pub.dev" source: hosted version: "6.3.0" url_launcher_android: dependency: transitive description: name: url_launcher_android sha256: ceb2625f0c24ade6ef6778d1de0b2e44f2db71fded235eb52295247feba8c5cf url: "https://pub.dev" source: hosted version: "6.3.3" url_launcher_ios: dependency: transitive description: name: url_launcher_ios sha256: "7068716403343f6ba4969b4173cbf3b84fc768042124bc2c011e5d782b24fe89" url: "https://pub.dev" source: hosted version: "6.3.0" url_launcher_linux: dependency: transitive description: name: url_launcher_linux sha256: ab360eb661f8879369acac07b6bb3ff09d9471155357da8443fd5d3cf7363811 url: "https://pub.dev" source: hosted version: "3.1.1" url_launcher_macos: dependency: transitive description: name: url_launcher_macos sha256: "9a1a42d5d2d95400c795b2914c36fdcb525870c752569438e4ebb09a2b5d90de" url: "https://pub.dev" source: hosted version: "3.2.0" url_launcher_platform_interface: dependency: transitive description: name: url_launcher_platform_interface sha256: "552f8a1e663569be95a8190206a38187b531910283c3e982193e4f2733f01029" url: "https://pub.dev" source: hosted version: "2.3.2" url_launcher_web: dependency: transitive description: name: url_launcher_web sha256: "8d9e750d8c9338601e709cd0885f95825086bd8b642547f26bda435aade95d8a" url: "https://pub.dev" source: hosted version: "2.3.1" url_launcher_windows: dependency: transitive description: name: url_launcher_windows sha256: ecf9725510600aa2bb6d7ddabe16357691b6d2805f66216a97d1b881e21beff7 url: "https://pub.dev" source: hosted version: "3.1.1" uuid: dependency: transitive description: name: uuid sha256: "814e9e88f21a176ae1359149021870e87f7cddaf633ab678a5d2b0bff7fd1ba8" url: "https://pub.dev" source: hosted version: "4.4.0" vector_graphics: dependency: transitive description: name: vector_graphics sha256: "32c3c684e02f9bc0afb0ae0aa653337a2fe022e8ab064bcd7ffda27a74e288e3" url: "https://pub.dev" source: hosted version: "1.1.11+1" vector_graphics_codec: dependency: transitive description: name: vector_graphics_codec sha256: c86987475f162fadff579e7320c7ddda04cd2fdeffbe1129227a85d9ac9e03da url: "https://pub.dev" source: hosted version: "1.1.11+1" vector_graphics_compiler: dependency: transitive description: name: vector_graphics_compiler sha256: "12faff3f73b1741a36ca7e31b292ddeb629af819ca9efe9953b70bd63fc8cd81" url: "https://pub.dev" source: hosted version: "1.1.11+1" vector_math: dependency: transitive description: name: vector_math sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" url: "https://pub.dev" source: hosted version: "2.1.4" version: dependency: transitive description: name: version sha256: "3d4140128e6ea10d83da32fef2fa4003fccbf6852217bb854845802f04191f94" url: "https://pub.dev" source: hosted version: "3.0.2" vm_service: dependency: transitive description: name: vm_service sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec" url: "https://pub.dev" source: hosted version: "14.2.1" wakelock_plus: dependency: "direct main" description: name: wakelock_plus sha256: "14758533319a462ffb5aa3b7ddb198e59b29ac3b02da14173a1715d65d4e6e68" url: "https://pub.dev" source: hosted version: "1.2.5" wakelock_plus_platform_interface: dependency: transitive description: name: wakelock_plus_platform_interface sha256: "422d1cdbb448079a8a62a5a770b69baa489f8f7ca21aef47800c726d404f9d16" url: "https://pub.dev" source: hosted version: "1.2.1" web: dependency: transitive description: name: web sha256: "97da13628db363c635202ad97068d47c5b8aa555808e7a9411963c533b449b27" url: "https://pub.dev" source: hosted version: "0.5.1" webdriver: dependency: transitive description: name: webdriver sha256: "003d7da9519e1e5f329422b36c4dcdf18d7d2978d1ba099ea4e45ba490ed845e" url: "https://pub.dev" source: hosted version: "3.0.3" webview_flutter: dependency: "direct main" description: name: webview_flutter sha256: "6869c8786d179f929144b4a1f86e09ac0eddfe475984951ea6c634774c16b522" url: "https://pub.dev" source: hosted version: "4.8.0" webview_flutter_android: dependency: transitive description: name: webview_flutter_android sha256: f42447ca49523f11d8f70abea55ea211b3cafe172dd7a0e7ac007bb35dd356dc url: "https://pub.dev" source: hosted version: "3.16.4" webview_flutter_platform_interface: dependency: transitive description: name: webview_flutter_platform_interface sha256: d937581d6e558908d7ae3dc1989c4f87b786891ab47bb9df7de548a151779d8d url: "https://pub.dev" source: hosted version: "2.10.0" webview_flutter_wkwebview: dependency: transitive description: name: webview_flutter_wkwebview sha256: "7affdf9d680c015b11587181171d3cad8093e449db1f7d9f0f08f4f33d24f9a0" url: "https://pub.dev" source: hosted version: "3.13.1" webview_windows: dependency: "direct main" description: name: webview_windows sha256: "47fcad5875a45db29dbb5c9e6709bf5c88dcc429049872701343f91ed7255730" url: "https://pub.dev" source: hosted version: "0.4.0" win32: dependency: transitive description: name: win32 sha256: a79dbe579cb51ecd6d30b17e0cae4e0ea15e2c0e66f69ad4198f22a6789e94f4 url: "https://pub.dev" source: hosted version: "5.5.1" win32_registry: dependency: transitive description: name: win32_registry sha256: "10589e0d7f4e053f2c61023a31c9ce01146656a70b7b7f0828c0b46d7da2a9bb" url: "https://pub.dev" source: hosted version: "1.1.3" window_manager: dependency: "direct main" description: name: window_manager sha256: "8699323b30da4cdbe2aa2e7c9de567a6abd8a97d9a5c850a3c86dcd0b34bbfbf" url: "https://pub.dev" source: hosted version: "0.3.9" xdg_directories: dependency: transitive description: name: xdg_directories sha256: faea9dee56b520b55a566385b84f2e8de55e7496104adada9962e0bd11bcff1d url: "https://pub.dev" source: hosted version: "1.0.4" xml: dependency: transitive description: name: xml sha256: b015a8ad1c488f66851d762d3090a21c600e479dc75e68328c52774040cf9226 url: "https://pub.dev" source: hosted version: "6.5.0" yaml: dependency: transitive description: name: yaml sha256: "75769501ea3489fca56601ff33454fe45507ea3bfb014161abc3b43ae25989d5" url: "https://pub.dev" source: hosted version: "3.1.2" sdks: dart: ">=3.4.0 <4.0.0" flutter: ">=3.22.0" ` ```
yanshouwang commented 2 weeks ago

Can you provide a sample to reproduce this issue. From the logs above, it seems you passed invalid Peripheral or GATTCharacteristic instance, so the plugin can not find corresponding instance on native side which will throw illegalArgument error.

IvanTorres21 commented 1 week ago

Here is the issue replicated on a single page.

import 'dart:io';
import 'dart:typed_data';

import 'package:bluetooth_low_energy/bluetooth_low_energy.dart';
import 'package:flutter/material.dart';

class ReplicateIssue extends StatefulWidget {
  @override
  State<ReplicateIssue> createState() => _ReplicateIssueState();
}

class _ReplicateIssueState extends State<ReplicateIssue> {
  final List<DiscoveredEventArgs> _devices = List.empty(growable: true);
  final List<DiscoveredEventArgs> _connectedTo = List.empty(growable: true);
  List<GATTService> services = List.empty();
  final String commonCharacteristic = ""; // This is the common characteristic, both of the devices have this.
  final String commonCharacteristic2 = ""; // Same as above, they share this characteristic.

  bool isScanning = false;

  @override
  void initState() {
    scanDevices();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: [
          ElevatedButton(onPressed: sendMessage, child: Text("Send BLE Message")),
          SizedBox(
            height: MediaQuery.of(context).size.height * .6,
            child: ListView.builder(
              itemBuilder: (_, index) =>
                  ElevatedButton(onPressed: () => connectDevice(_devices[index]), child: Text("${_devices[index].advertisement.name}")),
              itemCount: _devices.length,
            ),
          )
        ],
      ),
    );
  }

  bool isWritting = false;
  Future<void> sendMessage() async {
    if(isWritting) return;
    isWritting = true;
    for(var device in _connectedTo) {
      await Bluetooth.writeCharacteristic(device.peripheral, getGattCharacteristic(commonCharacteristic2),  value: Uint8List.fromList([0x0]), type: GATTCharacteristicWriteType.withResponse);
    }
    isWritting = false;
  }

  void scanDevices() async {
    if(!Platform.isWindows) {
      await Bluetooth.authorize();
    }
    isScanning = true;
    Bluetooth.discovered.listen(AddDevice);
    while(isScanning) {
      await Future.delayed(const Duration(seconds: 1));
      await Bluetooth.startDiscovery();
      await Future.delayed(const Duration(seconds: 2));
      await Bluetooth.stopDiscovery();
    }
  }

   CentralManager get Bluetooth => CentralManager();

  void AddDevice(DiscoveredEventArgs event) {
    print(event.advertisement.name);
    if (_devices.any((x) => x.advertisement.name == event.advertisement.name)) return;
    setState(() {
      _devices.add(event);
    });
  }

  Future<void> connectDevice(DiscoveredEventArgs device) async {
    isScanning = false;
    await Bluetooth.stopDiscovery();

    await Bluetooth.connect(device.peripheral);
    services = await Bluetooth.discoverGATT(device.peripheral); //Both the devices we are connecting to are the same.
    _connectedTo.add(device);
    await Bluetooth.writeCharacteristic(device.peripheral, getGattCharacteristic(commonCharacteristic),  value: Uint8List.fromList([0x25]), type: GATTCharacteristicWriteType.withResponse);
  }

  GATTCharacteristic getGattCharacteristic(String whichOne) {
    for (var service in services) {
      for (var characteristic in service.characteristics) {
        if (UUID(characteristic) == whichOne) return characteristic;
      }
    }
    throw new Exception("Characteristic not found in any service");
  }

  String UUID(GATTCharacteristic gatt) => gatt.uuid.toString().toUpperCase();
}

As I said previously, when executing this in windows it works perfectly fine. But mobile throws the error. I´m using the same bluetooth devices for both attempts, and the bluetooth devices are the exact same.

yanshouwang commented 1 week ago

@IvanTorres21 There are issues in these two method.

Future<void> connectDevice(DiscoveredEventArgs device) async {
    isScanning = false;
    await Bluetooth.stopDiscovery();

    await Bluetooth.connect(device.peripheral);
    services = await Bluetooth.discoverGATT(device.peripheral); //Both the devices we are connecting to are the same.
    _connectedTo.add(device);
    await Bluetooth.writeCharacteristic(device.peripheral, getGattCharacteristic(commonCharacteristic),  value: Uint8List.fromList([0x25]), type: GATTCharacteristicWriteType.withResponse);
  }

  GATTCharacteristic getGattCharacteristic(String whichOne) {
    for (var service in services) {
      for (var characteristic in service.characteristics) {
        if (UUID(characteristic) == whichOne) return characteristic;
      }
    }
    throw new Exception("Characteristic not found in any service");
  }
  1. The services is set after the first deice connected, and will be replaced after the second device connected. As a result, the first device's service instances are lost.
  2. Since the two devices have the same services defination. When you get service for the first device, you can get a characteristic with UUID from the services without error, but the characteristic is belong to the second's actually. So the plugin will throw this error when you tell it to write to the first device but with the characteristic which belong to the second device.

This issus is not exist on Windows because the way I used to find corresponding native instance on Windows is different from the way on other platforms.

  1. On Windows, I use device address to find device instances, use GATT attribute handle to find GATT attribute instances. That means if the tow devices have the same service, characteristic and descriptor definations, the attribute handles are same too. So we can find the characteristic of the first device with the second device's characteristic without error in this case.
  2. On other platforms, I use object's hashCode to find the corresponding native instance. That's will cause the characteristic can't be found with the second characteristic's hashCode, so this error occured.
  3. On windows, it's not easy to use the hashCode because the c++ object doesn't have this. On other platforms, it's not possible to use the GATT attribute handle because the Bluetooth APIs doesn't have this.
IvanTorres21 commented 1 week ago

Ahhh, I see. Sorry then, I did the windows implementation first and since it worked thought it was a problem with the plugin itself.

Sorry for the issue, I´ll store the services twice then.