dotintent / react-native-ble-plx

React Native BLE library
Apache License 2.0
3.07k stars 512 forks source link

Write failed for device on large BLE packets #731

Closed Frondall closed 4 years ago

Frondall commented 4 years ago

Expected Behavior

Module should be able to handle all size of packets that are written. If packets are too large for the MTU, break them up automatically.

Current Behavior

When trying to send large packets (148 bytes in this case) the following non-descriptive error is seen

[BleError: Characteristic 06d1e5e7-79ad-4a71-8faa-373789f7d93c write failed for device 20:FA:BB:06:AF:94 and service bc2f4cc6-aaef-4351-9034-d66268e328f0]

This occurs when using writeCharactersticWithResponseForDevice. I have tried to use writeCharactersticWithoutResponseForDevice but the device never receives the data. Everything works correctly up until this large packet is sent Sending smaller packets have no issues.

Immediately prior to the failed packet the device successfully received and responded to multiple smaller packets (5 to 18 bytes).

I have tried changing the MTU to 150 and 300 but receive the same error.

Originally the package used was 1.0.1, after upgrading to 2.0.1 the problem still remains.

I found this bug report for a similar issue but it doesn't explain if or how it was fixed https://github.com/Polidea/react-native-ble-plx/issues/549

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

  1. Connect to a BLE device
  2. Attempt to send a large packet to the device (148 bytes in my case)
  3. The device with either not receive the packet or will fail with the error above

Context

Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions. Both JS and platform logs can be enabled via setLogLevel function call.

dariuszseweryn commented 4 years ago

Hi, Firstly — there is a wiki page on how to get most of the error. Secondly — it is your peripheral that does not support the action you try to perform (google 'ble prepared write' or 'ble queued write'). You have not specified it but I assume the negotiated MTU is <150. Consult the specification of your peripheral how it expects data of this length delivered. Best regards