Is Now a Good Time to Start using Web Bluetooth? (Hint: Yes, yes it is.)

If you’re into IoT and the Web, or like playing with cutting edge, user-facing tech, you should check out Web Bluetooth

It is prime time for Web Bluetooth. The standard is maturing, toolsets and APIs are popping up, and most exciting of all: Chrome 53 was released this week!

Chrome 53 has an Origin Trial for Bluetooth, which means that websites can opt-in to use this feature and automatically enable Web Bluetooth for all their visitors. It is the first time such technology enabling IoT directly from the web is deployed in the wild.

If you want to join the Origin Trial, all you have to do is register your site here and then add some code in order to join the trial. The Chrome team will end the trial in next January (2017), and after that, they expect to be able to stabilize the feature and move it closer to a general release.

Update: Chrome 56, released January 31, 2017, now includes Web Bluetooth enabled by default for Mac, Android 6 and Chrome OS users. Hooray!

So if you and your developers are already up to date with Web Bluetooth, you’ll be ready to go the minute your Business Analyst comes running down the hall, hair and pinstripe suit askew, worrying about some new “Web Bluetooth thingy” and demanding that it be added to the site next week.

Perhaps more realistically, the Origin Trial for Chrome means that you can experiment with Web Bluetooth and test your ideas with real users while the standard gains traction. And it’s popping up in more and more places and tech stacks.

For example, at the end of this month, my friends François Beaufort from the Chrome DevRel team, Gil Fink from sparXys, and I will do a workshop about Web Bluetooth at AngularConnect in London. We will introduce the technology to Angular developers, and show how you can connect to a Smart Light bulb (I won’t assume everyone has read my post about it ;-), some MiP robots, and who knows what devices might turn up at the workshop to play with…

In response to my previous posts, as well as during talks I give about Web Bluetooth, I’ve received a bunch of good questions about Web Bluetooth, and I will try to answer many of the big ones below.

Bluetooth Heart Rate Monitor: Now Coming to the Web!

What OSs Support Web Bluetooth?

At the time of this post, Web Bluetooth is natively supported by Android 6+ (Marshmallow), Chrome OS, and Mac OS X. Linux is supported, too, but it requires tinkering with settings, so most users won’t do it (though if you’re interested, check out this tutorial).

According to the official statistics — 40% of Android Users use Marshmallow or newer. It’s rising fast though — 16 months ago, it was only 2% (source), and Mac OS X has about a 10% market share worldwide (around 17.5% in the US), according to Wikipedia. It’s not a bad slice of the market, but…

Windows is still missing!

I began working on adding Web Bluetooth support to Chrome for Windows a few weeks ago, and already made some progress — you can already scan for nearby Bluetooth devices.

Web Bluetooth on Windows 10 (work in progress)

If anybody is interested in helping out and has either good knowledge in C++/Windows programming or Chromium Internals — let me know! That knowledge could definitely be helpful in pushing this project forward. You can check out a small Proof of Concept (PoC) that I created here.

Update: Seems like the Chrome team will be shipping Web Bluetooth on Windows 10 soon. Meanwhile, I created a Web Bluetooth Polyfill for Windows 10.

And to Address the Elephant in the Room…

Still no official* support for iOS. Yes, unfortunately, Web Bluetooth is not supported in iOS at the moment. We’re waiting for Apple to pick it up and implement it in their web browser engine, WebKit. Chrome for iOS uses WebKit, so once Apple implements it in WebKit, Chrome will also pick it up. Until then, I’m sure we can make do.

*I say “no official” support because it looks like somebody has created a special Web Bluetooth-enabled browser for iOS even without official blessing from Apple, and it is even open-sourced. All of which is to say — it is possible, but not easy just yet.


Does Web Bluetooth Currently Have Any Limitations?

Like all of us, Web Bluetooth is only mortal (or…?).

Right now, Web Bluetooth can only speak with Bluetooth Low Energy (BLE) devices. Many devices, such as entertainment systems in most cars, speak classic Bluetooth. If a device says Bluetooth Low Energy or Bluetooth Smart, it can work with Web Bluetooth. If it says Bluetooth 2 or 3 or Bluetooth Classic — unfortunately, it won’ be supported. Confusingly, Bluetooth 4 usually means a device supports BLE, but not always. That said, adoption and use of BLE is increasing all the time, and I expect this trend will continue and we’ll see almost everything supporting it in the future.

