My lighthouse (SensorTag CC2541) is an advertiser transmitting its information 10 times per second.
My Android apps are scanned with BluetoothLeScanner. Basically, the time between each scan result registered by me BluetoothLeScanneris from 0.1 second to 0.6 second, which is completely normal. But sometimes (every 5 seconds) the time between the results of each scan is more than 2 seconds. Sometimes it’s up to 5. Which delays my application because I need a quick beacon detection.
I do not scan the package, I just process each scan result when it comes in.
I tried to deal with this issue of indifference by creating my own scanSettingsand making reportDelay set to 0, and the scan mode with low latency. However, when I implement it using the code below, my scanner only takes every ONCE beacon. But when used mLeScanner.startScan(scanCallback)without, scanSettingsI get several results from the same beacon (albeit at inconsistent intervals, as described above). Does anyone know what might cause this problem?
BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
BluetoothAdapter mBluetoothAdapter = bluetoothManager.getAdapter();
BluetoothLeScanner mLeScanner = mBluetoothAdapter.getBluetoothLeScanner();
ScanSettings.Builder scanSettingsBuilder = new ScanSettings.Builder();
scanSettingsBuilder.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY);
scanSettingsBuilder.setReportDelay(0);
scanSettingsBuilder.setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES);
ScanSettings scanSettings = scanSettingsBuilder.build();
ScanCallback scanCallback = new ScanCallback() {
@Override
public void onScanResult(int callbackType, ScanResult result) {
super.onScanResult(callbackType, result);
}
@Override
public void onBatchScanResults(List<ScanResult> results) {
super.onBatchScanResults(results);
}
@Override
public void onScanFailed(int errorCode) {
super.onScanFailed(errorCode);
}
};
mLeScanner.startScan(null, scanSettings, scanCallback);
The result shows callbackType = 1, and scanSettings does the same when I register it before the mLeScanner.startScan (....) file, as far as I can see, this is not a problem.
UPDATE. It seems that the only problem with checking once when using scanSettings is that my beacons have connected mode. I will try to disable them tomorrow.
, scanSettings, ?
user1747330