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

WiFiDirect cppwinrt misplaced '}' #1401

Open
orineman opened this issue Nov 8, 2023 · 3 comments
Open

WiFiDirect cppwinrt misplaced '}' #1401

orineman opened this issue Nov 8, 2023 · 3 comments
Labels

Comments

@orineman
Copy link

orineman commented Nov 8, 2023

Which sample are you reporting a bug in?

WifiDirect/cppwinrt

Describe the bug

Listener fails to accept connection from an unpaired device.

To Reproduce
Steps to reproduce the behavior:

Run the sample, start a listener using default settings, try to connect to it from an unpaired device.

Expected behavior

It should work the same as the C# sample and successfully connect.

Configuration

Any.

Additional context

The '}' currently at line 235 should be at line 182 in Scenario1_Advertiser.cpp. I.e. immediately before the following user notification:

rootPage.NotifyUser(L"Connecting to " + deviceName + L"...", NotifyType::StatusMessage);

See also Scenario1_Advertiser.xaml.cs in th C# sample which has identical flow.

@orineman orineman added the bug label Nov 8, 2023
@yanfangliu-google
Copy link

I also saw this problem. After you fixed it, do you get the GO and GC connected?

@orineman
Copy link
Author

I believe so. I worked more with the C# sample. So see also #1399.

Best way of testing is to make sure the devices aren't already paired and get the C# sample working first.

Life will be better if you make this change to Scenario2_Connector.cpp at approx. line 78.

            deviceWatcher = DeviceInformation::CreateWatcher(deviceSelector, { L"System.Devices.WiFiDirect.InformationElements", L"System.Devices.Aep.CanPair", L"System.Devices.Aep.IsPaired" });

It will make it correctly report the pairing status for the device you are connecting to and stop it from trying to pair when already paired (which fails).

          co_await clientSocket.ConnectAsync(remoteHostName, ServerPortString);

is throwing an exception for me at the moment, but it does make the WiFi Direct connection, but I haven't run this code for a couple of months.

I let all the GO settings default and add "Push button" configuration methods on both sides. I suggest trying this first.

Note that the Advertiser only advertises for a couple of minutes and the Connector only looks for a few seconds. Once it says the enumeration is complete, you won't see any more devices until you stop/restart the watcher.

You are better off doing this:

		WiFiDirectDevice wiFiDevice = WiFiDirectDevice(nullptr);
		hstring selector = wiFiDevice.GetDeviceSelector(WiFiDirectDeviceSelectorType::AssociationEndpoint);

		co_await resume_background();
		DeviceInformationCollection devices = co_await DeviceInformation::FindAllAsync(
			selector,
			{
				L"System.Devices.Aep.CanPair",
				L"System.Devices.Aep.IsPaired",
				L"System.Devices.WiFiDirect.InformationElements"
			}
		);
		co_await winrt::resume_foreground(_queue);

every 30 seconds or so while you aren't suspended.

@yanfangliu-google
Copy link

@orineman After look at your reply and the link you mentioned, I realize that only GC needs to do DeviceInformationCustomPairing::PairAsync(...), then both side can get a valid IP address and ping each other. But the problem is that how to use WiFiDirectConfigurationMethod::DisplayPin and ProvidePin? PushButton is kind of unsafe.
I don't see WiFiDirectConnectionParameters::PairingRequested call back handler get called at any situation.
I mentioned this problem in issue #1406

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

No branches or pull requests

2 participants