Wireless technologies such as Wi-Fi and Bluetooth enable device connectivity, including smartphones and tablets. In our case, we needed to connect mobile devices with a Raspberry Pi, which would serve as a check-in station. Any user near the check-in station should be able to check in effortlessly.
Each wireless technology has its own pros and cons. Wi-Fi requires users to manually connect, while Bluetooth also requires a secure pairing process. Given these constraints, we opted for Beacon technology, which allowed us to quickly identify the nearest Raspberry Pi check-in station without requiring extra user effort.
Challenges Faced
– Frequent disconnections
– Handling user movement between multiple check-in stations
– Managing app behavior in background/foreground states
– Battery drainage due to continuous Beacon detection
The need to detect Beacons in the app background while minimizing battery consumption was a major concern raised by users. This prompted us to revisit our Beacon detection logic.
Optimized Beacon Detection Approach
Initially, we used the Beacon ranging API, which ran every second, causing significant battery drain. To improve efficiency, we made two key changes:
1. Utilizing Region Monitoring: This alerts the app when the device enters or exits a Beacon region.
2. Selective Ranging: Instead of running continuously, ranging is triggered only when the device is inside a Beacon region.
Updated Code Implementation
beaconManager.addMonitorNotifier(new MonitorNotifier() { @Override
public void didEnterRegion(Region region) {
Log.v(TAG, "didEnterRegion fired");
startBeaconRanging();
}
@Override
public void didExitRegion(Region region) {
Log.v(TAG, "didExitRegion fired");
stopBeaconRanging();
}
@Override
public void didDetermineStateForRegion(int state, Region region) {
Log.v(TAG, "didDetermineStateForRegion fired : " + state);
if (state == MonitorNotifier.INSIDE) {
startBeaconRanging();
} else {
stopBeaconRanging();
}
}
});
try {
beaconManager.startMonitoringBeaconsInRegion(region);
} catch (Exception ex) {
ex.printStackTrace();
}
Key Improvements
– Battery Optimization: By eliminating continuous scanning, the app conserves battery life.
– Efficient Detection: The app now responds only to significant state changes instead of performing frequent scans.
– Seamless User Experience: Users can check in smoothly without unnecessary delays or disconnections.
With these optimizations, our Beacon implementation now provides a more stable and power-efficient solution for check-in stations using Raspberry Pi.
Remember! Use of latest technology is always cool for customers but when used on mobile devices the drain on battery and performance can be a major reason for a quick uninstall 🙂