-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sometimes startPeripheralScan doesn't return any result #480
Comments
Hi! Could you set logs to verbose, run the application from native IDE (XCode or Android Studio, but Android project, not Flutter) and check the logs? Could you paste them if that didn't give you an idea as to what happened? |
Yes, ok this is log when it discovers all the devices:
And this is the log, when no devices are found:
This log is the same case as above:
Here is the log when no devices are returned twice in a row:
I'm using your last library version and Flutter 1.17.4. |
Did you do |
Yes, here:
|
It has to be called after |
Yes, I can. I got this log when the scan returns three devices instead of four expected:
And here is the log when it doesn't return any device:
As far I can see, when no devices are returned, these lines are missing:
|
It seems as if native client was not there. Are you using |
No, I am using the Bloc pattern and the only place I use it is in a dispose method:
Then this method is called here: (I am using Provider lib)
Also, I don't think that can be the problem, because it occur in a random way, for example, if I try to scan devices after it returns no devices, it could now return all the devices or maybe not. |
Try setting a breakpoint on |
Hmm ok thanks, changing the radio state too fast, maybe explain why sometimes I don't get any results. However what about the other problem? Sometimes the function does not show all the available devices. |
Perhaps the advertisement simply didn't come? 5 seconds isn't a lot. Try adding a two second delay between stopping and restarting the scan and lengthen the scanning period to 15 seconds. Can you add a log to your dispose method to see if it's not called when it shouldn't be? |
Thanks for the suggestion, I will take into account to add a delay between stopping and restarting the scan. On the other hand, I don't think 5 seconds isn't a lot. This application I am doing is a refactor of a previous application I did with Ionic framework, and in that case 5 seconds were enough to identify all the near devices. I have debugged with a breakpoint on my dispose method, and it is never called, as it just have to be called at the end of the app. |
5 seconds may or may not be a lot. If you cannot scan all devices you expect you can change scan mode to more aggressive. |
Hi @dariuszseweryn, yes that's why I changed the default LowPower mode to Balanced mode, I just wonder why I can get all the devices in LowPower mode with the other app. |
So I assume you do not try to start more than 5 scans in any 30 second window. I also assume you do not try to run the scan in the background. Am I correct? |
Do you mean simultaneously? If so, then I am just one scan at time. If you do not mean simultaneously, then yes, it is possible to start more than five scans in a 30 second window, because I let the user to start or stop the scans but with a default timeout of 5 seconds (if they don't press the stop button). |
Legacy API used aggressive scan mode.
Not necessarily simultaneously. Serial calls may trigger throttling as well. Thing is that the library should cover that situation if the manager is not being recreated in the mean time. Do you have any specific recreation scenario under which the results are not returned? The more repeatable the better. |
Oh sorry, I didn't know it.
I have created a basic project based on the one I am developing in order to give you a way to test: |
Do you have any error handling there? I can't see it. I am not yet fluent with Flutter/Dart |
I'm just handling the error in _init() function, then I send it to state stream:
I'm not handling errors in startScan and stopScan functions, because startScan returns a stream, and an error in stopScan, at least for me, is not very important to the final user. |
From what I know the |
You are right, it's my mistake. I have updated my repo handling stream errors.
However, none of them are triggered so the error is not there, and the problem that sometimes does not return any result still appears. |
Hi ! |
Confirmed. The problem is that the native side is reporting an issue with scanning but the flutter side is not yet listening (race condition). Working on a fix. |
Hi!
I am using your library for a personal project. The problem I have is that when I try to scan many times, the function startPeripheralScan doesn't return anything, or some devices aren't shown. Here is my code:
The text was updated successfully, but these errors were encountered: