Home
Quickstart Guide
Introduction RIO Academic RIO Application examples Your first RT app Your first FPGA app
Real-Time
Basic procedures System admin File system I/O monitor System controller architecture Timed loops Inter-process communication RT/Host communication RT/FPGA communication FPGA personalities Interrupts Datalogger (file I/O)
FPGA
Design flow Simulation Inter-process communication RT/host communication Derived clock domain IP blocks FPGA personality
Networking
Get connected Email Web services UDP TCP IP addresses
Site Map
Guides Code examples Procedures Tags LabVIEW block diagram elements Targets Communications All pages
Glossary How to use About
RIO Developer Essentials Guide for Academia
RT guide

Web services: hosting a Web service technical principles

Learn the technical principles necessary to host a Web service on the Academic RIO Device. Remote clients such as another LabVIEW-based target, an IoT device, or a conventional browser can retrieve sensor measurements and control indicators and actuators using commands obtained from the remote client's request query string.

Globe and home icons

Note: You may wish to begin with this overview of Web services, and knowing how to call a Web service will be helpful before attempting this material.

Run this example Academic RIO Device Web service project to get an idea of what you can accomplish – this example serves the states of onboard sensors and system information to a remote client, and allows the remote client to control the onboard LEDs.

Technical principles

Fundamental concepts

LabVIEW implementation of a Web service client

The following step-by-step video tutorial shows you how to build from the ground up a Web service similar to the one demonstrated earlier. This example Web service includes endpoint URLs to report the system date and time as well as the values of onboard devices (accelerometer and pushbutton), to set the onboard LEDs to a desired pattern, and to retrieve a webcam image with the option of selecting its dimensions and automatically refreshing the image once every five seconds. The tutorial also illustrates how to use the basic terminal-based technique (use front-panel controls and indicators connected to the icon frame) to retrieve query values and to return text, HTML, and JSON strings, and the stream-based technique to take control of the exact appearance of returned text and to serve other types of content such as a JPEG image.

NOTE: A USB webcam is required for Steps 7 to 9.
NOTE: The embedded video previews all look the same, but the video will start at the correct place for each step.
  1. Create the LabVIEW project framework: create a new Academic RIO Device project, add a new “Web Service” called “API”, and create “Web Resources” folders for external devices (webcam), onboard devices (accelerometer, LEDs, and pushbutton), and system information (time and date):

    https://youtu.be/vFzborQdM7s?start=0&end=153 (2:33)

  2. Create the “system/date” method VI; use the “terminal” output type to serve the system date as simple text to the web service client:

    https://youtu.be/vFzborQdM7s?start=153&end=342 (3:08)

  3. Create the “system/time” method VI; use the “streaming” output type to control the exact format of the information returned to the client:

    https://youtu.be/vFzborQdM7s?start=342&end=579 (3:56)

  4. Create the “onboard/pushbutton” method VI. Use the “terminal” output type to return the pushbutton state as an HTML-formatted web page:

    https://youtu.be/vFzborQdM7s?start=579&end=754 (2:54)

  5. Create the “json/onboard/accelerometer” method VI. Use the “terminal” output method to return the three-axis accelerometer values as a JSON string in both cluster and array formats for the sake of comparison:

    https://youtu.be/vFzborQdM7s?start=754&end=1059 (2:33)

  6. Create the “onboard/LEDs” method VI. Learn how to retrieve the desired LED state from the endpoint URL query string using the “terminal” technique:

    https://youtu.be/vFzborQdM7s?start=1059&end=1368 (5:05)

  7. Create the basic “external/webcam” method VI. Learn how to using the “streaming” output type to return a JPEG image to the client:

    https://youtu.be/vFzborQdM7s?start=1368&end=1697 (5:08)

  8. Refine the “external/webcam” method to accept image dimensions from the URL query string:

    https://youtu.be/vFzborQdM7s?start=1697&end=2072 (5:29)

  9. Refine the “external/webcam” method to cause the browser to automatically refresh the page (which requests a new image) every few seconds by setting the “Refresh” field to the HTTP header:

    https://youtu.be/vFzborQdM7s?start=2072&end=2208 (2:16)

  10. Publish the web service to make it always available, even after a power cycle. Also view the site map for the URLs of all available method VIs:

    https://youtu.be/vFzborQdM7s?start=2208&end=2319 (1:53)

For more information

  1. LabVIEW Web Services FAQ (http://www.ni.com/white-paper/7747)
    Frequently asked questions and answers about LabVIEW Web Services implementation.
  2. JSON Basics: What You Need to Know (http://www.elated.com/articles/json-basics)
    Describes JSON syntax and how to form and parse JSON strings.
  3. The JavaScript Object Notation (JSON) Data Interchange Format (https://tools.ietf.org/html/rfc7159)
    Produced by the Internet Engineering Task Force (IETF), this document summarizes JSON syntax specifications and provides some examples.