The Web Bluetooth
API lets websites discover and communicate with devices over the
Bluetooth 4 wireless standard using the Generic Attribute Profile (GATT). It is
currently partially implemented in Android M, Chrome OS, Mac, and Windows 10.
This sample illustrates the use of the Web Bluetooth API to get all
characteristic's descriptors of an advertised service from a nearby Bluetooth
Low Energy Device. You may want to try this demo with the BLE Peripheral
Simulator App from the Google
Play Store and check out the Get
Descriptors (Promises) sample.
Live Output
JavaScript Snippet
asyncfunctiononButtonClick(){letserviceUuid=document.querySelector('#service').value;if(serviceUuid.startsWith('0x')){serviceUuid=parseInt(serviceUuid);}letcharacteristicUuid=document.querySelector('#characteristic').value;if(characteristicUuid.startsWith('0x')){characteristicUuid=parseInt(characteristicUuid);}try{log('Requesting Bluetooth Device...');constdevice=awaitnavigator.bluetooth.requestDevice({filters:[{services:[serviceUuid]}]});log('Connecting to GATT Server...');constserver=awaitdevice.gatt.connect();log('Getting Service...');constservice=awaitserver.getPrimaryService(serviceUuid);log('Getting Characteristic...');constcharacteristic=awaitservice.getCharacteristic(characteristicUuid);log('Getting Descriptors...');constdescriptors=awaitcharacteristic.getDescriptors();log('> Descriptors: '+descriptors.map(c=>c.uuid).join('\n'+''.repeat(19)));}catch(error){log('Argh! '+error);}}