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

Unable to Connect to Paired Device #17

Closed
timscott opened this issue Dec 7, 2016 · 5 comments
Closed

Unable to Connect to Paired Device #17

timscott opened this issue Dec 7, 2016 · 5 comments

Comments

@timscott
Copy link

timscott commented Dec 7, 2016

Not sure if this is a bug or I am doing something wrong. Basically I am unable to connect with an already paired device.

I have code like this:

return BluetoothSerial.isConnected().then(isConnected => {
  if (isConnected) {
    return true;
  }
  return BluetoothSerial.connect(lmu.address).then(response => {
    return response;
  });
});

The first time this code runs connect is called, and the (Android) phone prompts me to accept the pairing. I accept. Connect succeeds. I am able to write and read. All is well.

Upon subsequent passed through this code, isConnected is true. I can still write and read. Again, all is well.

Then I close and restart the app. After that when this code runs, I get an error on connect: "Error: Unable to connect to device"

Then I on the phone go to Settings > Bluetooth and Unpair from the device. Now when this code runs connect succeeds again.

I tried skipping connect if the device is already paired and just proceed to write. I did not expect that to work, and it does not.

@rusel1989
Copy link
Owner

rusel1989 commented Dec 9, 2016

@timscott Hey, that is very weird, I didn't have this issue before, but maybe the connection isn't terminated properly, can you try calling disconnect in componentWillUnmount or somewhere similar ? ... Also do you just reload the app or you shut it down completely and then run again ?

@timscott
Copy link
Author

timscott commented Dec 28, 2016

@rusel1989 I have narrowed this down a little. It only happens upon pressing Reload on the dev menu. It does not happen when stopping or killing the app on the device. Unfortunately, reloading apparently does not trigger componentWillUnmount or any other event handler I can find. I've posed this question on StackOverflow.

I wonder if there is any way to handle it in this module? Perhaps the fact that is does not happen when the app closes, but does happen when JS is reloaded offers some clue?

I suppose it's development-only problem, however, it's a quite painful one.

@rusel1989
Copy link
Owner

rusel1989 commented Jan 12, 2017

Hey this seems to me same as @waltermacambira describes in #15 so i will close this, the fix is almost ready :-)

@ramacha7
Copy link

@rusel1989 I am facing similar problems. I discover the paired devices in the useEffect() and store the paired devices. Then I have a button that when I press should connect to the device that I want to connect to. Sometimes when I re-run the app, it is suddenly not able to connect to the device. It happens at random times. I was wondering if you could help with this.

@zainulabideen-dev
Copy link

Hello guys,
I don't come up with a solution but I want to share one thing here. So when I try to connect my mobile device with my LapTop Bluetooth It connected successfully with the same function. But I'm not able to connect to another mobile device.

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

4 participants