Skip to content

Javascript__Web Bluetooth & WebUSB

Elias Issa edited this page Jun 8, 2018 · 6 revisions

Brief Background

Compared to a system app, a web app is limited in interfacing with external hardware. However, new APIs are emerging that allow the browser to communicate with external devices. Web Bluetooth is one example, and WebUSB is another example. For more sophisticated applications such as interfacing with a mouse or transmitting large amounts of data, the faster, higher bandwidth USB connection is warranted. However, for infrequent reading of simple sensors (e.g. RFID tags), both BLE and USB are adequate. Mkturk has implementations of both for basic operations such as sending a signal to trigger an external device and receiving messages back from that device (two-way communication).

Resources

Overview

API Spec

GitHub

Developer Tools

Web Bluetooth versus WebUSB

Both BLE (bluetooth low energy) and USB are proven connection technologies that are universally available on almost all devices. Either can be used if all you need is to send small amounts of information (bytes), infrequently (100 ms). For high bandwidth applications (data size or speed), WebUSB is recommended. Here are the pros & cons of both platforms:

  • Supported Devices (BLE): Web Bluetooth only works with bluetooth smart (aka bluetooth low energy or ble). This is a slower but low energy implementation of bluetooth. Any device that implements GATT characteristics and attributes can be queried by the Web Bluetooth API. On the other hand, device firmware needs to be updated for webusb. There is already a WebUSB implementation for the Arduino, but if you want other devices, this may be a more involved process as WebUSB is very new. For now, the edge goes to Web Bluetooth in flexibility of supported devices.

  • Ease of Connecting (USB): With WebUSB, you are physically plugging the device in, so it is explicitly paired with the corresponding hardware. Furthermore, you can auto-connect to USB devices on page load if you've already granted permission previously. So most of the time, you don't need to do anything other than plug in the hardware. For Web Bluetooth, you have to manually select the device on every page load.

  • Robustness of Connection (Tie): Because of the physical USB connection, it unlikely to be easily disconnected. However, in our experience BLE is quite robust. Since it's wireless, this reduces the amount of wires (though we use a USB hub to combine arduino + battery power into a single connection into the tablet).

  • Multiple Simultaneous Devices (USB): Currently, web bluetooth is limited to a single device. You can connect multiple simultaneous devices with USB.

  • Transfer Speed (USB): We observe 90ms roundtrip times (45ms 1-way) in our mkturk Web Bluetooth implementation and 10ms roundtrip times in our mkturk WebUSB implementation. However, it is important to note that we haven't modified the ble connection settings from default or fully explored the potential of WebUSB (see Transfer Size & Types below).

  • Transfer Size (USB): The exact bandwidth of BLE depends on configuration and specific device limitations. You can read more about ble bandwdiths here and also see this plot. In practice, you can send on the order of a few kilobytes per second and there is an upper limit of ~100 bytes per packet or communication event. While we haven't tested the full potential of WebUSB yet, suffice it to say, we expect WebUSB (o(10^3 kb/sec)) to allow 2-3 orders of magnitude greater bandwidth than WebBluetooth (O(1kb/sec)). Here, the limiting factor may be the device you're talking to. For example, an arduino leonardo can only transmit 100-200 kilobytes/second given its clock speed even though it uses serial over USB.

  • Transfer Types (USB): You can set connection interval in some cases to change the speed of Web Bluetooth. In WebUSB, you have more options for connection type - bulk (data), isochronous (audio,video), and interrupt (blocking for temporal precision).

http://projectsfromtech.blogspot.com/2013/09/combine-2-bytes-into-int-on-arduino.html http://forum.arduino.cc/index.php?topic=396450.0