Host a web service on the Academic RIO Device to serve the states of onboard sensors (pushbutton and accelerometer) and system information (date, time, host name, and IP address), and to control the onboard LEDs based on a user-selected LED hex code.
Use cases
Serve sensor measurements, peripheral device data, and other acquired information as JSON strings and as a web page for a remote client
Control onboard devices and attached peripheral devices based on information received from the remote client
Features
Serves system information: date, time, and IP address
Serves the state of onboard devices: push button and accelerometer
Illustrates how to retrieve information as JSON strings for machine-to-machine communication
Illustrates how to retrieve information as web page
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-host.zip (for use with NI myRIO 1900)
or the
NIELVISIII-rt_web-service-host.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"
Connect your Academic RIO device to the computer running the LabVIEW development system by the USB cable to establish the NI USBLAN network.
Locate the Web Service entitled “Onboard” under the “NI myRIO 1900” hierarchy.
Right-click on “Onboard” and then choose “Start.” You should see the service being built and deployed on the Device target, and eventually a message that says “The web service is now running on the debug server. You can connect to this web service on port 8001.” Click “OK” to continue.
Expand the “Web Resources” hierarchy under the “Onboard” web service, expand the “Public Content” folder, right-click on “index.html,” and then choose “Show Public URL.” Note how the URL is constructed: 172.22.11.2 is the IP address of your Device target on the USBLAN, the colon indicates the specific port number to use, “Onboard” is the base name of the web service, and “index.html” is the name of a web page.
Click “Copy URL” to copy this URL to the system clipboard.
Open a browser and paste this URL (Ctrl+V) into your browser. The web service now delivers the web page called “index.html” to your browser; this page shows a variety of ways to call the web services. Try the links and data entry boxes that send the desired LED hex code to the web service which responds with system information and also sets the state of the Academic RIO Device onboard LEDs.
Right-click on “Onboard” and then choose “Stop.”
Select “index.html” and find its URL as before, but now look at “Available Servers”. Note that one of the servers is called “Application” on port 8080 (distinct from the debug server on port 8001). Select this server, copy the URL, and try it in your browser. Expect to see this fail because you have not yet “published” the web service.
Right-click on “Onboard” choose “Application Web Server”, and then “Publish”. Expect to see the familiar deployment window as the project is built, but no summary comment.
Try the URL (now based on port 8080) again. You should find that the web service works properly. A published web service will start automatically each time you power-up the Device.
Open “Main - set LEDs, display sensors.vi” under the “My Computer” target (your development system).
Determine the URL of the “system_info_sensors_LEDs” method VI located in the “json” virtual folder of “Web Resources”; paste this into the “web service URL” front-panel control.
Run the VI. Expect to see the “parsed returned JSON string” cluster indicator display system information (date, time, name, and IP address) as well as the status of the onboard pushbutton and accelerometer. This illustrates how the VI running on the host computer calls the web service hosted on the Device.
Close the VIs and project when finished.
Troubleshooting tips
Failure to connect to target or deploy code – Try right-clicking on the “NI myRIO 1900” target and choosing “Disconnect” and then “Connect”. If this does not help, go ahead and power-cycle the Device.
“Conflict Message: The Web Services deployment failed. An active NI Application Web Server was not detected on the target”. – This error indicates that the Device is missing the required software set add-on called “NI Application Web Server.” See manage the Academic RIO Device software set add-ons to learn how to install this required software add-on.
Suggested modifications
Evaluate your ability to host a LabVIEW-based Web service by modifying one of the existing demo VIs to perform one or more of the following tasks:
1. Serve a sensor measurement from any of the sensors described in the NI myRIO Project Essentials Guide (temperature, ambient light intensity, proximity, acceleration, angular velocity, vibration, magnetic field, etc., see the table of contents for the complete list).
1. Control an indicator or actuator for any of those described in the NI myRIO Project Essentials Guide (seven-segment LED display, LCD display, LED matrix, motor, servomotor, etc.)