<button id="pair" onclick="onPairButton()">Connect with BLE device</button> <script> function onPairButton() { bleDevice=navigator.bluetooth.requestDevice({ filters: [{ name: [deviceName] }], optionalServices: [ bleService ] }); pairedDevice=bleDevice.then(device => { console.log(device.name); return device.gatt.connect(); }) psData=pairedDevice.then(server => server.getPrimaryService(bleService)) .then(service => service.getCharacteristic(psCT)) .then(characteristic => { return characteristic.readValue();}) .then(value => { var buf = new Uint8Array(value); var value1 = buf[0]; var value2 = buf[1]; console.log(`Values:`); console.log(buf); console.log(`${value1}`); console.log(`${value2}`); }) .catch(error => { console.error(error); }); } </script>
.then(value => { var buf = new Uint8Array(value); var value1 = buf[0]; var value2 = buf[1]; console.log(`Values:`); console.log(buf); console.log(`${value1}`); console.log(`${value2}`); }) .catch(error => { console.error(error); }); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)