StephenBlackWasAlreadyTaken / xDrip-Experimental

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

BLE connection buggy for xBridgeWixel #354

Open savek-cc opened 8 years ago

savek-cc commented 8 years ago

I'm using an Android 6 phone and an xBridgeWixel where the BLE is turned off between data samplings. This leads to failures where I have to completely disable and re-enable BT on my phone in order to receive any further sensor-values from the wixel. Looking at the code in DexCollectionService and comparing it to the DexShareCollectionService, one can see, that the classic DexCollectionService will close the GATT every time the connection to the GATT server is lost. Comparing that to the DexShare service where it does not close the GATT, I changed the code for this disconnect event to mirror the one from DexShare. Also I changed the retry_in calculation to match the one from DexShare to not set the Alarm to just 25 seconds (since the wixel will be sleeping for more than 4 minutes) - but calculate a value like it is done in the DexShare service. Currently running the code on my phone and will report if this helps to solve the issue here.

jstevensog commented 8 years ago

Hi Timm, The 25 second reconnection time came about from me. I found that the previous >60 seconds did not always reliably allow BLE reconnection to occur. Google's own recommendation is to kill off the GATT on disconnect, then re-establish it. I am not sure when this made it into the DexCollectionService code, but previously we had left the GATT open the whole time. The same issue of the GATT randomly deciding not to pass characteristic changes to the collection service, requiring a BT off/on cycle, or a Collection service restart, still occurred back then. Personally, I hope what you are trying works out. I would love a GATT that reliably works indefinitely.

I do find that this issue occurs mostly when WiFi is in use. I spent 2 weeks in South America last year, mostly disconnected from WiFi, and didn't have to cycle BT once. I also don't generally have the issue when I am travelling to/from work, or when I don't bother to connect to the guest WiFi in the office. Mostly around home and if I forget to turn WiFi off is when the issue arises for me. Cheers

On Fri, Jun 24, 2016 at 7:09 AM, Timm Korte notifications@github.com wrote:

I'm using an Android 6 phone and an xBridgeWixel where the BLE is turned off between data samplings. This leads to failures where I have to completely disable and re-enable BT on my phone in order to receive any further sensor-values from the wixel. Looking at the code in DexCollectionService and comparing it to the DexShareCollectionService, one can see, that the classic DexCollectionService will close the GATT every time the connection to the GATT server is lost. Comparing that to the DexShare service where it does not close the GATT, I changed the code for this disconnect event to mirror the one from DexShare. Also I changed the retry_in calculation to match the one from DexShare to not set the Alarm to just 25 seconds (since the wixel will be sleeping for more than 4 minutes) - but calculate a value like it is done in the DexShare service. Currently running the code on my phone and will report if this helps to solve the issue here.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/StephenBlackWasAlreadyTaken/xDrip-Experimental/issues/354, or mute the thread https://github.com/notifications/unsubscribe/AIQs8x4HG2aILSFp5KKoHXRQFUWxQg-Dks5qOvYegaJpZM4I9Pfg .

John Stevens "You are how you live, not what you have."

savek-cc commented 8 years ago

Hi John,

my phone is almost always on WiFi - at home, at work and even in the car, changing between different WiFis 10 times+ on a normal day ;). So far I didn't miss a reading in the last 10h - but I guess I'll have to observe at least a week. Previously I got a lot of dropouts (missed values but no BT restart) during the night, ranging from one to 10 readings - this night there were none - so I'm optimistic but will have to observe.

jstevensog commented 8 years ago

Yeah Timm, I have had it go for at least a week before requiring a restart. Do sometimes get missed packets and observe the bridge going to sleep 2 minutes after it got a packet, meaning the ACK wasn't received. When I have plugged the phone in and done a debug session (rare, because I am usually not in a position to do so) I see that it isn't receiving the data packet or sending the ack packet. Hope it fixes this. Cheers

On Fri, Jun 24, 2016 at 4:04 PM, Timm Korte notifications@github.com wrote:

Hi John,

my phone is almost always on WiFi - at home, at work and even in the car, changing between different WiFis 10 times+ on a normal day ;). So far I didn't miss a reading in the last 10h - but I guess I'll have to observe at least a week. Previously I got a lot of dropouts (missed values but no BT restart) during the night, ranging from one to 10 readings - this night there were none - so I'm optimistic but will have to observe.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/StephenBlackWasAlreadyTaken/xDrip-Experimental/issues/354#issuecomment-228265166, or mute the thread https://github.com/notifications/unsubscribe/AIQs8wpmd5I3Zq-PxSu5x4CXlc81Vgwoks5qO3NwgaJpZM4I9Pfg .

John Stevens "You are how you live, not what you have."

ericandloriapps commented 8 years ago

Curious as to whether these modifications have continued to stay steady. If so, how does one go about making the changes on their own phone? I'm having tons of issues with the disconnect (and no reconnect) and can rarely keep the initial connection for more than 10 minutes...although I am connected to WiFi almost all the time. Was wanting to move my daughter up to Marshmallow, but I definitely need more stability and she has to be connected to WiFi due to cell reception issues within the school.

Thanks to everyone for their hard work in developing and maintaining this amazing software.

Best Eric Moto X Pure Android 6.0

savek-cc commented 8 years ago

Included in xDip+ with commits https://github.com/jamorham/xDrip-plus/commit/b61683bcc92c07243792b17d4cc525f6f9f2121e and later even with a watchdog that automatically restarts the phone's bt if no packet has been received within the last 20 min. (both features optional via config options)

ericandloriapps commented 8 years ago

@savek-cc Thanks for the link. I was using the latest Xdrip beta release, but just uninstalled and installed the Xdrip plus and will give it a shot. i see all of the different switches regarding Bluetooth connectivity within this version, so hopefully I find a setup that stabilizes my connection....or better yet, the default settings may do the trick.

ericandloriapps commented 8 years ago

@savek-cc Thanks for the tip. After installing, changing a few settings, and performing 1 reboot due to some buggy behavior...everything has been rock solid, both with and without wifi turned on. I've activated "Use Excessive Wakelocks", "Bluetooth Watchdog", and "Bluetooth Wakelocks" for the most stability on my phone.