StephenBlackWasAlreadyTaken / xDrip-Experimental

Experimental Branches for Collaboration on DexDrip
GNU General Public License v3.0
25 stars 62 forks source link

Excessive BTLowPower/bluesleep wakelocks with Share #169

Open Entropy512 opened 8 years ago

Entropy512 commented 8 years ago

I have noticed when running xDrip on an Xperia Z3 that there is an excessive amout of BTLowPower (Sony stock firmwares) or bluesleep (AOSP-derivative firmwares) kernel wakelocks reducing device deep-sleep percentages significantly.

I enabled the Bluetooth HCI Snoop Log (Settings->Developer Options) and then paired my Dexcom Share receiver, let it collect data for 30-40 minutes and then loaded the results in Wireshark. (Note: A lot of data will be missing/uninterpreted in the snoop log if you do not reboot the device after turning it on, and also Wireshark won't parse some data if you don't monitor the pairing sequence.)

It appears that xDrip is fully resyncing the entire device database every 5 minutes? There's a LOT of data being transferred for just one reading. Also, is the heartbeat necessary/can this be disabled?

How was the protocol for Share2 reverse engineered? It appears from what I can figure out in the xDrip source code there's a lot of commonality between the Share2 protocol and the Dexcom receiver's USB protocol? Is there any readable documentation on what is known about the Share2 protocol anywhere? The use of the rxjava library makes attemptRead() at https://github.com/StephenBlackWasAlreadyTaken/xDrip-Experimental/blob/master/app/src/main/java/com/eveningoutpost/dexdrip/Services/DexShareCollectionService.java#L260 almost impossible to follow ( http://reactivex.io/RxJava/javadoc/rx/functions/Action1.html is completely and totally uninformative... ) - it looks like it's receiving data in this subroutine but what commands the receiver to send it?

Was Share2 REd by assuming commonality with the USB protocol, or did someone use a Bluetooth sniffing setup such as the Ubertooth One ( https://github.com/greatscottgadgets/ubertooth ) and crackle ( https://lacklustre.net/projects/crackle/ )?

Edit: Is there an IRC channel somewhere that the xDrip developers use to communicate/coordinate? #xdrip and #nightscout on Freenode are 100% empty, so obviously not there. :)

StephenBlackWasAlreadyTaken commented 8 years ago

Hey

Re: share Bluetooth protocol, yes unfortunately the only way to get data from the share receiver was to get a full database page, the heartbeat isn't used but I set it up to mirror how the iPhone app seemed to be doing things.

Re: the share protocol, yeah I have an uber tooth and a Nordic sniffer I used to keep track of what was going on. After enough poking around and reading up on some of the Nordic sdk docs it was apparent it was using the Nordic pipes api and just making slightly modified versions of the USB requests (two bytes to note the total request length and the sequence number of this part of the request are added at the front and then the other 18 would be exactly like the USB requests.)

I opted for rx Java because making something that android expects to be used async into something where sequence was everything was a bit tricky and I prefer callbacks over a message bus, but to each their own!

Are you getting poor battery life? I have never noticed any appreciable change but I also don't actually use a share receiver

On Sun, Oct 25, 2015, 12:00 PM Andrew Dodd notifications@github.com wrote:

I have noticed when running xDrip on an Xperia Z3 that there is an excessive amout of BTLowPower (Sony stock firmwares) or bluesleep (AOSP-derivative firmwares) kernel wakelocks reducing device deep-sleep percentages significantly.

I enabled the Bluetooth HCI Snoop Log (Settings->Developer Options) and then paired my Dexcom Share receiver, let it collect data for 30-40 minutes and then loaded the results in Wireshark. (Note: A lot of data will be missing/uninterpreted in the snoop log if you do not reboot the device after turning it on, and also Wireshark won't parse some data if you don't monitor the pairing sequence.)

It appears that xDrip is fully resyncing the entire device database every 5 minutes? There's a LOT of data being transferred for just one reading. Also, is the heartbeat necessary/can this be disabled?

How was the protocol for Share2 reverse engineered? It appears from what I can figure out in the xDrip source code there's a lot of commonality between the Share2 protocol and the Dexcom receiver's USB protocol? Is there any readable documentation on what is known about the Share2 protocol anywhere? The use of the rxjava library makes attemptRead() at https://github.com/StephenBlackWasAlreadyTaken/xDrip-Experimental/blob/master/app/src/main/java/com/eveningoutpost/dexdrip/Services/DexShareCollectionService.java#L260 almost impossible to follow ( http://reactivex.io/RxJava/javadoc/rx/functions/Action1.html is completely and totally uninformative... ) - it looks like it's receiving data in this subroutine but what commands the receiver to send it?

Was Share2 REd by assuming commonality with the USB protocol, or did someone use a Bluetooth sniffing setup such as the Ubertooth One ( https://github.com/greatscottgadgets/ubertooth ) and crackle ( https://lacklustre.net/projects/crackle/ )?

— Reply to this email directly or view it on GitHub https://github.com/StephenBlackWasAlreadyTaken/xDrip-Experimental/issues/169 .

Entropy512 commented 8 years ago

I have noticed a reduction in battery life when using xDrip, in addition time spent in deep sleep is significantly reduced. Usually my device is 80-90% asleep, with xDrip running it's down to 50%, and all of the wakelocks are down in the kernel's Bluetooth subsystem. (In one configuration I was permanently wakelocked, but that was a Bluetooth bug on a custom firmware build that xDrip actually helped identify/resolve. :) )

I'm surprised that the iPhone app is re-requesting so much data, perhaps their Bluetooth subsystem has less of a penalty for such a data sequence. (In my case, the device is a Broadcom bluetooth chipset hung off of a Qualcomm SoC, instead of using Qualcomm's own BT solution. This may be relevant, at some point I might try one of my pure-Qcom devices again)

All of this might become mostly irrelevant once G5 support is figured out.

mgranberry commented 8 years ago

Have you tried my Marshmallow branch lately? I have seen (somewhat) better battery life since making a few changes. I've also changed some alarm settings to be a little more battery-conscious where it won't affect the display/logging of BG data. Waking every 5 minutes and doing network transfers is going to be pretty punishing to the battery regardless.

mgranberry commented 8 years ago

Can you verify that this is fixed in master?

Entropy512 commented 8 years ago

I finally got my hosed Android Studio install working again, installed a build from master on Friday... However I just switched phones so I need to do a pairing on the old phone to verify at some point (tonight maybe?)