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 Watcher sometimes fails to restart #1400

Open
orineman opened this issue Nov 7, 2023 · 1 comment
Open

WiFiDirect Watcher sometimes fails to restart #1400

orineman opened this issue Nov 7, 2023 · 1 comment
Labels

Comments

@orineman
Copy link

orineman commented Nov 7, 2023

Which sample are you reporting a bug in?

WiFi Direct

Describe the bug

When running as a Connector, restarting the watcher will sometimes fail.

To Reproduce
Steps to reproduce the behavior:

  1. Run the WiFiDirect C# sample.
  2. Select Connector
  3. Click Start Watcher
  4. Do some connection testing
  5. Click Stop Watcher
  6. Click Start Watcher

It randomly fails. When it fails, the WiFiDirectAdvertisementPublisher is still in Started state when Start() is called.

Expected behavior

It should always be possible to stop/restart the watcher.

Configuration

  • Language/architecture/flavor: C#
  • Windows platform and build number: Windows 11, various
  • Visual Studio version: Various, currently 17.4.4

Additional context

Workarounds are:

  1. If the WiFiDirectAdvertisementPublisher isn't in Stopped, Created or Aborted state when going to start it, call Stop() then create a new WiFiDirectAdvertisementPublisher.
  2. Don't bother stopping the WiFiDirectAdvertisementPublisher when stopping/starting the watcher. This certainly seems to work, but what is the WiFiDirectAdvertisementPublisher doing in this case? Is it responsible for sending out the ProbeRequests? If so, it would seem to be harmless leaving it around as ProbeRequests only get sent for 5 seconds(!) after starting the DeviceWatcher.

It is likely this is an OS problem, but it's out in the wild and apps can't rely on it being fixed. Therefore the samples should workaround it.

@orineman orineman added the bug label Nov 7, 2023
@orineman
Copy link
Author

I gave up on using a DeviceWatcher. Since it only sends out ProbeRequests for 5 seconds, I'd have to keep calling it.

I found calling the following every 30 seconds or so more reliable:

		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);

Note the addtion of L"System.Devices.Aep.CanPair", L"System.Devices.Aep.IsPaired" to get correct pairing information.

The downside is the first call takes a few seconds before you see the devices.

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

1 participant