Bluetooth Websocket API
As the Bluetooth operations are dictated by the server, the front-end setup is straight forward. The Bluetooth search command, connect and communication are all initiated by the server side.
There are many different protocols on top of the WebSocket standard. The library has been designed while having this in mind, hence there is a separation between the library core and WebSocket adapter. Today Phoenix framework WebSocket channels are supported.
- Android6.0+, Chrome OS or OS X. The full list of supported hardware is all the time updated by the Web Bluetooth workgroup
- Chrome v50+
- HTTPS due to WebBluetooth security requirements
This library consists of three parts:
Handles the Web Bluetooth API and maps functions to the WebSocket adapter.
WebSocket specific implementation, formats and sends the messages back/forth between Core and the server.
An example app of usage is included in the repo, this can be used together with the Phoenix server reference app Bluetooth WebSocket Server.
Below is a simplified chart showing the different Bluetooth messages passed through the library.
For more detail of each socket event please see the Wiki page Wiki - Socket messages specification.
Installation of reference app
To start your app
Install node_module with
To use SSL on localhost with WebBluetoothAPI
- Generate key with
openssl genrsa -out localhost.key 2048
- Generate cert with
openssl req -new -x509 -key localhost.key -out localhost.cert -days 3650 -subj /CN=localhost
- Put them in a directory
- Start server with
Now you can visit
localhost:3000 with SSL from your browser.
To build js file when you update
- Update source file of
- Run build with
npm run build
- The file will be created to
To start your HTTPS server on local:
Now you can visit
localhost:3000/app from your browser.
Of course you can use your apache server.
- The value should be encoded with
base64when you read/write value.
Adapter#requestDevice()method should be fired by click event (due to WebBluetoothAPI specification).
characteristicvaluechangedevent is fired by after not only its value changes but also a value change notification/indication (due to WebBluetoothAPI specification).