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
Download and unpack the
rt_web-service-call.zip (for use with NI myRIO 1900)
or the
NIELVISIII-rt_web-service-call.zip (for use with NI ELVIS III)
archive, and then double-click the ".lvproj" file to open the project. NOTE: This project was written for a NI myRIO 1900 or NI ELVIS III connected by USBLAN at IP address 172.22.11.2.
If you are using a different IP address or another Academic RIO Device (Example: NI myRIO 1950 or NI RIO Control Module) do the following:
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 the “check internet access (http)” VI to confirm that the Device can reach the Internet. If the “Internet OK” indicator does not light, right-click on the error code number in the “error output” cluster indicator and select “Explain Error” for more details. See the “Troubleshooting” section below if you experience difficulty, especially if you see error code 7.
Open and run the “ipinfo.io IP Lookup API - learn my public IP address” VI located under the “NI myRIO 1900” target. Note the contents of each indicator:
“endpoint URL” is the web service endpoint; it is the URL to which the HTTP client VI opens a connection,
“returned headers” shows the webpage header information returned by the web server,
“returned body” is the webpage content itself, a JSON string containing name/value pairs, and
“IP address”, “geolocation”, and “hostname” show the extracted results from the JSON string.
Click the “look up a web server” button and re-run the VI. Note the change in the endpoint URL. Try other web servers, too, such as info.cern.ch, the very first website ever!
Next, open the “Google Maps API - geocoding.vi” VI. Run with the default address and confirm that the latitude is 30.408, longitude is -97.73, and the “address at this geolocation” indicator is the complete street address of the corporate headquarters of National Instruments in Austin, TX.
Try other street addresses, cities, countries, and place names such as businesses and national landmarks. “Royal Observatory, Greenwich” is of particular interest – does the resulting “longitude” indicator value make sense to you?
Spend a few moments scrolling through the “returned body” contents. The JSON string is much longer and more complex due to multiple nested levels and arrays, but is still much easier to parse than the HTML code of a conventional web page.
Try the other VIs that look interesting to you.
Close the VIs and project when finished.
Troubleshooting tips
“Error 7 occurred at Call Library Function Node in LabVIEWHTTPClient.lvlib:GET.vi” (File not found.) – This error indicates that the Academic RIO Device is missing the required software set add-on called “HTTP Client with SSL Support.” See manage the Academic RIO Device software set add-ons to learn how to install this required software add-on.
“Error 59 occurred at LabVIEWHTTPClient.lvlib:GET.vi” (The network is down, unreachable, or has been reset) – Check the Device Network Configuration page (browse to 172.22.11.2) to determine if one of the active network adapters has a “Gateway” IP addresses that is something other than 0.0.0.0. Also try running the “check internet access” VI located in under “My Computer” to learn whether or not your development system can reach the Internet.
“Error 363507 occurred at LabVIEWWeb serviceClient.lvlib:Send.vi” (LabVIEW could not verify the authenticity of the server) – verify that the Device system date and time are both correct so that the secured-HTTP connection (HTTPS) works properly. The Academic RIO Device does not have an onboard real-time clock (RTC), therefore each power cycle resets the date back to potentially many months into the past. Learn how to set the RT system time and date either with NI MAX or with your browser.
Suggested modifications
Evaluate your ability to call a Web service from a LabVIEW application by modifying one of the existing demo VIs to perform one or more of the following tasks:
Retrieve the current weather data from the “OpenWeatherMap” API http://openweathermap.org/api. Click the “API doc” link to learn the specifications of query strings and the returned JSON strings.
Find and use another JSON-based web service of interest to you.