-
-
Notifications
You must be signed in to change notification settings - Fork 763
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
Stuck on retrieveServices (not connected after connection?) #831
Comments
same issue |
@Silvesterrr any update on this? |
Nope, am focused on something different... |
@Silvesterrr I had the same hanging issue with Android only, iOS works perfectly fine to me. There is a workaround I did that solves the issue. Try to
Hope this helps. |
Is there any update on this issue? I'm currently struggling with the same issue. |
Same problem on xiaomi pad 5 😒 I tried so many things like clear bluetooth cache / binding etc.. I wasted few hours on this. As workaround im wating at least 1 sec and if there is no connection (not getting "retrieveServices") I trigger disconnect and then reconnect again every time.
Please let me know if you have better solutions, thanks 😀 |
Toady I played with "bluetooth MAP version & AVRCP version" inside developer options. |
yea, fun fact but I cannot force user to change that. Anyone tried using "react-native-ble-plx"? |
I already tried ble-plx, same issue 😟 |
Hi @Silvesterrr, I'm also facing similar kind of issue, Did you found a solution for this issue ? |
|
Mismo problema, alguna solución? |
Same issue |
The same issue |
Same here, any solutions for this? |
@maeda-kazuya , @KonstantinKostianytsia try to run the scan method first and then call the connect method. |
Thanks, I just came up with some workaround.
|
Also encountering this issue. It'll stall on |
I don't know if this could be an answer, but let me share my code. // react-native-ble-manager > src > types.ts
export interface PeripheralInfo extends Peripheral {
serviceUUIDs?: string[];
characteristics?: Characteristic[];
services?: Service[];
} // react-native-ble-manager > src > index.ts
retrieveServices(peripheralId: string, serviceUUIDs: string[] = []) {
return new Promise<PeripheralInfo>((fulfill, reject) => {
bleManager.retrieveServices(
peripheralId,
serviceUUIDs,
(error: string | null, peripheral: PeripheralInfo) => {
if (error) {
reject(error);
} else {
fulfill(peripheral);
}
}
);
});
} When you use retrieveServices, it will return the result 'peripheral', whose elements' types are defined by Interface 'PeripheralInfo'. As you can see, the original code makes PeripheralInfo extend Peripheral, and Interface 'Peripheral' is as below. export interface Peripheral {
id: string;
rssi: number;
name?: string;
advertising: AdvertisingData;
} These say, the result of retrieveServices must have attributes 'id', 'rssi', and 'advertising' while others are optional. So, here is the part of my code. export interface PeripheralInfo { // -> this is what I fixed
id: string; // -> this is what I added
serviceUUIDs?: string[];
characteristics?: Characteristic[];
services?: Service[];
} In my code, PeripheralInfo does not extend Peripheral anymore. Instead, the result still contains 'id', because you will offer it when you call retrieveServices function. rssi?: number;
name?: string;
advertising?: AdvertisingData;
|
sometimes connecting is fast, but retrieveServices takes over 30 seconds. |
This comment was marked as off-topic.
This comment was marked as off-topic.
My current workaround is something like this, where I basically race it against another promise. If the other promise resolves first I consider it a timeout and handle it accordingly. const tryGetServices = await Promise.race([
BleManager.retrieveServices(peripheral.id),
new Promise((resolve, reject) =>
setTimeout(() => {
resolve('timeout')
}, 10000)
),
])
const peripheralData = tryGetServices as PeripheralInfo | string
if (typeof peripheralData === 'string') {
// timeout
} else {
// got services, proceed...
} |
Any update? I have same problem after upgrade version 8.x.x to 11.x.x |
What I found out.
The function retrieveServices, reaches the code:
Nothing further service: 1818 react-native: 0.71.11 |
Version 11.0.8 fixed my problem |
I just ran across this issue with a peripheral that is already "connected" (i.e. It looks like that the command queue is the one that drops the ball. If the |
same problem, if the device is really connect retrieveService never return |
The Android stack (at least) requires that you call |
Running version |
It works on android! My solution is: myRetrieveServices = async () => {
return await Promise.race([
BleManager.retrieveServices(this.deviceConnected.id),
new Promise((resolve, reject) => setTimeout(reject, 3000)),
]);
}; |
Describtion
Hi, I've got this annoying bug it appears inconsistently every few times. It's really similar to this Issue [#402]
(#402)
It looks something like this:
I never found out this bug after first run of my app (first connect). Only at second, etc. connection.
I can't find any mistakes because one time it works like a charm and other time it has a problem.
I found out that disabling and enabling Bluetooth on the phone and retrying connecting works
(But I can't make my users to disable and enable Bluetooth. Or can I ;) ha-ha).
My code
I've tried writing my code in 2 ways both have this bug.
And this way:
In this way when the bug appears after running
isPeripheralConnected
I getPeripheral is NOT connected!
So I've tried to resolve this by running this function again, but it just loops in this place and doesn't work.How to Reproduce
Accually I don't know. It appears so random, I can't control it. I only know that it appears at second or next connections.
Smartphone:
Btw, I really like this library. It's really intuitive :)
The text was updated successfully, but these errors were encountered: