quick_blue icon indicating copy to clipboard operation
quick_blue copied to clipboard

Add Pair Method for Windows

Open rohitsangwan01 opened this issue 3 years ago • 12 comments

@Sunbreak Added Pair method for Windows Platform , Thanks to kinyoklion it will throw Unimplemented Error for Other Platforms also update Example to show Pair button for Windows Platform

rohitsangwan01 avatar Jun 06 '22 16:06 rohitsangwan01

I prefer add BIG features into https://github.com/woodemi/quick.flutter

https://pub.dev/packages/quick_notify/versions/0.3.0-dev.0 has been released within quick.flutter

Sunbreak avatar Jun 06 '22 23:06 Sunbreak

https://pub.dev/packages/quick_notify/versions/0.3.0-dev.0

when are you planning to release quick_blue from quick.flutter ??

rohitsangwan01 avatar Jun 07 '22 04:06 rohitsangwan01

@rohitsangwan01 device disconnects while pairing in windows... in rohitsangwan01:add_pairAsync branch example [+7106 ms] flutter: _handleConnectionChange 259603888117496, connected after clicking pair button, this log comes : [+6697 ms] flutter: _handleConnectionChange 259603888117496, disconnected

VishavjeetSingh8 avatar Jul 01 '22 06:07 VishavjeetSingh8

@rohitsangwan01 device disconnects while pairing in windows... in rohitsangwan01:add_pairAsync branch example [+7106 ms] flutter: _handleConnectionChange 259603888117496, connected after clicking pair button, this log comes : [+6697 ms] flutter: _handleConnectionChange 259603888117496, disconnected

probably because this device does not supports pairing , can you confirm

rohitsangwan01 avatar Jul 01 '22 12:07 rohitsangwan01

@rohitsangwan01 device supports pairing. It pairs successfully with microsoft https://github.com/microsoft/BluetoothLEExplorer app. My device requests a pin while pairing and hardware using BGX13P.

VishavjeetSingh8 avatar Jul 01 '22 12:07 VishavjeetSingh8

@rohitsangwan01 device supports pairing. It pairs successfully with microsoft https://github.com/microsoft/BluetoothLEExplorer app. My device requests a pin while pairing and hardware using BGX13P.

Can you check from Windows setting , after clicking on Pair from App , your device will disconnect from QuickBlue , and when you go to windows settings , it will appear there as Paired , you can now connect back again to the device in QuickBlue i faced this behaviour with a device i used which does not supports pairing , you can try to play with the PairAsync options in Windows native code

rohitsangwan01 avatar Jul 01 '22 14:07 rohitsangwan01

I have checked the code and confirm it is an issue when we are using a device with pin..

I have used following code in my device and its working... If you can test this please confirm.

We have to use DevicePairingKinds : ProvidePin with args.Accept(winrt::to_hstring(L" YOUR DEVICE PIN "));

winrt::fire_and_forget QuickBlueWindowsPlugin::PairAsync(uint64_t bluetoothAddress, DevicePairingProtectionLevel level) {
  auto device = co_await BluetoothLEDevice::FromBluetoothAddressAsync(bluetoothAddress);
  if(device != nullptr) {
    if(device.DeviceInformation().Pairing().CanPair()) {
      try {
        device.DeviceInformation().Pairing().Custom().PairingRequested({ this, &QuickBlueWindowsPlugin::BluetoothLEDevice_PairingRequested });
        auto result = co_await device.DeviceInformation().Pairing().Custom().PairAsync(DevicePairingKinds::ProvidePin);
        if(result.Status() != DevicePairingResultStatus::Paired && result.Status() != DevicePairingResultStatus::AlreadyPaired) {
          OutputDebugString((L"PairAsync error: " + winrt::to_hstring((int32_t)result.Status()) + L"\n").c_str());
        }
      } catch(winrt::hresult_error const& ex) {
        OutputDebugString((L"PairAsync " + ex.message() + L"\n").c_str());
      }
    }
  }
  co_return;
}
void QuickBlueWindowsPlugin::BluetoothLEDevice_PairingRequested(DeviceInformationCustomPairing sender, DevicePairingRequestedEventArgs args) {
  args.Accept(winrt::to_hstring(L"000000")); //DEVICE PIN IS ENTERED AS ARGUMENT
}

VishavjeetSingh8 avatar Jul 02 '22 06:07 VishavjeetSingh8

void QuickBlueWindowsPlugin::BluetoothLEDevice_PairingRequested(DeviceInformationCustomPairing sender, DevicePairingRequestedEventArgs args) { args.Accept(winrt::to_hstring(L"000000")); //DEVICE PIN IS ENTERED AS ARGUMENT }

Got it , and some device paired without Pin , we need to find a way to fix this , btw can you test Pair method in new QucikBlue.flutter , here i added a PR , added Pair method in Windows and Android

rohitsangwan01 avatar Jul 02 '22 10:07 rohitsangwan01

I tested https://github.com/woodemi/quick.flutter/pull/33 also and the same error occurs in windows..

VishavjeetSingh8 avatar Jul 04 '22 07:07 VishavjeetSingh8

Android pairing code works fine btw

VishavjeetSingh8 avatar Jul 04 '22 07:07 VishavjeetSingh8

@Vishavjeet-clarity can you add this comment on That PR, it will be easy to track and fix

rohitsangwan01 avatar Jul 04 '22 08:07 rohitsangwan01

Done

VishavjeetSingh8 avatar Jul 04 '22 08:07 VishavjeetSingh8