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.
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
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 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.
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.
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.)