Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reconnection #19

Open
sdg97 opened this issue Nov 13, 2019 · 6 comments
Open

Reconnection #19

sdg97 opened this issue Nov 13, 2019 · 6 comments

Comments

@sdg97
Copy link

sdg97 commented Nov 13, 2019

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?

@urish
Copy link
Owner

urish commented Nov 15, 2019

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?

@sdg97
Copy link
Author

sdg97 commented Nov 15, 2019

We tried both but after reconnection stream don't work 😕

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

@CelticHarp
Copy link

Hello,
I also face this problem. Is there any solution?

@CelticHarp
Copy link

CelticHarp commented Oct 23, 2021

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?

@nuKs
Copy link

nuKs commented Jan 23, 2024

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

@laurikskl
Copy link

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

The reconnection does not work when I wait 3 minutes after a establishing an initial connection and then disconnect.

It seems that the permissions that are granted in the browser when you pair a device expire after about 3 minutes, making automatic reconnection impossible. I've been trying to find out why the muse device sends the "ongattdisconnected" event, but I have no clue so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants