Intermittent Issue with writeWithoutResponse on Android #751
Replies: 1 comment 4 replies
|
Hi @gion-andri That is an interesting screen-grab you have there.
Yes. There is in fact a global queue of Bluetooth commands that could conceivably cause a single dead result to block every subsequent callback: https://github.com/capacitor-community/bluetooth-le/blob/main/src/bleClient.ts#L590-L616. (I suspect we can do better here, but haven't had the time to poke at how hard it would be to turn this into at least device-specific queues).
Things like #734 show the above queuing mechanism in play. I believe these logs come out of Capacitor itself. It would be very interesting to get more from the nosier ADB logs for the device when the error occurs. A few places in the plugin that are of interest (just brain-dumping these for future-us):
Question: Does this characteristic only support a write without response? Based on #104, it seems like if you try and do a no-response write, there are still some times when Android might actually send through a normal write that depends on a response. (You can use nrf Connect as an easy way to see exactly what modes are supported for a characteristic) While doing some searching to see what might be causing your issue here though, I stumbled on this gem of information in a few places (I can't find the official source for this however): https://stackoverflow.com/a/43744888
I wonder if the phone or BLE device is getting into a state where Bluetooth packets are no longer transmitting properly, thus the phone is never calling Can you make the problem occur any more readily by increasing the frequency with which you're writing data? |




@peitschie Thank you for your detailed reply. I tried to look at the things you pointed out. And I think, I found the issue.
I added quite some debugging output in the native android code to try to narrow down, where the issue occurs. I committed the logging code here, so you can see where the logoutput is coming from: main...gion-andri:bluetooth-le:debug-issue
A normal "write without response" command looks like that:
you can see the
writemethod being called in theDeviceclass, the callback coming in to theDevice, the lookup for the timer and callback, and then theBluetoothLeclass handling the data and returning to the capacitor JS bridge.This happens as soon as the problem occurs:
…