Best practices for saving battery life

  • Hi, I'm trying to maintain a connection to a BLE peripheral over hours without drastically draining the phone's battery in a way that's significantly noticeable by the end user.

    This is what I've thought of so far, what do you all think about it?

    Connection interval

    • After some time has passed and the user has not interacted with the app or the peripheral, I'll slow down the connection interval to several hundred ms.

    SweetBlue parameters

    • I was reading the documentation on the defaultStatePollRate. Is there any problem if I switch this to be several seconds after certain conditions? What is the slowest poll rate that you would redommend?
    • Are there any other parameters that I could tweak in favor of the battery life, maybe something related to the wakelock?

    Thanks a lot!

  • @AlejandroHCruz ,

    I think the most bang for the buck you are going to get is adjusting the connection interval. You can try to set the connection priority via BleDevice.setConnectionPriority(). This only gives you LOW/MEDIUM/HIGH, so there's not much fine-tuning you can do (however, you can set whatever parameters you want in your firmware, given you have access to do that).

    I think most of the SweetBlue options will have a minor impact compared to adjusting the connection interval. You may want to consider also adjusting the autoUpdateRate to a higher value (increasing the time between update ticks). This will only really make a difference if there are a lot of devices you are working with, but you may want to run some tests to see what difference there really is. As for the slowest poll rate for the defaultStatePollRate, it's really how confident you are in the android callbacks working. The state poll is there because the callback isn't always called, hence the need for polling. I would say somewhere between .5 and 1 second should be good. Again, it's something you will have to test with your device (and several different phones for better coverage).