Open tthiery opened 4 years ago
The WebBluetooth stack is not fast enough to setup a GATT characteristics handler. A member of the WebBluetooth WG was friendly enough and filed an issue as a request of my StackOverflow question.
Simultaneously reported to the LEGO Protocol repository in hope to get a command to explicit query the information which are send automatically in the beginning of the protocol setup (hub attached io).
Minimum reproducable issue in the browser
function writeToLog(x) {
console.log(x.target.value.buffer);
}
async function connectToLwpDevice() {
const serviceUuid = "00001623-1212-EFDE-1623-785FEABCD123".toLowerCase();
const characteristicUuid = "00001624-1212-EFDE-1623-785FEABCD123".toLowerCase();
const device = await navigator.bluetooth.requestDevice({ filters: [{ services: [serviceUuid] }] });
const connectedDevice = await device.gatt.connect();
const service = await connectedDevice.getPrimaryService(serviceUuid);
const characteristic = await service.getCharacteristic(characteristicUuid);
characteristic.addEventListener('characteristicvaluechanged', writeToLog);
await characteristic.startNotifications();
}
Enable the usage of the
SharpBrick.PoweredUp
library in Blazor on WebAssembly. For that a bridge between Blazor and WebBluetooth is required. After the bridge, an adapter to theSharpBrick.PoweredUp.Bluetooth
interface is required.