Strategies to improve battery usage of our SDKs

Strategies to improve battery usage of our SDKs

At MOCA we have designed our SDKs to be very efficient and use the minimum necessary battery for Proximity Marketing use cases. We prefer low energy solutions that do not involve GPS and, for Android, offer ways to fine tune the sensitivity of the SDK when reacting to BLE Beacons. This support article will outline some best practices so the SDK can be configured to be as efficient as necessary for your use case.

 

Android

Our Android SDK uses proprietary Geofence and BLE Beacon engines. These are configurable in the MOCA.properties file. We'll start with the BLE configuration:

 

# MOCA driver. This is required for Bluetooth Beacon detection. Set it to false if a custom
# beacon driver is being used
mocaDriver = true

The mocaDriver entry manages if the SDK wakes up and scans for nearby beacons. If your project does not use BLE Beacons this setting can be turned off in order to improve battery usage efficiency.

 

# Beacon detection engine profile [LowLatency, Balanced, BatterySaver, Custom]
# LowLatency = Notifications will be delivered almost instantly in foreground and background.
# but will have an important impact on the user's device battery.
# Balanced = Notifications are delivered almost instantly in foreground. In background it can
# take up to one minute. In Android Lollipop, Marshmallow, and N there are operating system
# optimizations that reduce the notification delay (Default setting).
# BatterySaver = Detections in foreground can take up to one minute, and in background up to
#5 minutes. this is the recommended setting for analytics-only usages.

beaconProfile = Balanced

If your project does use Beacons we have presets that allow for fine tuning when we scan. This tuning has to be in line with the project's use case. We have found our Balanced profile to fit most uses, but maybe you need a more aggressive profile.

If for any reason the presets do not cover your use case you can always set the custom profile and manually define the following entries:

# foregroundTimeBetweenScans = 3300
# foregroundScanDuration = 3300
# backgroundTimeBetweenScans = 60000
# backgroundScanDuration = 5001

 

We also have a setting that uses Wi-Fi SSIDs as Beacons. This service can be turned off if not used:

wifiProximity = true

 And has two configuration options that change battery consumption and sensitivity:

# ACTIVE_SCANNING: When a user gets into a geofence that contains Wi-Fi beacons
# MOCA SDK performs a Wi-Fi scan once every 60 seconds in background and once # every 30 seconds in  foreground.
# PASSIVE_SCANNING: SDK will never initiate any Wi-Fi Scan. But if another app
# or the systems performs a Wi-Fi Scanning, the SDK will use this information
# to determine if the device is nearby a Wi-Fi Beacon.
wifiScanningMode = ACTIVE_SCANNING

 

MOCA SDK also allows for the fetch and upload intervals to be set. These are very low consumption and will not improve the battery usage of your app if changed, but can greatly affect propagation of data to/from the SDK:

#Data fetch interval in milliseconds. Defaults to 1 hour
dataFetchInterval = 3600000

#Event upload interval. Defaults to 15 minutes.
eventUploadInterval = 900000

 

iOS

Our iOS SDK is not as configurable as Android due to the fact we use the OS systems for proximity marketing. This means iOS will inform us about proximity to beacons or geofences using the OS's internal systems. These are extremely efficient.

However, when backgrounded, your application will be woken up by iOS in order to respond to location events. That means that the didFinishLaunchingWithOptions could be called several times while the user is moving, or when the device is in the range of bluetooth beacons.
Be extra careful: filter out these events so that MOCA SDK is initialized, but any other heavy tasks are not executed. If the UIApplicationLaunchOptionsLocationKey key is present in the launchOptions, you can tell that the App was launched to respond to a location event.

Example (objective-c):

#import <MOCA.h>

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [MOCA initializeSDK];
    //Filter out the events
    if([launchOptions objectForKey:@"UIApplicationLaunchOptionsLocationKey"]) {
        return YES;
    }
    //do heavy stuff afterwards
}

 

    • Related Articles

    • Beacons Introduction

      Basic concepts: Beacons are devices that broadcast a BLE (Bluetooth Low Energy) radio frequencies. This is detected by BLE compatible smartphones. MOCA supports two Bluetooth Beacon protocols: iBeacon and Eddystone. In this article we'll talk only ...
    • Proximity guidelines: Geofencing - How to maximize detections

      Geofences Smartphones use a combination of sensors to estimate current position, depending on its availability. Specifically: GPS Wi-Fi Cellular networks Bluetooth GPS MOCA SDK does not use GPS directly, as this is a high battery consuming resource ...
    • Proximity marketing

      What is Proximity Marketing? Proximity marketing is engaging the user at the right place and time using a variety of technologies. The video below is a visual example of the technology used to drive user engagement:   Beacons Vs Geofences Two ...
    • iBeacon Protocol: region, blink rate, ranges

      MOCA Platform requires iBeacon protocol compliant beacons. These beacons use BLE (Bluetooth Low Energy) to broadcast their position (up to 100 meters). The iBeacon protocol reports four attributes (prefix, UUID, Major and Minor). Prefix - Advertising ...