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.
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.
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.
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).
Our first attempt 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.
We 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).
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.
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.
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).
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:
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.
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.
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 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.
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.
The custom-build device from the outside showing a USB cable, two buttons, LCD display and two LEDs (LEDs not visible).
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.
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