Sunday, April 02, 2017

LabVIEW Web Services on BBB/RPi

It's been some time since it released to the public but I'd like to talk through some of the technical details that make LabVIEW Web Services (LVWS) work on the Raspberry Pi and BeagleBone Black.

Background
LabVIEW has had support for Web Services for many years, The basic idea is that a VI can be automatically turned into a REST interface and served up via an HTTP server built-into the LabVIEW run-time engine.  This allows an easy path to creating a web-enabled LabVIEW application.

Although we didn't have LabVIEW Web Services enabled in the intial release of the LabVIEW support for BBB and RPi, we knew how important it would be to have a way to create web interfaces for their embedded LabVIEW applications, which are generally headless (no local user interface).  So as soon as we released LINX 3.0, we immediately started work on getting LVWS working, and after a few months of work we released the support to the community as an update to LINX.  Along with that we even created a tutorial to introduce this new capability to the community.

Removing NIAuth
The NIAuth system is a PAM module that allows for creating users and setting permssions through the NI Measurement and Automation Explorer (MAX).  MAX isn't supported on BBB/RPi because we have a more focused Target Configuration tool which is more appropriate for these devices.  We also are less focused on users and permissions for these targets so it made sense to simply remove the NIAuth tie-ins in LVWS for these devices.  This proved to be more work than we thought because there were a number of assumptions in the code that depend on NIAuth being present.  In the end, this was the majority of the work required to get LVWS up and running.

HTTPS Support
One of the features of LVWS is the ability to enable HTTPS to allow for secure web service access.  Unfortunately, the HTTPS support didn't work "for free", and so we made the decision to release LVWS support without working HTTPS support.  Sorry, we tried.  We'll probably get back around to this at some point but no promised ETA.

In the meantime, one of my colleagues came up with a clever way to "wrap" HTTPS support on LVWS in order to get LabVIEW to work with the Amazon Alexa service.  The tutorial is a great one to read in general, but you can re-use the httpsHelper Node.js script to wrap your own custom LV web service.

A UI for your BBB/RPi
Usually the next thing users ask when learning about LabVIEW Web Services is how to create a UI that access the LVWS.  You can access the web service with a web browser (for HTTP GET methods) or the curl utility (for HTTP POST methods).  This is very useful for debugging, but is probably not sufficient for a real user interface.  One method is to create a static web page is using HTML and Javascript that calls your LVWS to read or write data, but many users aren't too interested in learning a text-based programming language and HTML when they're already using a graphical programming language in LabVIEW.  This tutorial uses HTML and Javascript to create a web-based UI.

Data Dashboard
Data Dashboard is a free mobile app available for iOS and Android (tablets, not phones) that gives you a pretty nice UI design tool.  Data Dashboard can interface directly with LVWS to allow creating a mobile-friendly a UI.  As a side benefit of the work we had already done to enable LVWS, the Data Dashboard app worked with Raspberry Pi and BeagleBone Black targets.  This is a really nice option for users that want to avoid doing any text-based HTML or Javascript coding.  We created a tutorial on how to use LVWS with Data Dashboard.

Calling REST interface with the LV HTTP VIs
Another way to create a web-based UI for a LabVIEW app came from the Makerhub Forums.  The basic idea is that you create an LVWS interface for your LabVIEW app running on a RPi or BBB, and then create a client LabVIEW app on a desktop machine that interfaces to the target's LVWS interface using the LabVIEW HTTP VIs.  The upside to this strategy is that you can once again avoid coding HTML or Javascript, but the downside is that you must have LabVIEW running on the client device, which precludes having this UI on devices like smartphones.

No comments: