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).



  • @ryanbis thanks for your reply. I'm normally only working with up to 5 devices simultaneously. I'll try to lower the poll rate and perform some battery tests then.

    I was thinking about lowering the connection interval to something quite slow under certain scenarios, around 100ms or so. Do you know if, in practice, that's a safe thing to do or does it cause some unexpected issues? I'll test on my side too, of course, but would like to know your opinion.

    Thanks!



  • To be honest, it's been a while since I've dug deep into the numbers for connection interval. I would think 100ms would be good, just make sure to test like crazy :).