You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
First Issue that I found is in the await BleManager.requestMTU(item, 517) function, first parameter is peripheral's ID and second is the MTU size, where we can set the maximum value of 512, but you have set it to 517 which exceeds the limit. Try to set the value to 512.
Second is the method that you are using BleManager.getConnectedPeripherals([]), I think you have to pass serviceUUIDs to this Array, can take a look into this.
Here is the solution you can try (as I was also facing the same Issue, and I resolved it by doing this):
Whenever you initialize the BleManager.start() method, add restoreIdentifierKey: "test" and forceLegacy: true, This is the example for that :-
BleManager.start({
showAlert: false,
restoreIdentifierKey: "test",
forceLegacy: true,
})
By doing this what will happen is
restoreIdentifierKey(ios) : Enables background restoration of BLE state after app termination/restart.
forceLegacy : This option forces the library to use legacy scanning APIs on Android.
Let me know the further Updates regarding this, Thank You and Happy Hacking !
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:
Current Behavior:
The text was updated successfully, but these errors were encountered: