react-native-ble-plx icon indicating copy to clipboard operation
react-native-ble-plx copied to clipboard

Device disconnected after write

Open kurogalaxy opened this issue 1 year ago • 12 comments

Prerequisites

  • [X] I checked the documentation and FAQ without finding a solution
  • [X] I checked to make sure that this issue has not already been filed
  • [X] I'm sure that question is related to the library itself and not Bluetooth Low Energy or Classic in general. If that so, please post your question on StackOverflow.
  • [X] I'm running the latest version

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.

kurogalaxy avatar Mar 13 '24 00:03 kurogalaxy

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

EmmaZachara avatar Mar 14 '24 16:03 EmmaZachara

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:

  • connection to the device
  • discovering characteristics you should not experience any problems sending data.

Could you show:

  • how do you declared plxBleManager
  • how you call the function to connect to the device (parameters)
  • the logs from Logcat?

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

nhaduongc avatar Mar 19 '24 07:03 nhaduongc

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 avatar Apr 01 '24 18:04 fustaro

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
});

fustaro avatar Apr 01 '24 18:04 fustaro

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

ex3ndr avatar Apr 29 '24 02:04 ex3ndr

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

EmmaZachara avatar Apr 29 '24 13:04 EmmaZachara

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

PierreHenri123 avatar May 27 '24 15:05 PierreHenri123

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.

jklimke avatar Jun 03 '24 14:06 jklimke

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.

gamilr avatar Jun 22 '24 16:06 gamilr

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

  • Android 12
  • React-Native 0.74.5

mikasius avatar Oct 22 '24 08:10 mikasius

same problem here on iOS. Disconnected after write.

niffler92 avatar Aug 09 '25 23:08 niffler92