I am building a Flutter app that uses bluetooth to detect bluetooth beacons. I want to monitor the distance (RSSI) of the beacons continuously but I am not too sure how to approach this.
I am currently using flutter_blue. I am open to any new packages.
At the moment I am just scanning for devices.
_flutterBlue.scan(scanMode: ScanMode.balanced).listen((scanResult) {
// scanResult.device.
print("${scanResult.device.id} :: ${scanResult.device.name}");
// check if uuid can be assigned to a gate
if (!_gateOpening && !_preparingToOpenGate) {
_userGates.forEach((manualGate) {
manualGate.gates.forEach((gate) {
gate.beacons.forEach((beacon) {
if (beacon.uuid == scanResult.device.id.id) {
print("found a uiid");
if (gate.detectedBeacons.containsKey(scanResult.device.id.id)) {
gate.detectedBeacons[scanResult.device.id.id]
.insert(0, scanResult.rssi);
} else {
gate.detectedBeacons[scanResult.device.id.id] = [
scanResult.rssi
];
}
if (gate.detectedBeacons[scanResult.device.id.id].length >=
_config.minBLEDetections) {
gate.detectedBeacons[scanResult.device.id.id].removeLast();
}
}
});
});
});
//// only take readings further if gps is struggling
if (_gpsAccuracy > _config.maxFineAccuracyLevel) {
approachingBeacons();
}
}
});