As discussed briefly in a previous post, BLE has two roles: Central and Peripheral. The Central scans for Peripherals and can be connected to several Peripherals at once, depending on the hardware. Peripherals are passive — which means they can’t initiate the connection, and they can usually only be connected with one peer (i.e., one Central). Most hardware supports both roles — that is, both Central and Peripheral — but not always. For example, my Nexus 5 phone can only be a Central, but not a peripheral. With the newer Nexus 5X, both modes are supported. But it’s important to note that there are no Central-to-Central or Peripheral-to-Peripheral connections; it is always Central-to-Peripheral.

Web Bluetooth only supports the Central role, which means you can only connect with Peripherals. This means you can’t establish a direct BLE connection between two web pages on different devices using Web Bluetooth. You could, however, make a connection between Web Bluetooth (as a Central) and a native app implementing a Peripheral service.

Finally, in Web Bluetooth’s current state, you can’t scan for all devices around you — for good privacy reasons — and you can’t just connect to any device any time. So certain use cases, such polling a device periodically in the background, controlling a device through push notification received via Web Push API, or putting on a show for your website visitors by making their smart lights at home go all crazy, aren’t really possible just yet.

That said, it it seems like a spec is being drafted to add scanning capabilities to Web Bluetooth, so we’ll just have to wait and see what the future holds!

To put it all briefly (for those of you who are more “TL;DR”):

  • Only BLE, no classic Bluetooth
  • Only Central, no Peripheral
  • One device at a time, no scanning (yet)

(p.s. — If you’re curious about the reasoning behind some of these limitations, check out the official FAQ.)

BLE and Security

Web Bluetooth specific security concern are already addressed in this great article, which also compares Web Bluetooth with BLE on Native apps.

BLE itself does provides some encryption, but it is only available when you pair the devices prior to connecting them. Many consumer BLE devices work out-of-the-box without pairing in order to make the user experience simpler/better, and apparently, even when pairing with a PIN, it seems like a modern computer can easily brute-force all the possible combinations in a matter of seconds.

It does, however, seem like the most recent BLE 4.2 spec, released more than 18 months ago, supports a strong Elliptic curve Diffie–Hellman (ECDH) key agreement algorithm, but the majority of BLE devices still don’t implement a whole lot of security.

Are there exciting IoT-related Web APIs on the Horizon?

You bet! Here’s a few:

  • WebNFC: this API will enable Near Field Communication (NFC) capabilities (okay, right now just “selected use-cases”) for Web Bluetooth. Pretty neat, especially for Android and someday iOS users (hopefully soon!)
  • WebUSB: have you ever wanted to connect your hardware directly and safely to the Web? WebUSB lets you do just that; I’m already dreaming of the cool new Web Game controllers people will come up with…
  • Web Midi: Music lovers of the world, get ready: the Web Midi API, already present in Chrome, is pretty stinkin’ cool. The API lets you both control external MIDI devices using JavaScript and use MIDI devices to control things on the Web. Web-based synth orchestras, anyone?

How Can I Join the Party?

Minimally, you need two things:

  1. A device that supports Web Bluetooth (see above, but tl;dr: Android 6, Mac OSX with Bluetooth 4 capable hardware, Linux, or Chrome OS)
  2. A device to connect to! Anything will work — a $10 smart bulb, a $50 MiP robot, or for no money, check out BLE Peripheral Simulator or nRF Connect for Android or LightBlue for iOS.

I walked through the basics in my last post on Web Bluetooth and PWA, and there are tons of other resources out there on the web to help you get started.

Easily simulate a variety Bluetooth devices on iOS with the LightBlue app

The cool thing about Web Bluetooth — in combination with things like the Physical Web and Progressive Web Apps — is that the sky really is the limit for what you can build with it (well, that and Windows and official iOS support…).

In an upcoming post, we will show how to build a simulator for the smart bulb using JavaScript. As ever, feel free to reach out to me in the comments if you have any further questions (I can always add to/expand this post), awesome ideas, cool code snippets, good stories about spooking your neighbors… well, you know.