The connection and characteristic discovery are working and I'm assigning the discovered characteristic to a variable to do the reading. The first read using the snippet below is returning the correct value but every subsequent read returns immediately with the same value as the first read. I've verified what the read should return with Bluetooth LE Explorer: https://github.com/Microsoft/BluetoothLEExplorer.
Thanks
export async function readCharacteristic(id) {
if (!botIsConnected() || gattIsBusy) {
return false;
}
let charac = bleCharacFromID(id);
if (!charac) {
console.log('Invalid BLE characteristic on write');
return false;
}
gattIsBusy = true;
let retVal = await readCharAsync(charac);
gattIsBusy = false;
console.log('retVal: ' + retVal);
return retVal.readUInt8(0);
}
async function readCharAsync(charac) {
return await new Promise(function(resolve,reject){
charac.read(function(err, data) {
if(err !== null) return reject(err);
resolve(data);
});
});
}
Update: I found the bluetooth characteristic read call that didn't have the uncached flag set. The pull request fixes the issue for me. I'm not sure if caching is the desired behaviour and maybe there is another way to force an update.
The connection and characteristic discovery are working and I'm assigning the discovered characteristic to a variable to do the reading. The first read using the snippet below is returning the correct value but every subsequent read returns immediately with the same value as the first read. I've verified what the read should return with Bluetooth LE Explorer: https://github.com/Microsoft/BluetoothLEExplorer.
Thanks
Update: I found the bluetooth characteristic read call that didn't have the uncached flag set. The pull request fixes the issue for me. I'm not sure if caching is the desired behaviour and maybe there is another way to force an update.