Profile
|_ Service
| |_ Characteristic
| |_ Characteristic
| |_ Characteristic
|_ Service
|_ Characteristic
|_ Characteristic
...
02 02 01 06 02 0a 00 11 07 9e ca dc 24 0e e5 a9
0xff === 255
(1 byte)parseInt('ff', 16) === 255
// Length of 12 bytes
var buffer = new ArrayBuffer(12);
// ...Read data into the buffer, then...
var array = new Uint8Array(buffer);
// Gives e.g. 255 / 0xff:
var my8BitInt = array[0];
var buffer = new ArrayBuffer(12);
var dataView = new DataView(buffer);
// Gives e.g. 255 / 0xff:
var my8BitInt = dataView.getUint8(0);
let options = {filters: [{
services: ['battery_service'] }] };
navigator.bluetooth.requestDevice(options)
...
.then(device => device.connectGATT())
.then(server =>
server.getPrimaryService('battery_service'))
.then(service =>
service.getCharacteristic('battery_level'))
.then(characteristic => {
// Read battery level
return characteristic.readValue();
})
.then(value => {
let bytes = new Uint8Array(value.buffer);
console.log(`Battery level: ${bytes[0]}`);
});
βThis is a short list of issues you will encounter if you try to use native Android BLE...β
$yourFavouriteBLEDevice