sharpbrick / powered-up

.NET implementation of the LEGO PoweredUp Protocol
MIT License
94 stars 19 forks source link

WebAssembly Port #43

Open tthiery opened 4 years ago

tthiery commented 4 years ago

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 the SharpBrick.PoweredUp.Bluetooth interface is required.

tthiery commented 3 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).

tthiery commented 3 years ago

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();
}