question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BTEvents.READ callback with latency

See original GitHub issue

Mobile Device Environment

  • Device: Xiaomi Mi A3 & Samsung Galaxy Tab A
  • OS: API 28

Application Environment

  • React Native version: 0.63.1
  • RN Bluetooth Classic version: 0.10.9

Describe the bug Handling data received by BTEvents.READ. I discovered that the data is processed with a certain delay (almost 1 second) and the data does not arrive in the same amount of messages per second as that sent by the device. Finally, after a certain time the listener stops processing anything.

To Reproduce Steps to reproduce the behavior:

  1. Add the listener in componentDidMount() and define the function to handling the data

handleRead = data => {
    console.log(data.data);
    this.setState({sensorValue: data.data});
};

componentDidMount() {
...

this.onRead = RNBluetoothClassic.addListener(
      BTEvents.READ,
      this.handleRead,
      this
    );

...
}
  1. Connect to the device
  2. See the data in the device and the output log

Expected behavior Receive data as close as possible to real time and never stop of receive data.

Screenshots Screenshoot of the data received by the bluetooth serial terminal app serial_bluetooth_terminal

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
eipporkocommented, Aug 20, 2020

Sorry about the delay in this response but I was doing some kind of research about the problem related with stop receiving data from the bluetooth device.

I found the next:

  • I was testing with different Android 10 devices (Xiaomi Mi A2, Xiaomi Mi A3 & OnePlus 5T)
  • The only one where I found this weird behaviour was in the Xiaomi Mi A3.
  • Before a while (not always at the same time) the app stops of receiving data.

Checking the log with adb logcat I found that after the next messages, the application stops of receiving data from the InputStream.

08-20 14:17:41.175   683  2902 I vendor.qti.bluetooth@1.0-ibs_handler: DeviceSleep: TX Awake, Sending SLEEP_IND
08-20 14:17:41.175   683  2902 D vendor.qti.bluetooth@1.0-ibs_handler: SerialClockVote: vote for UART CLK OFF
08-20 14:17:41.326   683  2755 D vendor.qti.bluetooth@1.0-wake_lock: Release wakelock is released 

The thread related with the task of reading data from the InputStream, gets stuck waiting for input data available to write in the buffer. You can find this process here->bluetooth/RNBluetoothClassicService.java:468

At first I thought that could be something related with the socket between android and the bluetooth device, but despite not been receiving data if I turn off the bluetooth device the thread which was stuck waiting for data, gets an exception and stops gracefully showing in the log the next message Disconnected - was it cancelled? false

So seems that the socket is open and working but something related with the communication protocol between the Android and the Bluetooth device is wrong.

0reactions
eipporkocommented, Aug 20, 2020

Maybe I explained it wrong, but the behaviour with the native app (Terminal) is the same, when the logcat shown the messages commented before the application stops to receive data.

Probably is something related with the OS, but I don’t know if there is any way to manage this and avoid this behaviour.

08-20 17:23:46.120   683  2902 I vendor.qti.bluetooth@1.0-ibs_handler: DeviceSleep: TX Awake, Sending SLEEP_IND
08-20 17:23:46.121   683  2902 D vendor.qti.bluetooth@1.0-ibs_handler: SerialClockVote: vote for UART CLK OFF
08-20 17:23:46.282   683  2755 D vendor.qti.bluetooth@1.0-wake_lock: Release wakelock is released 
Read more comments on GitHub >

github_iconTop Results From Across the Web

Waiting for asynchronous events - Undocumented Matlab
delay = 0.01; % 10 milliseconds while ~object.isDone % set by the callback pause(delay); % a slight pause to let all the data...
Read more >
Understanding Callbacks, Event Loops, and EventEmitters in ...
setTimeout() accepts a callback function and a delay in milliseconds as first and second arguments, respectively. The callback function is fired after 5,000 ......
Read more >
simpy.events — Core event types - Read the Docs
Timeout (env, delay, value), A Event that gets triggered after a delay has passed. ... Once an event gets processed, all callbacks will...
Read more >
windows - What is the latency (or delay) time for callbacks ...
The Windows scheduler runs at either 10ms or 16ms intervals by default depending on the processor. If you use the timeBeginPeriod() API you ......
Read more >
Socket.on(event, callback) - Grafana k6
Set up callback functions for various events on the WebSocket connection.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found