Reconnection
Hi!
My friend @Th4n05 and I have worked with Muse2016 and your packet for a few month. Sometimes Muse disconnect during the acquisition. We know that Muse is a strange stuff but when it disconnect we want that it reconnect automatically. You could say 'you can do it, create a new MuseClient or something else'. We don't know why but after reconnection the EEG stream don't work.
@Th4n05 understands that if we remove takeUntil() in muse-utils.js the problem is resolved but we don't understand why this happens also when we create a new MuseClient instance.
Do you have any ideas?
This sounds strange indeed. The takeUntil() basically removes the event listeners when the device disconnects, but they are recreated when you connect(), so it shouldn't be an issue.
Do you create the new instance as soon as the disconnect happens? Or do you wait some time before reconnect?
We tried both but after reconnection stream don't work :confused:
let urishMuse = require('muse-js')
let device
let gatt
async function reconnection() {
let muse = await new urishMuse.MuseClient()
//choose device and connection
if (!device) {
device = await navigator.bluetooth.requestDevice({
filters: [{ services: [urishMuse.MUSE_SERVICE] }]
});
}
gatt = await device.gatt.connect()
await muse.connect(gatt)
//set automatic reconnection
gatt.device.addEventListener('gattserverdisconnected', async () => {
await setTimeout( async () => {
await reconnection()
}, 2000);
})
//open stream
muse.eegReadings.subscribe((eeg) => {
console.log('EEG')
})
muse.telemetryData.subscribe((telemetry) => {
console.log('BATTERY' + telemetry)
})
await muse.start()
} ```
Hello, I also face this problem. Is there any solution?
Hello again,
It is strange but in my angular app the disconnection occurs very frequently. I am using the latest version of muse-js (3.2.0). But, when using EEGEdu ( https://eegedu.com/ ) the disconnections seem to be rare..
@sdg97 Can you please check if this is also the case with your Muse ? I also see that EEGEdu uses muse-js version 3.0.1. Could that be the case?
Also, this is of interest for automatic bluetooth reconnection in chrome (this is an official demo).
https://googlechrome.github.io/samples/web-bluetooth/automatic-reconnect.html