Determine whether or not Internet access is available by attempting a TCP connection to the "Microsoft Network Connectivity Status Indicator" (NCSI) web service.
Use cases
Determine whether or not the RT target can connect to other Internet hosts
Does not require the “HTTP Client with SSL Support” Academic RIO Device software set add-on, an advantage if your application does not otherwise require HTTP services (each add-on consumes space on the RT target file system)
Code runs on either the RT target or PC host without modification
Use as a stand-alone VI or incorporate the code directly into your block diagram
Keep in mind
The “Microsoft NCSI” string normally returned by the web service is not retrieved nor checked by this TCP connection-based approach; for increased confidence, use the HTTP-based Internet access check method
LabVIEW block diagram elements
Locate these elements with "Quick Drop" (press Ctrl+Space and start typing the name); click on an icon to see more sample code that uses that element:
Example code
Connect your Academic RIO Device to your PC using USBLAN, Ethernet, or Wi-Fi. NOTE: Not all Academic RIO Devices have Ethernet and Wi-Fi connectivity options.
If using the NI myRIO 1950 or NI RIO Control Module start with the NI myRIO 1900 Archive.
Different IP address: Right-click on the "NI myRIO 1900" Device, choose "Properties", and then enter the new IP address
Different device:
Right-click on the top of the project hierarchy, select "New Targets and Devices", keep the "Existing target or device" option, and then find and select your particular device
Select all of the components under the "NI myRIO 1900" device: click the first one and then shift+click the last one
Drag the selected components to the new device
Right-click the "NI myRIO 1900" device and select "Remove from project"
Run “RT Main” and “PC Main” and observe the following:
Each VI executes the same subVI “check internet access (tcp).vi” once every five seconds and displays its result as the “Internet OK” Boolean indicator
Click the “dot-decimal notation?” control to switch between the machine name and the IP address
If you are using the USB cable to establish the network link between the Academic RIO Device and the PC, you should observe that the PC is host #1 (172.22.11.1) and the RT is host #2 (172.22.11.2) on the USBLAN network 172.22.11.0
“PC Main” will likely show other networks such as your wireless connection
“RT Main” will also show address 127.0.0.1 (“localhost”) – this address is for loopback testing and is internal to the RT target (in fact, every network host has its own loopback address)
If your wireless connection provides Internet service (e.g., with your consumer-grade wireless router) you can expect to see the “Internet OK” indicator activated
Try disabling your PC network connection to see the “Internet OK” indicator go out
“TCP Open Connection” function attempts to open a TCP/IP connection to the Microsoft “Network Connectivity Status Indicator” web service on port 80
“TCP Close Connection” function closes the connection, if established
Conclude Internet access is OK when error status is “False”
Error number 54 (ill-formed network address) generated by “TCP Open Connection” function – a symptom of unavailable Internet connection – is always cleared
Case structure implements standard error behavior
Same VI runs without modification on RT or PC
RT Main
Process Loop #1: run “show available IP addresses” VI every half second
Process Loop #2: run “check Internet access (tcp)” VI every five seconds
Use local variable technique to stop both process loops from one button
PC Main – same code as “RT Main”
Stop parallel process loops
Use local variable
Set mechanical action of “stop” button to “Switch When Pressed”