quick_blue icon indicating copy to clipboard operation
quick_blue copied to clipboard

[Windows] Lost connection to device when paired

Open maxzand opened this issue 3 years ago • 1 comments

Hi, I just want to say thank you so much for the package for BLE, I am still very new, but I want to help if I can. I am trying to use some services which require authorization (Apple Notification Center Service). For now, I am testing using LightBlue and creating a virtual peripheral. I noticed that when I try to pair my device manually in windows settings, the pairing is successful, but when I try to listen via setNotifiable(...) I lose connection to the device. This error disappears again if I go back into windows settings and unpair the device. I am fairly new to flutter or BLE so I may be misunderstanding some fundamentals.

Note: This code is running on Windows and communicating with my iPhone.

flutter doctor -v

[√] Flutter (Channel stable, 2.10.4, on Microsoft Windows [Version 10.0.22000.613], locale en-US) • Flutter version 2.10.4 at C:\Users\mazime\src\Flutter\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision c860cba910 (3 weeks ago), 2022-03-25 00:23:12 -0500 • Engine revision 57d3bac3dd • Dart version 2.16.2 • DevTools version 2.9.2 [√] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1) • Android SDK at C:\Users\Popsi\AppData\Local\Android\sdk [√] HTTP Host Availability • All required HTTP hosts are available • No issues found!

Code

  void _handleConnectionChange(String deviceId, BlueConnectionState state) {
    print('_handleConnectionChange $deviceId, $state');
    print(state.value);
    if (state.value == "connected") {
      print("Discovering Services!");
      //QuickBlue.discoverServices(deviceId); Not Necessary
      QuickBlue.setNotifiable(
          deviceId, serviceid, charid, BleInputProperty.notification);
    }
  }

What pairing looks like. image Note that both of these devices will appear after a single pairing attempt.

Not even the virtual LightBlue services work anymore

flutter: Alert Notification flutter: Found flutter: stopScan invokeMethod success flutter: _handleConnectionChange 104442226430328, Instance of 'BlueConnectionState' flutter: connected flutter: Discovering Services! flutter: _handleConnectionChange 104442226430328, Instance of 'BlueConnectionState' flutter: connected flutter: Discovering Services! Lost connection to device.

^ Ignore the random prints

When I click remove device and unpair the code begins to work again and I can easily listen to the virtual peripheral provided by LightBlue

flutter: _handleConnectionChange 105262347644159, Instance of 'BlueConnectionState' flutter: connected flutter: 5fbc4cd6ecff flutter: Discovering Services! flutter: _handleValueChange 105262347644159, 00002a46-0000-1000-8000-00805f9b34fb, 000000000f0e0d0000 flutter: _handleValueChange 105262347644159, 00002a46-0000-1000-8000-00805f9b34fb, 000000000f0e0d0000 flutter: _handleValueChange 105262347644159, 00002a46-0000-1000-8000-00805f9b34fb, 000000000f0e0d0000 flutter: _handleValueChange 105262347644159, 00002a46-0000-1000-8000-00805f9b34fb, 000000000f0e0d0000

I am hoping that pairing the device will not make my Windows computer unable to communicate with my iOS device as I think that many of Apple's built-in services require the device to be paired, although I may be wrong about that.

maxzand avatar Apr 18 '22 10:04 maxzand

Sorry. I don't have a pairable BLE device to test. I would recommand you post on to MSDN community or StackOverflow for help

Windows has a lot of glitches on BLE pairing: https://github.com/woodemi/quick_blue#windows-specific-info

There is a version restriction with Connection without pairing on C++/WinRT and Windows 10

Sunbreak avatar Apr 18 '22 11:04 Sunbreak