I'm trying to connect the Muse headband in chrome so i can stream live brainwave data.
I can connect and stream data fine in python using ports, but am having trouble streaming the data via web BLE.
With the code bellow, I can connect to the device and startNotifications(), but the event listener for "characteristicvaluechanged" is not being triggered. I've also tried connecting with other bluetooth devices, and no values are read so I don't think this is a Muse problem.
<h1>Test HTML</h1>
<button id="read" onclick="onButtonClick(event)">Connect with the BLE device</button>
<script>
function onButtonClick(event){
connectBLE()
}
async function connectBLE() {
let serviceUuid = '5052494d-2dab-0341-6972-6f6861424c45'
let characteristicUuid = '43484152-2dab-3141-6972-6f6861424c45'
try {
console.log('Requesting Bluetooth Device...');
const device = await navigator.bluetooth.requestDevice({
filters: [{services: [serviceUuid]}]});
console.log('Connecting to GATT Server...');
const server = await device.gatt.connect();
console.log('Getting Service...');
const service = await server.getPrimaryService(serviceUuid);
console.log('Getting Characteristic...');
myCharacteristic = await service.getCharacteristic(characteristicUuid);
await myCharacteristic.startNotifications();
console.log(myCharacteristic)
console.log('> Notifications started');
myCharacteristic.addEventListener('characteristicvaluechanged',
handleNotifications);
} catch(error) {
console.log('Argh! ' + error);
}
}
function handleNotifications(event) {
console.log('YEAH!')
let value = event.target.value;
let a = [];
// Convert raw data bytes to hex values just for the sake of showing something.
// In the "real" world, you'd use data.getUint8, data.getUint16 or even
// TextDecoder to process raw data bytes.
for (let i = 0; i < value.byteLength; i++) {
a.push('0x' + ('00' + value.getUint8(i).toString(16)).slice(-2));
}
console.log('> ' + a.join(' '));
}
</script>
Anyone ever had a similar issue? I can't find any solutions online so this is kinda my last resort.
PS: I'm running Ubuntu 18.04 and Chromium 83.0.4103.61