chipweinberger / flutter_blue_plus

Flutter plugin for connecting and communicationg with Bluetooth Low Energy devices, on Android, iOS, macOS
Other
791 stars 478 forks source link

[Help]: BLE Advertisements Slow Down On iOS #801

Closed oooluwa closed 9 months ago

oooluwa commented 9 months ago

Requirements

Have you checked this problem on the example app?

Yes

FlutterBluePlus Version

1.31.15

Flutter Version

3.19.0

What OS?

iOS

OS Version

iPadOS 16.6, 17.3

Bluetooth Module

Nordic nRF52

What is your problem?

Our app listens to peripheral devices advertising data over BLE. We noticed that the app was missing some data packets and discovered that the BLE data being received from the flutter_blue_plus package slows down for about 1-3 seconds occasionally. The delay can be up to 5 or more seconds in some cases.

Here are the other things we have tried:

Has any other person experienced this issue? How can we solve it?

Logs

Each timestamp represents a new data packet. Notice the difference in timestamp after *After turning OFF peripheral and turning it ON again*

flutter: 🐛 BLE Service: 2024-02-29 15:41:30.730064
flutter: 🐛 BLE Service: 2024-02-29 15:41:30.730064
flutter: 🐛 BLE Service: 2024-02-29 15:41:30.730064
flutter: 🐛 BLE Service: 2024-02-29 15:41:30.730064
flutter: 🐛 BLE Service: 2024-02-29 15:41:30.783699
flutter: 🐛 BLE Service: 2024-02-29 15:41:30.905540
flutter: 🐛 BLE Service: 2024-02-29 15:41:31.034623
flutter: 🐛 BLE Service: 2024-02-29 15:41:31.152538
flutter: 🐛 BLE Service: 2024-02-29 15:41:31.152538
flutter: 🐛 BLE Service: 2024-02-29 15:41:31.402218
flutter: 🐛 BLE Service: 2024-02-29 15:41:32.502261
flutter: 🐛 BLE Service: 2024-02-29 15:41:32.621619
flutter: 🐛 BLE Service: 2024-02-29 15:41:33.107828
flutter: 🐛 BLE Service: 2024-02-29 15:41:33.234106
flutter: 🐛 BLE Service: 2024-02-29 15:41:33.356785
flutter: 🐛 BLE Service: 2024-02-29 15:41:33.475597
flutter: 🐛 BLE Service: 2024-02-29 15:41:37.018594
flutter: 🐛 BLE Service: 2024-02-29 15:41:37.139212
flutter: 🐛 BLE Service: 2024-02-29 15:41:41.539490
flutter: 🐛 BLE Service: 2024-02-29 15:41:43.618194
flutter: 🐛 BLE Service: 2024-02-29 15:41:43.985213
flutter: 🐛 BLE Service: 2024-02-29 15:41:44.108227
flutter: 🐛 BLE Service: 2024-02-29 15:41:44.235095
flutter: 🐛 BLE Service: 2024-02-29 15:41:44.356477
flutter: 🐛 BLE Service: 2024-02-29 15:41:44.840517
flutter: 🐛 BLE Service: 2024-02-29 15:41:45.450298
flutter: 🐛 BLE Service: 2024-02-29 15:41:45.704151
flutter: 🐛 BLE Service: 2024-02-29 15:41:45.817266
flutter: 🐛 BLE Service: 2024-02-29 15:41:45.939839
flutter: 🐛 BLE Service: 2024-02-29 15:41:46.057219
flutter: 🐛 BLE Service: 2024-02-29 15:41:46.186734
flutter: 🐛 BLE Service: 2024-02-29 15:41:46.310417
flutter: 🐛 BLE Service: 2024-02-29 15:41:46.555355
flutter: 🐛 BLE Service: 2024-02-29 15:41:46.792736
flutter: 🐛 BLE Service: 2024-02-29 15:41:46.921714
flutter: 🐛 BLE Service: 2024-02-29 15:41:47.288794
flutter: 🐛 BLE Service: 2024-02-29 15:41:47.408543
flutter: 🐛 BLE Service: 2024-02-29 15:41:47.525725
flutter: 🐛 BLE Service: 2024-02-29 15:41:47.652344
flutter: 🐛 BLE Service: 2024-02-29 15:41:47.900871
flutter: 🐛 BLE Service: 2024-02-29 15:41:48.018770
flutter: 🐛 BLE Service: 2024-02-29 15:41:48.141951
flutter: 🐛 BLE Service: 2024-02-29 15:41:48.262374
flutter: 🐛 BLE Service: 2024-02-29 15:41:48.388707
flutter: 🐛 BLE Service: 2024-02-29 15:41:48.510023
flutter: 🐛 BLE Service: 2024-02-29 15:41:48.753278
flutter: 🐛 BLE Service: 2024-02-29 15:41:49.113502
flutter: 🐛 BLE Service: 2024-02-29 15:41:49.486908
flutter: 🐛 BLE Service: 2024-02-29 15:41:49.608284
flutter: 🐛 BLE Service: 2024-02-29 15:41:49.737538
flutter: 🐛 BLE Service: 2024-02-29 15:41:49.852073
flutter: 🐛 BLE Service: 2024-02-29 15:41:49.969240
flutter: 🐛 BLE Service: 2024-02-29 15:41:50.088452
flutter: 🐛 BLE Service: 2024-02-29 15:41:50.223143
flutter: 🐛 BLE Service: 2024-02-29 15:41:50.337761
flutter: 🐛 BLE Service: 2024-02-29 15:41:50.955710
flutter: 🐛 BLE Service: 2024-02-29 15:41:51.806207
flutter: 🐛 BLE Service: 2024-02-29 15:41:52.055005
flutter: 🐛 BLE Service: 2024-02-29 15:41:52.291681
flutter: 🐛 BLE Service: 2024-02-29 15:42:04.507405
flutter: 🐛 BLE Service: 2024-02-29 15:42:06.224855
flutter: 🐛 BLE Service: 2024-02-29 15:42:06.356005
flutter: 🐛 BLE Service: 2024-02-29 15:42:06.586189
flutter: 🐛 BLE Service: 2024-02-29 15:42:06.837209
flutter: 🐛 BLE Service: 2024-02-29 15:42:06.956367
flutter: 🐛 BLE Service: 2024-02-29 15:42:07.202265
flutter: 🐛 BLE Service: 2024-02-29 15:42:07.320533
flutter: 🐛 BLE Service: 2024-02-29 15:42:07.569635
flutter: 🐛 BLE Service: 2024-02-29 15:42:09.280486
flutter: 🐛 BLE Service: 2024-02-29 15:42:09.280486
flutter: 🐛 BLE Service: 2024-02-29 15:42:09.519999
flutter: 🐛 BLE Service: 2024-02-29 15:42:10.136060
flutter: 🐛 BLE Service: 2024-02-29 15:42:10.379347
flutter: 🐛 BLE Service: 2024-02-29 15:42:10.498151
flutter: 🐛 BLE Service: 2024-02-29 15:42:10.622723
flutter: 🐛 BLE Service: 2024-02-29 15:42:10.743205
flutter: 🐛 BLE Service: 2024-02-29 15:42:11.237638
flutter: 🐛 BLE Service: 2024-02-29 15:42:12.706717
flutter: 🐛 BLE Service: 2024-02-29 15:42:12.821705
flutter: 🐛 BLE Service: 2024-02-29 15:42:12.941860
flutter: 🐛 BLE Service: 2024-02-29 15:42:13.061658
flutter: 🐛 BLE Service: 2024-02-29 15:42:13.434602
flutter: 🐛 BLE Service: 2024-02-29 15:42:13.559460
flutter: 🐛 BLE Service: 2024-02-29 15:42:13.677421
flutter: 🐛 BLE Service: 2024-02-29 15:42:15.994277
flutter: 🐛 BLE Service: 2024-02-29 15:42:16.243333
flutter: 🐛 BLE Service: 2024-02-29 15:42:16.488717
flutter: 🐛 BLE Service: 2024-02-29 15:42:16.735747
flutter: 🐛 BLE Service: 2024-02-29 15:42:16.857614
flutter: 🐛 BLE Service: 2024-02-29 15:42:17.096728
flutter: 🐛 BLE Service: 2024-02-29 15:42:17.217947
flutter: 🐛 BLE Service: 2024-02-29 15:42:17.338590
flutter: 🐛 BLE Service: 2024-02-29 15:42:17.338590
flutter: 🐛 BLE Service: 2024-02-29 15:42:17.338590
flutter: 🐛 BLE Service: 2024-02-29 15:42:17.827304
flutter: 🐛 BLE Service: 2024-02-29 15:42:19.174856
flutter: 🐛 BLE Service: 2024-02-29 15:42:20.390221
flutter: 🐛 BLE Service: 2024-02-29 15:42:21.869595
flutter: 🐛 BLE Service: 2024-02-29 15:42:22.224359
flutter: 🐛 BLE Service: 2024-02-29 15:42:25.527777
flutter: 🐛 BLE Service: 2024-02-29 15:42:25.656254
flutter: 🐛 BLE Service: 2024-02-29 15:42:25.769934
flutter: 🐛 BLE Service: 2024-02-29 15:42:25.897182
flutter: 🐛 BLE Service: 2024-02-29 15:42:26.258048
flutter: 🐛 BLE Service: 2024-02-29 15:42:26.506660
flutter: 🐛 BLE Service: 2024-02-29 15:42:26.625764
flutter: 🐛 BLE Service: 2024-02-29 15:42:26.748951
flutter: 🐛 BLE Service: 2024-02-29 15:42:28.460558
flutter: 🐛 BLE Service: 2024-02-29 15:42:28.589233
flutter: 🐛 BLE Service: 2024-02-29 15:42:28.706673
flutter: 🐛 BLE Service: 2024-02-29 15:42:28.829473
flutter: 🐛 BLE Service: 2024-02-29 15:42:28.956841
flutter: 🐛 BLE Service: 2024-02-29 15:42:29.196176
flutter: 🐛 BLE Service: 2024-02-29 15:42:29.320422
flutter: 🐛 BLE Service: 2024-02-29 15:42:29.441356
flutter: 🐛 BLE Service: 2024-02-29 15:42:29.557303
flutter: 🐛 BLE Service: 2024-02-29 15:42:29.677546
flutter: 🐛 BLE Service: 2024-02-29 15:42:29.798795
flutter: 🐛 BLE Service: 2024-02-29 15:42:29.925454
flutter: 🐛 BLE Service: 2024-02-29 15:42:30.165185
flutter: 🐛 BLE Service: 2024-02-29 15:42:31.393797
flutter: 🐛 BLE Service: 2024-02-29 15:42:31.887930
flutter: 🐛 BLE Service: 2024-02-29 15:42:32.004943
flutter: 🐛 BLE Service: 2024-02-29 15:42:32.247827
flutter: 🐛 BLE Service: 2024-02-29 15:42:32.365440
flutter: 🐛 BLE Service: 2024-02-29 15:42:32.492586
flutter: 🐛 BLE Service: 2024-02-29 15:42:32.614523
flutter: 🐛 BLE Service: 2024-02-29 15:42:32.737350
flutter: 🐛 BLE Service: 2024-02-29 15:42:34.937467
flutter: 🐛 BLE Service: 2024-02-29 15:42:35.056776
flutter: 🐛 BLE Service: 2024-02-29 15:42:35.181169
flutter: 🐛 BLE Service: 2024-02-29 15:42:35.542525
flutter: 🐛 BLE Service: 2024-02-29 15:42:35.789203
flutter: 🐛 BLE Service: 2024-02-29 15:42:35.914317
flutter: 🐛 BLE Service: 2024-02-29 15:42:36.032008
flutter: 🐛 BLE Service: 2024-02-29 15:42:36.275966
flutter: 🐛 BLE Service: 2024-02-29 15:42:36.392812
flutter: 🐛 BLE Service: 2024-02-29 15:42:37.989501
flutter: 🐛 BLE Service: 2024-02-29 15:42:38.354063
flutter: 🐛 BLE Service: 2024-02-29 15:42:38.476649
flutter: 🐛 BLE Service: 2024-02-29 15:42:38.598067
flutter: 🐛 BLE Service: 2024-02-29 15:42:38.724216
flutter: 🐛 BLE Service: 2024-02-29 15:42:38.961597
flutter: 🐛 BLE Service: 2024-02-29 15:42:39.091995
flutter: 🐛 BLE Service: 2024-02-29 15:42:39.331226
flutter: 🐛 BLE Service: 2024-02-29 15:42:39.575192
flutter: 🐛 BLE Service: 2024-02-29 15:42:40.924327
flutter: 🐛 BLE Service: 2024-02-29 15:42:41.170403
flutter: 🐛 BLE Service: 2024-02-29 15:42:41.289256
flutter: 🐛 BLE Service: 2024-02-29 15:42:41.406237
flutter: 🐛 BLE Service: 2024-02-29 15:42:41.529340
flutter: 🐛 BLE Service: 2024-02-29 15:42:41.659003
flutter: 🐛 BLE Service: 2024-02-29 15:42:41.774605
flutter: 🐛 BLE Service: 2024-02-29 15:42:41.904291
flutter: 🐛 BLE Service: 2024-02-29 15:42:42.137613
flutter: 🐛 BLE Service: 2024-02-29 15:42:42.258027
flutter: 🐛 BLE Service: 2024-02-29 15:42:42.387867
flutter: 🐛 BLE Service: 2024-02-29 15:42:42.510076
flutter: 🐛 BLE Service: 2024-02-29 15:42:42.748406
flutter: 🐛 BLE Service: 2024-02-29 15:42:43.113148
flutter: 🐛 BLE Service: 2024-02-29 15:42:44.342581
flutter: 🐛 BLE Service: 2024-02-29 15:42:44.957332
flutter: 🐛 BLE Service: 2024-02-29 15:42:45.324863
flutter: 🐛 BLE Service: 2024-02-29 15:42:45.687483
flutter: 🐛 BLE Service: 2024-02-29 15:42:46.048611
flutter: 🐛 BLE Service: 2024-02-29 15:42:51.294664
flutter: 🐛 BLE Service: 2024-02-29 15:42:51.424883
flutter: 🐛 BLE Service: 2024-02-29 15:42:51.546105
flutter: 🐛 BLE Service: 2024-02-29 15:42:51.794548
flutter: 🐛 BLE Service: 2024-02-29 15:42:51.907281
flutter: 🐛 BLE Service: 2024-02-29 15:42:52.038649
flutter: 🐛 BLE Service: 2024-02-29 15:42:52.395705
flutter: 🐛 BLE Service: 2024-02-29 15:42:53.007956
flutter: 🐛 BLE Service: 2024-02-29 15:42:54.725195
flutter: 🐛 BLE Service: 2024-02-29 15:42:55.455706
flutter: 🐛 BLE Service: 2024-02-29 15:42:55.811529
flutter: 🐛 BLE Service: 2024-02-29 15:42:57.775136
flutter: 🐛 BLE Service: 2024-02-29 15:42:58.021567
flutter: 🐛 BLE Service: 2024-02-29 15:42:58.130814
flutter: 🐛 BLE Service: 2024-02-29 15:42:58.378479
flutter: 🐛 BLE Service: 2024-02-29 15:42:58.507931
flutter: 🐛 BLE Service: 2024-02-29 15:42:58.863790
flutter: 🐛 BLE Service: 2024-02-29 15:43:01.191126
flutter: 🐛 BLE Service: 2024-02-29 15:43:01.557681
flutter: 🐛 BLE Service: 2024-02-29 15:43:01.799462
flutter: 🐛 BLE Service: 2024-02-29 15:43:01.922217
flutter: 🐛 BLE Service: 2024-02-29 15:43:02.290994
flutter: 🐛 BLE Service: 2024-02-29 15:43:02.656114
flutter: 🐛 BLE Service: 2024-02-29 15:43:02.895082
flutter: 🐛 BLE Service: 2024-02-29 15:43:03.633217
flutter: 🐛 BLE Service: 2024-02-29 15:43:04.607911
flutter: 🐛 BLE Service: 2024-02-29 15:43:04.846562
flutter: 🐛 BLE Service: 2024-02-29 15:43:04.976287
flutter: 🐛 BLE Service: 2024-02-29 15:43:05.226270
flutter: 🐛 BLE Service: 2024-02-29 15:43:05.342111
flutter: 🐛 BLE Service: 2024-02-29 15:43:05.825200
flutter: 🐛 BLE Service: 2024-02-29 15:43:06.073495
flutter: 🐛 BLE Service: 2024-02-29 15:43:08.144822
flutter: 🐛 BLE Service: 2024-02-29 15:43:08.264352
flutter: 🐛 BLE Service: 2024-02-29 15:43:08.391964
flutter: 🐛 BLE Service: 2024-02-29 15:43:08.576204

