BTEvents.READ callback with latency
See original GitHub issueMobile 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:
- 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
);
...
}
- Connect to the device
- 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
Issue Analytics
- State:
- Created 3 years ago
- Comments:14 (7 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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:
Checking the log with
adb logcat
I found that after the next messages, the application stops of receiving data from the InputStream.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.
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.