Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Pair Method for Windows #116

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

rohitsangwan01
Copy link

@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

dependency_overrides:
quick_blue_platform_interface:
path: ../quick_blue_platform_interface

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for here. There is a dependency_overrides in quick_blue_example

@Sunbreak
Copy link
Collaborator

Sunbreak commented Jun 6, 2022

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

@rohitsangwan01
Copy link
Author

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

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

@VishavjeetSingh8
Copy link

@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

@rohitsangwan01
Copy link
Author

@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

@VishavjeetSingh8
Copy link

@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.

@rohitsangwan01
Copy link
Author

@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

@VishavjeetSingh8
Copy link

VishavjeetSingh8 commented Jul 2, 2022

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
}

@rohitsangwan01
Copy link
Author

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

@VishavjeetSingh8
Copy link

VishavjeetSingh8 commented Jul 4, 2022

I tested woodemi/quick.flutter#33 also and the same error occurs in windows..

@VishavjeetSingh8
Copy link

Android pairing code works fine btw

@rohitsangwan01
Copy link
Author

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

@VishavjeetSingh8
Copy link

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants