ios - BLE scan window and scan Interval for Android - Stack Overflow

admin2025-04-10  0

I'm designing a flutter application for BLE communication with a BLE device which is supposed to advertise at an advertising interval of 2sec (power optimisation reasons), My issue arises when I'm scanning and trying to connect to the device. The time taken to discover and connect to the device is very large on Android.

Upon reading some more (I maybe wrong and am open to ideas), I found that iOS has a burst scanning mechanism making it extremely efficient at quickly scanning for devices, however Android is limited in this aspect.

I read that I need to modify the scan_window & scan_interval to achieve what I want, however as of my knowledge I think it is not possible, or is it? Is there something else that I can do to tackle this situation?

I'm using flutter_blue_plus as my wrapper, what can I do to achieve iOS like functionality while keeping the parameters mostly same?

Following are my scan_params -

FlutterBluePlus.startScan(
  timeout: const Duration(seconds: 7),
  androidScanMode: AndroidScanMode.lowLatency,
  withNames: ['Demo Lock'],
);

Connect params -

Future<bool> connectToDevice(String bleAddress) async {
    try {
      final device = BluetoothDevice(remoteId: DeviceIdentifier(bleAddress));

      await device.connect();
      print('Connected to $bleAddress');

      await readData(device);

      return true;
    } catch (e) {
      print('Error connecting to device: $e');
      return false;
    }
  }

Android Connection Time - 3 to 12 sec

iOS Connection Time avg - 3 to 4 sec

(The BLE device has an adv interval of 2sec and is advertising from all three channels)

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1744284719a239656.html

最新回复(0)