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

100ms delay between packages

Open ApostolosMavroukakis opened this issue 2 years ago • 6 comments

Im communicating with a bluetooth device, and im having trouble optimizing performance. Even though the mtu is about 247 bytes the data is sent in 64bytes, more importantly tho its braking the data to multiple packages that have about 100ms delay between them. For a 300byte json it takes 500ms for the data to reach its destination.

0-02-05-9e970009dd722d74d11e381cbb628460d2084019a17f4e7bd9b5886682776ed2_28a07dc8f17b8453

ApostolosMavroukakis avatar Aug 04 '22 10:08 ApostolosMavroukakis

Hi, probably is a device problem that cap the MTU to 64. The BLE protocol is not designed to transfer data.

marcosinigaglia avatar Sep 14 '22 13:09 marcosinigaglia

yes and yes, it was indeed the device that capped at 64. I dont understand the delay though. Its been tested with native code with passable results as well.

ApostolosMavroukakis avatar Sep 14 '22 14:09 ApostolosMavroukakis

The react native bridge is the bottleneck, are you using writeWithoutResponse or write?

marcosinigaglia avatar Sep 15 '22 12:09 marcosinigaglia

I'm using write

` const writeData = (stringToWrite) => { if (stringToWrite) { console.log("writeData function", stringToWrite)

  const data = stringToBytes(stringToWrite);
  BleManager.write(
    peripheralId,
    service,
    characteristicRX,
    data,
    247
  )
    .then(() => {
      console.log("Write: " + stringToWrite);
    })
    .catch((error) => {
      console.log(error);
    });

}

} `

ApostolosMavroukakis avatar Sep 15 '22 12:09 ApostolosMavroukakis

In my experience is faster to use writeWithoutResponse and put a manual delay between each write.

marcosinigaglia avatar Sep 15 '22 13:09 marcosinigaglia

Will try and come back to you, thanks a ton

ApostolosMavroukakis avatar Sep 15 '22 21:09 ApostolosMavroukakis