Slow Startup When Inside Region; Conflicting Events
gchallen opened this issue · comments
Thanks for the excellent library! We're trying to use it as part of an app for CS 125 @ Illinois to track when our course staff (and eventually students) come and go into a room that we use for office hours. Source code is here: https://github.com/gchallen/cs125_app. I'm very new to flutter and to Dart so am just trying to get something simple working that logs when regions are entered and exited from.
I'm having two problems at present. First, the library seems slow to report when the app is restarted inside an existing region. This is in contrast to the fairly quick reports that are generated when regions are exited or entered, or when I turn the beacon on and off—those appear within a few seconds. When I do a restart of the app with an existing beacon nearby, several minutes go by before the first reports are received. However, the library does seem to know it's inside an existing region based on this message from the logs:
06-21 09:18:38.711 20541-20541/edu.illinois.cs.cs125.cs125app I/ScanJob: We are inside a beacon region. We will not scan between cycles.
So is there a way to query on startup to determine the current region? I didn't see that in the API description, although not everything seems to be documented yet.
Second, the beacon does begin to be reported I'm getting repeated pairs of exited region + entered region messages back to back. That doesn't seem to happen in other scenarios: for example, when I turn the beacon on and off I get one message back, not a pair. Obviously we could do some debouncing in our app but I thought perhaps this was related to the issue I described above.
Hello, are you testing on iOS or Android?
Can you reproduce the issue on both platforms?
Under the hood implementations are very different and the issue might be specific to one platform. That would help a lot for debugging.
Testing on Android. I don't have an iOS device to test with at this point, and the emulator isn't helpful here... sorry.
Easiest steps to reproduce:
- Launch app. Turn beacon off and on. Receive notifications promptly.
- Close app.
- Restart app... and wait.
- Eventually you begin to see pairs of exited/entered at regular but slow intervals.
Ok will try to tomorrow on iOS & android, see if I can reproduce.
In the meantime would you mind trying and report back behaviour using the following android app: https://github.com/AltBeacon/android-beacon-library-reference
It's the library that the plugin is using for working with beacons on android.
So I've noticed this now on a React Native library that also uses AltBeacon. You might want to peek at the writeup here: MacKentoch/react-native-beacons-manager#99.
Essentially it seems that AltBeacon > 2.8 stopped delivering didEnterRegion
events when the app is restarted. There is a different event that you are supposed to use called didDetermineStateForRegion
: https://altbeacon.github.io/android-beacon-library/state-persistence.html.
Would it be possible for this library to forward that event? It looks like there is just a log message there currently.
Thanks for the research! I will implement a fix tomorrow.
Great, thanks! However, note that I'm not sure that this will fix the underlying issue. I've opened this bug against AltBeacon itself, since I was able to reproduce the behavior using their reference app.
Perhaps this is the result of the cheap iBeacons I'm using. Any advice on good low-cost alternatives?
Unfortunately I have no idea, I have very little experience with beacons outside of our test lab.
This library was developed for and sponsored by Pointz.
Maybe @AndrewPetrovics knows some good and reliable hardware?
I will track closely AltBeacon/android-beacon-library#708.
@gchallen can you try to update the reference project of android-beacon-library by adding beaconManager.setRegionStatePersistenceEnabled(false)
as suggested in AltBeacon/android-beacon-library#708?
If it works, it seems to me that the clean way of handling this would be by exposing this option on the flutter side.
Beacons.configure(BeaconsSettings(android: BeaconsSettingsAndroid(regionStatePersistenceEnabled: false)));
Let me know. Thanks.
@gchallen Were you able to make more experimentation with android-beacon-library?
Right now I'm thinking about allowing more options on setup
method in order to customize the working of android-beacon-library, but leaving the default behaviour consistent with the original library.
Sorry for the delay—I've been out of town without access to a testing harness. IIRC I did try this and it does work properly, although it doesn't debounce the spurious enter and exit events.
FYI I've moved both away from Flutter and away from general beacons for this project (in favor of Estimotes), so future testing may be limited. But overall your solution sounds like a good one.
I would like to fork this and test it on my own. although I have to configure my own beacons than you are using. I am using Sensoro Smart4aa... I have a hard time reading how to set up the instructions provided in the README.md. I will try to continue with your project btw. Thanks!