Closed brunovollmer closed 1 year ago
I'm aware of this issue on ios, it's due to me not programming the stream interaction well. But on Android I've not seen this before. How many messages are you sending? What's the throughput.
The native code should be handling this OK, it's running a separate thread. But what's your listener doing? OnDataReceived? If that's doing too much work for each request you'll have issues.
Can you confirm whether it's react or Android that's having this issue? I don't have a device available to simulate this, none of my devices stream data.
If react has a constant stream, then you'll need to
For the latter there are many options, but it all depends on what data you have.
I can't answer this for you, they sre design issues.
If it's the native side, you may have to write a custom device connection native class that can handle the constant stream better.
Hey @kenjdavidson,
thanks for the quick answer. I'm just parsing the message and then passing it to redux.
const onDataReceived = async (data: any) => {
await data;
let msg = parseBluetoothMessage(data);
if (
msg.dataStr.type !== undefined &&
msg.dataStr.type === 'environment_data'
) {
dispatch(setCurrentObjects(msg.dataStr.objects));
dispatch(setCurrentObstacles(msg.dataStr.obstacles));
}
if (msg.type === 'error') {
dispatch(setErrorMessage(msg.errorMsg));
}
};
The throughput should be around ~5-10 messages per second. Those are still individual messages though.
Can you confirm whether it's react or Android that's having this issue? I don't have a device available to simulate this, none of my devices stream data.
How would I test this? And if I would implement a limiting in the app how would you design that? I think dropping some messages should not hurt to much especially if it allows the app to work "smoother"
With regards to confirming Android/Native
isn't the issue, you can try to connect without setting up the auto read. This way you will have messages coming into the buffer on Android, but not hitting the UI Thread on React (js). If this doesn't halt the app, then the Android side should be fine.
With regards to the limiting things on the React (js) side, you'll have to do some research on what's available to offload processing from the UI Thread on Javascript/React. You need to think of getting getting bluetooth data much like getting HTTP data. If you're running a reducer getting HTTP data then you're going to see the same issues. There are a number of sites/libraries that document how to do Async reducers, this is probably what you're going to want to look into.
If you're already doing this, then I'm not sure. I'd have to spend way more time researching, time of which I don't have.
Hey @kenjdavidson,
thanks for the tips. I will spent some time in this direction and will let you know if it is successful or there are open questions.
Sounds good. I'll leave the task open for a bit. Please update it if you get things resolved or figure something out.
Get Outlook for Androidhttps://aka.ms/ghei36
From: Bruno @.> Sent: Thursday, February 17, 2022 3:07:15 AM To: kenjdavidson/react-native-bluetooth-classic @.> Cc: Ken Davidson @.>; Mention @.> Subject: Re: [kenjdavidson/react-native-bluetooth-classic] Device freezes on to many messages (Issue #169)
thanks for the tips. I will spent some time in this direction and will let you know if it is successful or there are open questions.
— Reply to this email directly, view it on GitHubhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fkenjdavidson%2Freact-native-bluetooth-classic%2Fissues%2F169%23issuecomment-1042674548&data=04%7C01%7C%7Cd37390d609c541577e2b08d9f1ec831e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637806820379678548%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=%2BNnKTCKr6L2ybRdjqIkQatOUOw5vxvUtYb92XIY5f%2B4%3D&reserved=0, or unsubscribehttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FABPMJL7NSXRERSSOH5623SDU3SUDHANCNFSM5ON67ODQ&data=04%7C01%7C%7Cd37390d609c541577e2b08d9f1ec831e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637806820379678548%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=GPt1ETapcCcKYsGLeVksZ1%2BUou8S0ej1Odbc%2FfMa7bY%3D&reserved=0. Triage notifications on the go with GitHub Mobile for iOShttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fapps.apple.com%2Fapp%2Fapple-store%2Fid1477376905%3Fct%3Dnotification-email%26mt%3D8%26pt%3D524675&data=04%7C01%7C%7Cd37390d609c541577e2b08d9f1ec831e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637806820379678548%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=dZaTggQh%2BM22QScepuKL6%2FPajTs%2B%2FDJUJUtGi9SRsH4%3D&reserved=0 or Androidhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fplay.google.com%2Fstore%2Fapps%2Fdetails%3Fid%3Dcom.github.android%26referrer%3Dutm_campaign%253Dnotification-email%2526utm_medium%253Demail%2526utm_source%253Dgithub&data=04%7C01%7C%7Cd37390d609c541577e2b08d9f1ec831e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637806820379678548%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=XAZECENTEznPFnUUy3oVOmAs%2BbGgq9k5nukKa%2FAcq8k%3D&reserved=0. You are receiving this because you were mentioned.Message ID: @.***>
Hey,
before I start this I want to mention that I really like this library and that I'm not a professional JS/React developer so it might be that I'm just using some concepts wrong.
System
Mobile Device Environment Provide a list of operating systems on which this issue is relevant.
Application Environment Provide information about your development environment:
Problem
In our setup we have a python client communicating with our react native app via bluetooth. So far everything works fine. I can connect, send messages and reply. In some situations it can happen that the python client sends a lot more messages and this leads to the app losing all responsiveness (buttons don't work, etc.).
My question would be is there a way to handle this inside react native as I guess the problem is somehow related to some event handlers or is the only solution to send less messages? As mentioned before I might miss some basic understanding of React here.
I've appended the code I think is relevant but if you need more information I'm happy to update the information.
Thanks in advance,
Bruno
Code