USB Connect
to Salesforce

Modern browsers started providing support for direct communication between browser technologies and external hardware devices via USB ports. Beyond the commonly known PC accessories, there is a range of USB-enabled devices that can benefit from WebUSB. These enable Web applications to dynamically interact with such devices to extend their functionality locally on the user’s machine.

This project from Arlanis Reply aims at demonstrating the potential of this bridge when combined with the powerful cloud technology of Salesforce. Let us explore the path of uploading data from such a device to the browser, transmitting it all the way to the cloud, and then downloading the processed information back onto the device.


USB – a success story

The Universal Serial Bus (USB) was invented in 1996 by a consortium of several companies. USB serves to enable connections of electronic devices to a computer via cables, connectors and protocol for bi-directional data transfer. It quickly replaced many other interfaces in the computer world. The USB standard has since then evolved over the years, as speed and features increased with every revision. Today, USB is the industry standard for all kinds of devices and applications.

There are however challenges that arise as the USB becomes a ubiquitous solution in technological environments. Compatibility, for example, when using USB can be an issue. USB drivers are in most cases available only for Windows or MacOS but not for Linux. Moreover, USB drivers must be downloaded from the Internet and can pose a security risk: If the code is of low quality it can crash your whole system since the driver runs on the system level. Drivers for older devices are sometimes not compatible with newer versions of the operating systems and never updated by the vendor.

Web USB – put the driver in Javascript

How can we avoid the downsides of USB drivers? The solution is to place the driver in Javascript and embed it into the website. This results in the driver always having the latest updates without the constant need to refresh it manually. In addition, no older driver code will be left in the system that could expose it to security risks. There is also no need to install a system driver, meaning no additional administrator permissions are required from the receiving computer (Beaufort).

WebUSB is a draft from Google that has been submitted to standardization to W3C (Github). While the current implementation runs only in Chromium-based browsers (i.e. Chrome, Chromium, Microsoft Edge(Beta)), other browser vendors are also expected to adopt WebUSB as it becomes released as an industry standard in the near future.

Use Case: Connect devices to the cloud – on demand

Not all devices need to constantly be connected to the Internet due to varying reasons. For example, WiFi hardware is too expensive for small and cheap consumer devices, while not all industrial devices are allowed to be connected for security reasons.

On the other hand, all devices need maintenance from time to time, such as enabling maintenance-mode from web-application, uploading diagnostic data to the manufacturer or downloading new firmware with bug fixes and enhancements.

With WebUSB, there is no need to develop special apps limited to certain operating systems. Apps can run on any laptop (in Chrome browser) or mobile phone (Android) (Google Developers).


Prototype

Selection of a suitable device

USB accessories

Our first attempt at Arlanis Reply was to read data from standard PC accessories - a PC keyboard and a PC webcam. However, standard USB devices are apparently locked by the operating system’s driver when plugged in, and hence, prevents access to the device when the standard driver has already acquired it.

A device with programmable USB vendor ID and device ID that appears as “unknown” to the system was required.


Raspberry

We first considered the widely popular Raspberry mini computer, which runs with a Linux operating system. However, the Linux USB driver needed to be converted to a WebUSB standard, which was ultimately considered too complex for the task (BeyondLogic).

Arduino Leonardo

A breakthrough came with the discovery of the WebUSB project for Arduino on GitHub. Arduino, a programmable microcontroller without an operating system, is a much simpler mini computer than Raspberry that did not require a driver conversion.

Arduino is a platform with many different hardware boards. The Arduino Leonardo was chosen because of its onboard Micro USB Controller and serial port feature.

Set up

Arduino Leonardo

The idea was to create a user-friendly device that simulates logging entries of the two simple log levels, “error” and “info”. The log entries can then be uploaded by the customer via the device to inform the manufacturer on the Cloud. An automatically created support case would allow the manufacturer to respond to the customer’s needs. Based on these requirements, we built a device with:

  • two buttons, to simulate error and info log entries;
  • two LEDs for status signalling;
  • an LCD display to show a ticket number.


Salesforce Org

A Salesforce developer org was created for software development in order to transmit data onto the Cloud. The goal was to seamlessly update Salesforce records with the user’s credentials directly through the Arduino device through WebUSB.

Implementation

Lightning Web Component

Lightning Web Components (LWC) are the latest technology from Salesforce to create reusable frontend components. LWC are custom HTML elements built using HTML and modern JavaScript (Salesforce Developer).

We implemented a Lightning Web Component that connects to the Arduino device with JavaScript. Access to browser APIs on the Salesforce platform is controlled through a service called Lightning Locker (Salesforce Developer). This security feature, however, does not yet support WebUSB and blocked access to the USB device.

Heroku App

Since the implementation of Lightning Web Component did not lead to success, we tried a different approach. A custom application with the Java framework Spring Boot was created and hosted on Heroku, another Salesforce cloud platform that enables applications to run. We successfully created a support form that connects to the USB device. The user can now press buttons on the device to create log entries on the cloud. In order to test its functionality, Salesforce web-to-case feature was used to transmit data into the Salesforce org without further authentication. Lightning Design System was used to style the custom app with Salesforce’s design.


Aura Component

The Heroku application was a successful proof of concept, but it was missing seamless integration into the Salesforce platform. Research continued to find a better solution.

The Aura Component Framework is an older, but widely-used framework for frontend components in Salesforce (Salesforce Developer). Aura Components are subject to the same restrictions of Lightning Locker as LWC but in addition, there is an officially supported possibility to disable Lightning Locker for a single component (Salesforce Developer). With this solution, the USB feature could be accessed in the browser with JavaScript.

An Aura component with a single “Connect” button was implemented. The component can be combined with other components in a Salesforce application. It encapsulates all the Javascript in a user-friendly way. When the user presses “Connect”, a USB connection to the device is established.

The main benefit of the Aura Component compared to the Heroku solution is the possibility for records to be created with the logged-in user’s credentials. Users do not have to leave the familiar Salesforce user interface while working with an external tool.

Arduino Firmware

The firmware on the Arduino is the counterpiece to the JavaScript driver. It reads and transmits data according to the commands from the driver. Arduino IDE was used to develop the firmware (Arduino).

Two-way communication is demonstrated with the following features:
When the user pushes a button on the device, the event is handled in real-time in the browser. A popup notification on the Salesforce interface is displayed for immediate feedback. After a record is created in Salesforce, the record’s ID is transmitted to the device and shown on the LCD display.


Arduino Firmware

The custom-build device from the outside showing a USB cable, two buttons, LCD display and two LEDs (LEDs not visible).


Conclusion

In this article, Arlanis Reply demonstrated the benefits of WebUSB for customers and hardware manufacturers. Through trial and error, a solution compatible in the browser was found, without the need for an operating system specific app or driver. An Aura Component was built as a proof-of-concept that communication with a custom USB device is possible. Through this one use case of logging web-to-case entries, other possibilities are further enabled.


  • strip-0

    Arlanis Reply specializes in consulting, planning, developing and integrating Salesforce solutions and services. Arlanis Reply provides market leaders with seamlessly integrated solutions for all customer related processes for sales, marketing and services – from the initial contact to the long-term service business. Arlanis Reply configures all common Salesforce components such as Sales Cloud, Service Cloud, Community Cloud, Marketing Cloud or App Cloud, or adds individual programming with Heroku if required. With Mulesoft, Arlanis Reply provides an integration technology which allows you to develop, build, analyze, manage and monitor APIs and custom point-to-point integrations. In doing so, Arlanis Reply relies on agile project management methods and a project approach optimized for Salesforce introductions, which ensures maximum flexibility.
    www.arlanis-reply.com