After turning OFF peripheral and turning it ON again

flutter: 🐛 BLE Service: 2024-02-29 15:43:08.576204
flutter: 🐛 BLE Service: 2024-02-29 15:43:08.576204
flutter: 🐛 BLE Service: 2024-02-29 15:44:06.158156
flutter: 🐛 BLE Service: 2024-02-29 15:44:06.766008
flutter: 🐛 BLE Service: 2024-02-29 15:44:07.379573
flutter: 🐛 BLE Service: 2024-02-29 15:44:10.058008
flutter: 🐛 BLE Service: 2024-02-29 15:44:10.664066
flutter: 🐛 BLE Service: 2024-02-29 15:44:21.168758
flutter: 🐛 BLE Service: 2024-02-29 15:44:26.540021
flutter: 🐛 BLE Service: 2024-02-29 15:44:30.434947
flutter: 🐛 BLE Service: 2024-02-29 15:44:31.664129
flutter: 🐛 BLE Service: 2024-02-29 15:44:34.340325
flutter: 🐛 BLE Service: 2024-02-29 15:44:34.954245
flutter: 🐛 BLE Service: 2024-02-29 15:44:34.954245
chipweinberger commented 9 months ago

how are you reading the data? are you using setNotifyValue? or are you manually calling read?

oooluwa commented 9 months ago

how are you reading the data? are you using setNotifyValue? or are you manually calling read?

Not sure I understand that. This is the function that listens to the devices:

Stream<BleDeviceModel> get advertisingDevices async* {
    try {
      await for (List<ScanResult> results in FlutterBluePlus.scanResults) {
        for (ScanResult result in results) {
          if (result.advertisementData.manufacturerData.isEmpty) {
            continue;
          }

          var mfgId = result.advertisementData.manufacturerData.entries.first.key;
          if (mfgId == _kOurId) {
            if (_minRssiThreshold == null || result.rssi > _minRssiThreshold!) {
              _logger.d("BLE Service: ${result.timeStamp}");
              yield result;
            }
          }
        }
      }
    } on Exception catch (e) {
      _logger.e(e.toString());
      throw AppException(e.toString());
    }
  }
chipweinberger commented 9 months ago

I see.

scan results come straight from the operating system

i'm not aware of anything FBP could change to improve your situation

chipweinberger commented 9 months ago

if you figure it out, please report back

it could be a problem with your device.

try different ios version also if possible

oooluwa commented 8 months ago

To achieve our goal, we set the continuousUpdates flag to true and set a timer to start the scanner every 5 seconds. It seems a little hacky but this is the only way to achieve our use case.