dotintent / react-native-ble-plx

React Native BLE library
Apache License 2.0
3.05k stars 513 forks source link

Device disconnected after write #1179

Open kurogalaxy opened 7 months ago

kurogalaxy commented 7 months ago

Prerequisites

Question

After scanning and connecting the device, I call the following

await plxBleManager .writeCharacteristicWithoutResponseForDevice( deviceId, serviceUUIDs.server, serviceUUIDs.write, data, ) .then(algo => { console.log('Write successful'); }) .catch(error => { console.log('Error', error); });

The first time I run the code I get the 'write successful' text but second time returns a [BleError: Device D8:3A:DD:83:AE:DC is not connected]

I also have the following method but it won't return anything at all

const onDisconnect = (device: Device) => { device.onDisconnected(error => { console.log('device was disconnected', error); }); };

Am I missing something? Do I need to call another method before doing every write? I'd really appreciate any help.

Testing on Android 13.

EmmaZachara commented 7 months ago

Hi @kurogalaxy, Thank you for raising this question. We will review it and get back to you soon.

dominik-czupryna-withintent commented 7 months ago

Yes, we currently have a problem with the onDisconnect listener, especially when the disconnection is initiated from the BLE device, we are working on it.

If you have called functions for:

Could you show:

nhaduongc commented 7 months ago

I got the current issue now. when I sync data from my BLE device, the BLE device send data to the app(Android) the progress take arround 10 - 30 second. But in the latest version 3.1.2 It's fire disconnection event in this case. I'm not sure it is the same case. look like when the BLE device do some busy task. that make the library fire disconnect event

fustaro commented 6 months ago

same happening to me after updating from 2.0.3 to 3.1.2 on Android, module fires disconnected event a few seconds after connecting.

fustaro commented 6 months ago

for me it basically disconnects after the timeout period, despite it actually connecting successfully and I can send and receive data fine before it happens. E.g. below will connect fine for 30 seconds then disconnect for no reason.

const connectedDevice = await this.manager.connectToDevice(device.id, {
      timeout: 30000
});
ex3ndr commented 5 months ago

I have the same problem, in my case iOS works fine, but Android disconnects.

EmmaZachara commented 5 months ago

@fustaro, @ex3ndr, @nhaduongc Thanks for your patience; we'll need a bit more time to get back to you with a solution.

PierreHenri123 commented 4 months ago

Same problem here. When I try char.writeWithResponse, it fails randomly telling me that device has been disconnected. IOS and Android

jklimke commented 4 months ago

Is there any progress here ? I am also experiencing a disconnect after writing and leading several characteristics (so somehow a heavy read). Unfortunately i have to write a little piece of data after each connect.

gamilrr commented 4 months ago

Any update on this issue?. I could make it work putting a small delay (around 50ms) before sending every chunk of data, it happens to me with the writeWithResponse call.

mikasius commented 6 hours ago

Any update on this issue? The same issue, disconnects after 20-30 seconds on Android.