I'm new to javascript so i might have some unconventional way of programming. That said, I'm working on a project where I need to read and write data to a custom BLE device. I'm using the gatt server protocol for the connection. I'm able to make a connection with the device but now i'm trying to read data from the registers.
I looked trough the web samples from google as well as the web bluetooth github but I cant make any sense of it. The code below is my current attempt to break this. earlier tries had me get stuck on the fact that the value that I got was an object or a promise object.
function readFromPcb() {
let p2 = new Promise((resolve, reject) => {
if (device.connected === false) {
reject('network Error');
}
})
.then(characteristic => {
readValue = characteristic.readValue();
console.log('data is: ' + readValue);
})
.catch(error => {
console.log('error: ' + error + DOMException.name);
});
}