Search code examples
uwpwindows-10-iot-core

How do you scan for available WiFi networks from Windows IoT Background App?


Anybody know a work around for scanning for WiFi Network using a Windows IoT Background App (task)?

All possible solutions require a foreground app/UI thread (obviously not possible with a pure IoT Background App)

References: "If it is called from a background task, you will see an "Access Denied" error message or a similar message." - https://learn.microsoft.com/en-us/uwp/api/windows.devices.wifi.wifiadapter.scanasync

"DeviceUseTrigger cannot be used with in-process background tasks. The info in this topic only applies to background tasks that run out-of-process." - https://learn.microsoft.com/en-us/windows/uwp/launch-resume/access-sensors-and-devices-from-a-background-task


Solution

  • WiFiAdapter.ScanAsync method does not support in background task, it is by design. I think you can use Device Portal API to get the available wifi networks information.

    Firstly, /api/wifi/interfaces can enumerate the available wireless network interfaces, and then

    /api/wifi/networks can enumerate the list of wireless networks on the specified interface, in this api you can specify the interface with GUID on the request URI.

    In this workaround, you need to send http request in the background task. In addition, here is a client library that wraps the Windows Device Portal REST APIs. Hope that is helpful for you.

    You can also post a requirement via Feedback Hub App.The Feedback Hub app lets you tell Microsoft about any problems you run in to while using Windows 10 and send suggestions to help us improve your Windows experience.