You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I noticed that my scan was restarting every 6 seconds. See "steps to reproduce" for details of the problematic code line.
I was able to trace this behavior to the following explanation:
// Determine if we need to restart scanning. Restarting scanning is only
// needed on devices incapable of detecting multiple distinct BLE advertising
// packets in a single cycle, typically older Android devices (e.g. Nexus 4)
// On such devices, it is necessary to stop scanning and restart to detect
// multiple beacon packets in the same scan, allowing collection of multiple
// rssi measurements. Restarting however, causes brief detection dropouts
// so it is best avoided. If we know the device has detected to distinct
// packets in the same cycle, we will not restart scanning and just keep it
// going.
I have several distinct packets within the same cycle, and my settings are no "between scan" period and my scan returns results every 100ms. Based on the description above, my scan should not be restarted because of this issue found on certain old Android devices. It is important to notice that (the reason for pointing this out will come up later in this post) I have /no/ repeated packets within those 6 seconds (they are /all/ distinct).
Actual behavior
I don't expect my scan to stop and restart so often (I was expecting once every 30 minutes, to prevent Android from stopping the scan on its own), and I think I know where the problem is.
Steps to reproduce this behavior
Go to DistinctPacketDetector.java, line 39. This line returns true when the packet is found (so, /not/ distinct). A couple lines below, line 42, this line returns true when the packet is not found (so, distinct). This is strange, one of the two is probably wrong (probably the first one), but additionally the way that this method (isPacketDistinct) is used is also strange.
Go to ScanHelper.java line 449, the line of code will evaluate to true if the packet at hand is /not/ distinct (the log entry right after that seems to confirm this is the intent by saying non-distinct packet detected), and it will set setDistinctPacketsDetectedPerScan to true.
In my case, within a 6 second period, I have less than 1000 packets, so I never get to the first return of the isPacketDistinct, but always the second one. All my packets are unique (I do not repeat /any/ packets within a 6 second interval) and so it always returns true, and then ScanHelper never sets "setDistinctPacketsDetectedPerScan" to true, and my scans reset every 6 seconds.
You can see the way that the distinctPacketsDetected flag is used in CycledLeScanner.java line 405.
I believe a solution requires a few changes:
In ScanHelper.java line 449, remove the not ("!") from the beginning of the conditional, and in the following line, change the log entry from "Non-distinct" to "Distinct".
In DistinctPacketDetector.java line 39, invert the return value (add a "!"), then in line 42 the return is fine but there needs to be a check and if "mDistinctPacketsDetected" set is empty (the first time this is called), return false (not distinct -- this will prevent setting setDistinctPacketsDetectedPerScan on the first packet received).
Mobile device model and OS version
Samsung Galaxy Tab Active2 on Android 8.1.0
Android Beacon Library version
Latest in master.
IMPORTANT: This forum is reserved for feature requests or reproducible bugs with the library itself. If you need help with using the library with your project, please open a new question on StackOverflow.com.
The text was updated successfully, but these errors were encountered:
Expected behavior
I noticed that my scan was restarting every 6 seconds. See "steps to reproduce" for details of the problematic code line.
I was able to trace this behavior to the following explanation:
// Determine if we need to restart scanning. Restarting scanning is only
// needed on devices incapable of detecting multiple distinct BLE advertising
// packets in a single cycle, typically older Android devices (e.g. Nexus 4)
// On such devices, it is necessary to stop scanning and restart to detect
// multiple beacon packets in the same scan, allowing collection of multiple
// rssi measurements. Restarting however, causes brief detection dropouts
// so it is best avoided. If we know the device has detected to distinct
// packets in the same cycle, we will not restart scanning and just keep it
// going.
I have several distinct packets within the same cycle, and my settings are no "between scan" period and my scan returns results every 100ms. Based on the description above, my scan should not be restarted because of this issue found on certain old Android devices. It is important to notice that (the reason for pointing this out will come up later in this post) I have /no/ repeated packets within those 6 seconds (they are /all/ distinct).
Actual behavior
I don't expect my scan to stop and restart so often (I was expecting once every 30 minutes, to prevent Android from stopping the scan on its own), and I think I know where the problem is.
Steps to reproduce this behavior
Go to DistinctPacketDetector.java, line 39. This line returns true when the packet is found (so, /not/ distinct). A couple lines below, line 42, this line returns true when the packet is not found (so, distinct). This is strange, one of the two is probably wrong (probably the first one), but additionally the way that this method (isPacketDistinct) is used is also strange.
Go to ScanHelper.java line 449, the line of code will evaluate to true if the packet at hand is /not/ distinct (the log entry right after that seems to confirm this is the intent by saying non-distinct packet detected), and it will set setDistinctPacketsDetectedPerScan to true.
In my case, within a 6 second period, I have less than 1000 packets, so I never get to the first return of the isPacketDistinct, but always the second one. All my packets are unique (I do not repeat /any/ packets within a 6 second interval) and so it always returns true, and then ScanHelper never sets "setDistinctPacketsDetectedPerScan" to true, and my scans reset every 6 seconds.
You can see the way that the distinctPacketsDetected flag is used in CycledLeScanner.java line 405.
I believe a solution requires a few changes:
In ScanHelper.java line 449, remove the not ("!") from the beginning of the conditional, and in the following line, change the log entry from "Non-distinct" to "Distinct".
In DistinctPacketDetector.java line 39, invert the return value (add a "!"), then in line 42 the return is fine but there needs to be a check and if "mDistinctPacketsDetected" set is empty (the first time this is called), return false (not distinct -- this will prevent setting setDistinctPacketsDetectedPerScan on the first packet received).
Mobile device model and OS version
Samsung Galaxy Tab Active2 on Android 8.1.0
Android Beacon Library version
Latest in master.
IMPORTANT: This forum is reserved for feature requests or reproducible bugs with the library itself. If you need help with using the library with your project, please open a new question on StackOverflow.com.
The text was updated successfully, but these errors were encountered: