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

Auto-Connect/Re-connect Issue with Ble Manager in React Native #1290

Open
prabu-nesh opened this issue Nov 26, 2024 · 0 comments
Open

Auto-Connect/Re-connect Issue with Ble Manager in React Native #1290

prabu-nesh opened this issue Nov 26, 2024 · 0 comments

Comments

@prabu-nesh
Copy link

I'm facing an issue with auto-connecting and re-connecting devices using BleManager in React Native. The connection process is working for the initial connection, but the subsequent reconnect attempts are failing. The goal is to connect to a peripheral, set the MTU size, retrieve services, and handle the connected device's characteristics. However, the reconnect logic does not seem to be functioning as expected.

Here is the code that I am currently using:

const onConnect = async (item) => {
try {
await new Promise(async () => {
await BleManager.connect(item);
// Await the MTU request
await BleManager.requestMTU(item, 517);
BleManager.retrieveServices(item).then((res) => {
// handle characteristics response
});
});
} catch (error) {
console.error("Connection error:", error);
}
};

const onConnectedDevices = async () => {
await BleManager.getConnectedPeripherals([]).then(async (peripherals) => {
if (peripherals.length > 0) {
onConnect(peripherals[0]?.id);
}
});
};

Expected Behavior:

  • The first connection attempt should succeed, and the MTU request and service retrieval should work fine.
  • On subsequent calls to onConnectedDevices, the device should reconnect successfully and handle the same operations (MTU request, retrieve services).

Current Behavior:

  • The initial connection works as expected, but the reconnection does not establish a stable connection.
  • The device may appear as connected, but operations like MTU size adjustment and service retrieval fail.
  • No error message is thrown, making it difficult to debug.
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

1 participant