LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Find SSIDs of available WIFI networks

Solved!
Go to solution

I am trying to find out how to get a list of the SSIDs of available WIFI networks from LabVIEW.  We are doing automated manufacturing testing on a product which has a WIFI chip and is set up to act as a WIFI access point.  When the device is powered, it broadcasts its SSID, and a nearby computer can connect to the access point and then communicate with device to read data and set parameters using http.  We want the manufacturing test to confirm that the WIFI hardware is working by confirming that the SSID is being broadcast.  Up until now, this has been done manually by observing the available networks in Windows.  How do I get a list of the available networks in LabVIEW?  I found something close to what is needed here  https://forums.ni.com/t5/Example-Code/WiFi-Network-Scanning-and-Connecting-with-LabVIEW/ta-p/3731977. and here https://forums.ni.com/t5/Example-Code/WiFi-Library-for-LabVIEW/ta-p/3736625.  Show Networks.vi  uses the command "netsh wlan show networks" in a command line to get a list of the networks, but this does not seem to work reliably.  Sometimes it shows most or all of the available networks, sometimes it only shows the network that is currently connected, and sometimes it shows old results (does not detect a newly available network for a minute after the network becomes available).  Any thoughts on how to reliably do what I want in LabVIEW.  I'm wondering whether there is a way to do it using WMI and dotnet nodes.

0 Kudos
Message 1 of 11
(8,005 Views)

Try using the System Exec with the command line "netsh wlan show networks", then parse the returned list.

 

wifiCapture.PNG

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 2 of 11
(7,923 Views)

I tried "netsh wlan show networks" before and have run into issues with it.  It appears that "netsh wlan show networks" does not cause the computer to scan for available networks, but only returns a cached list.  If the computer is connected to a WiFi network and has not scanned for some time, "netsh wlan show networks" only returns the currently connected network.  Clicking the WiFi icon on the Windows taskbar or executing "explorer.exe ms-availablenetworks:" forces a scan, after which "netsh wlan show networks" will return all the available networks.  Unfortunately, clicking the WiFi icon on the Windows taskbar or executing "explorer.exe ms-availablenetworks:" again will not force a scan again unless some time has elapsed since the last scan.  The list of available networks becomes stale.

"netsh wlan show networks" would work for me if there was a way to force a scan for networks from LabVIEW even if a scan was done recently.  Do you know how to do this?

0 Kudos
Message 3 of 11
(7,896 Views)

I recommend to critically asses if parsing a command output intended for human consumption is applicable to your problem. If your program has any perspective of running on a system not directly controlled by you, someone might mess up the language settings to the point where the parser breaks. Notice that the example output in https://forums.ni.com/t5/Example-Code/WiFi-Library-for-LabVIEW/ta-p/3736625 is from a system set to German language, but the umlauts ("Verschlsselung") are missing. Also, the network type ("Infrastructure") got translated to "Infrastruktur".

 

If you need the program to be portable, try https://learn.microsoft.com/en-us/uwp/api/windows.devices.wifi.wifiadapter.scanasync?view=winrt-1836... or https://learn.microsoft.com/en-us/windows/win32/api/wlanapi/nf-wlanapi-wlanscan.

Message 4 of 11
(7,870 Views)
Solution
Accepted by cbfsystems

Try if this works.

 

LabVIEW 2018

Rolf Kalbermatter
My Blog
Message 5 of 11
(7,812 Views)

Thanks for pointing to the Native WiFi API.  I took a look at the link and read a bit, but haven't actually tried it yet.  It looks like I will have to download a Microsoft SDK and use some code interface nodes.  It looks like this may do what I want though.

By the way, I appreciate your warning about parsing a message meant for human consumption.  It feels a lot more reliable to use an API that is meant for a machine.

0 Kudos
Message 6 of 11
(7,781 Views)

@cbfsystems wrote:

Thanks for pointing to the Native WiFi API.  I took a look at the link and read a bit, but haven't actually tried it yet.  It looks like I will have to download a Microsoft SDK and use some code interface nodes.  It looks like this may do what I want though.


The VI library I posted in the post before yours does interface to the Windows APIs and provides functions to list the WIFI interfaces, scan for networks on an interface and list those networks on an interface.

Rolf Kalbermatter
My Blog
0 Kudos
Message 7 of 11
(7,758 Views)

I looking over WLAN Library.zip right now.  I see that it is using the functions from the Native WiFi API from windows and doing the hard stuff that I was going to have to figure out.  Where does that library come from and what is its licence agreement?  Can I use it in production code that is shipped to a client?

0 Kudos
Message 8 of 11
(7,752 Views)

I developed it over the weekend as an exercise. Use at your own risk and as you wish, except trying to pass it off as your own creation.

Rolf Kalbermatter
My Blog
0 Kudos
Message 9 of 11
(7,749 Views)

Thank you everyone for your suggestions, and thank you Rolf for the WLAN library.  I have tried this out, and it seems to do what I need.  I was considering using the Native WiFi API that LLindenbauer linked to, but your library has done that and saved me a lot of headache.  I have used code interface nodes and the LabVIEW memory manager functions before, but not a lot, so it would have been a lot of trouble to figure out how to do this on my own.  I am still going through the library and the API documentation to try to understand how the library works, but that is easier than trying to figure it out from scratch.

 

I'm still a little in the dark about how Windows or the WiFi interface handles scanning for available WiFi networks.  It appears that it I run Get Interfaces.vi (scan and then list available networks) every few seconds, a new network shows up quickly when the associated device is turned on, but after the device is turned off, the network still shows up in the list of available networks for quite a while.  I'm a little surprised that the network did not disappear from the list right away, but this is acceptable for my use case.

 

One other thing.  Scan Networks.vi checks for a return code of 170 from WlanScan.  Do you know what causes that code to be returned?

0 Kudos
Message 10 of 11
(7,632 Views)