Open LiroyvH opened 9 months ago
I can confirm that the patch kills updating of BG values running in follower mode from Nightscout with the "Background Keep-alive" mode set to "Disabled". No BG updates happen until set to “Normal”, even with the screen on, while "Normal" mode does work.
the goal is to test in master mode, why did you test in follower mode? In the end this branch will not be merged, because there's another branch with lots of other changes. Goal is that @paulplant copies this minor change here to his branch
I am doing the main testing in master mode on phones connected to Dexcom transmitters. The follower mode testing was just incidental when building to my phone that has only been used in follower mode. So just an FYI that there is a minor regression here for this specific case. Master mode works as expected.
ok clear
I can confirm that the patch kills updating of BG values running in follower mode from Nightscout with the "Background Keep-alive" mode set to "Disabled". No BG updates happen until set to “Normal”, even with the screen on, while "Normal" mode does work.
Yes, as Johan says, this regression was already fixed several weeks ago in the staging branch. The aim will be to finish everything and hopefully merge into develop (and release) latest tomorrow I guess.
Thanks, @paulplant that’s great, I thought the regression was introduced here, I had not previously tested recent dev.
@bjornoleh , @LiroyvH , @dnzxy probably still waaaaay too early to confirm anything, but please feedback here when you know anything so we can keep this issue open or close it. Cheers.
Looking at what I see in-app (connection state and last connected mismatching last reading from time to time) and what the logs tell me: it's unfortunately still very frequently going in to connection loops with 5.1.4.
Looking at what I see in-app (connection state and last connected mismatching last reading from time to time) and what the logs tell me: it's unfortunately still very frequently going in to connection loops with 5.1.4.
@LiroyvH , please try to reboot your phone if you didn’t already try that. I saw some issues where reconnects happened very frequently after building various other builds. A reboot fixed this, it seems.
@bjornoleh Yep makes no difference. It’ll simply start doing it again at some point. Besides, the issue has been present for a very long time, phone's been rebooted for various reasons copious amounts of time in the meantime :P
Thing is, it shouldn't happen at all; also not after a fresh build. Connect, exchange data, disconnect - sleep until 5 minutes later; that's the flow. But xDrip for some reason often, but not always (especially not when the app is foregrounded (which is odd and one of the reasons why I’m still looking in to the BLE management aspect as other apps do not have these issues)),ends up in a connection loop. This btw doesn’t only drain the transmitter battery, but also causes red loops (failure to wake up or go in a connection loop then (I wonder sometimes if when the app is relaunching/waking up that it fails to work properly on the first connection for some reason and then goes in to a loop because the next attempt we tell ourselves to ignore it)); which has been forcing me to use the official Dexcom app due to reliability issues for months on end now, which really sucks. :(
Ok, yes I am seeing the same now, very frequent reconnects (and reboot made no difference in this case...), I suppose this is what @LiroyvH calls a "connection loop"? It's strange, because sometimes it works well, with only reconnects every five minutes.
@JohanDegraeve: Should we try with a longer delayInSeconds
? I have only been testing 2.0 seconds so far.
2024-04-04 10:15:43.3950 5.0.2 4196 BlueToothTransmitter Will try to reconnect
2024-04-04 10:15:58.6240 5.0.2 4196 BlueToothTransmitter Will try to reconnect
2024-04-04 10:16:13.8820 5.0.2 4196 BlueToothTransmitter Will try to reconnect
2024-04-04 10:16:29.1200 5.0.2 4196 BlueToothTransmitter Will try to reconnect
2024-04-04 10:16:44.3090 5.0.2 4196 BlueToothTransmitter Will try to reconnect
2024-04-04 10:16:59.5420 5.0.2 4196 BlueToothTransmitter Will try to reconnect
2024-04-04 10:17:14.9040 5.0.2 4196 BlueToothTransmitter Will try to reconnect
2024-04-04 10:20:24.1520 5.0.2 4196 BlueToothTransmitter Will try to reconnect
2024-04-04 10:20:33.9400 5.0.2 4196 BlueToothTransmitter Will try to reconnect
2024-04-04 10:25:17.0040 5.0.2 4196 BlueToothTransmitter Will try to reconnect
2024-04-04 10:25:26.9570 5.0.2 4196 BlueToothTransmitter Will try to reconnect
2024-04-04 10:25:42.3830 5.0.2 4196 BlueToothTransmitter Will try to reconnect
2024-04-04 10:25:57.6430 5.0.2 4196 BlueToothTransmitter Will try to reconnect
2024-04-04 10:26:12.8960 5.0.2 4196 BlueToothTransmitter Will try to reconnect
2024-04-04 10:26:28.1170 5.0.2 4196 BlueToothTransmitter Will try to reconnect
2024-04-04 10:26:43.4100 5.0.2 4196 BlueToothTransmitter Will try to reconnect
2024-04-04 10:26:58.7840 5.0.2 4196 BlueToothTransmitter Will try to reconnect
2024-04-04 10:27:14.2040 5.0.2 4196 BlueToothTransmitter Will try to reconnect
2024-04-04 10:30:22.7690 5.0.2 4196 BlueToothTransmitter Will try to reconnect
2024-04-04 10:30:32.4800 5.0.2 4196 BlueToothTransmitter Will try to reconnect
2024-04-04 10:35:18.7380 5.0.2 4196 BlueToothTransmitter Will try to reconnect
2024-04-04 10:35:28.6460 5.0.2 4196 BlueToothTransmitter Will try to reconnect
2024-04-04 10:40:18.6460 5.0.2 4196 BlueToothTransmitter Will try to reconnect
Edit: adding some more context in the logs, although probably not too useful:
2024-04-04 10:15:43.3950 5.0.2 4196 BlueToothTransmitter Will try to reconnect
2024-04-04 10:15:43.4040 5.0.2 4196 CGMG5 connected to peripheral with name DexcomT2, but last reading was less than 2.1 minute ago, will let the connection timeout
2024-04-04 10:15:56.5720 5.0.2 4196 CGMG5 in sendGlucoseDataToDelegate
2024-04-04 10:15:56.5740 5.0.2 4196 CGMG5 glucoseDataArray has no values
2024-04-04 10:15:58.6150 5.0.2 4196 BlueToothTransmitter didDisconnect peripheral with name DexcomT2
2024-04-04 10:15:58.6190 5.0.2 4196 BluetoothPeripheralManager in didDisconnectFrom
2024-04-04 10:15:58.6220 5.0.2 4196 BlueToothTransmitter error: The specified device has disconnected from us.
2024-04-04 10:15:58.6240 5.0.2 4196 BlueToothTransmitter Will try to reconnect
2024-04-04 10:15:58.6280 5.0.2 4196 CGMG5 connected to peripheral with name DexcomT2, but last reading was less than 2.1 minute ago, will let the connection timeout
2024-04-04 10:16:11.8090 5.0.2 4196 CGMG5 in sendGlucoseDataToDelegate
2024-04-04 10:16:11.8110 5.0.2 4196 CGMG5 glucoseDataArray has no values
2024-04-04 10:16:13.8740 5.0.2 4196 BlueToothTransmitter didDisconnect peripheral with name DexcomT2
2024-04-04 10:16:13.8770 5.0.2 4196 BluetoothPeripheralManager in didDisconnectFrom
2024-04-04 10:16:13.8800 5.0.2 4196 BlueToothTransmitter error: The specified device has disconnected from us.
@JohanDegraeve: Should we try with a longer
delayInSeconds
? I have only been testing 2.0 seconds so far.
it's worth trying, but there's a risk that withiin that longer period (like 3 seconds) the app gets suspended and if that happens the app will not reconnect anymore, unless you bring it back to the foreground. Don't try it while you sleep :)
@JohanDegraeve @paulplant Was looking in to this again and noticed something I'm not sure of will make a difference. DisconnectTx (0x09) is defined in the Dexcom opcodes, but as far as I can tell isn't actually called anywhere in the flow - can't find a mention of it anywhere other than the DexcomOpCodes file. xDrip+ does seem to call it at the end of every connection. (https://github.com/NightscoutFoundation/xDrip/blob/master/app/src/main/java/com/eveningoutpost/dexdrip/services/G5CollectionService.java#L989-L998)
I'm not sure if it will make any difference, but on the other hand one could suppose the command isn't there for nothing and above all else: likely can’t hurt. Could we do the same and send the disconnect command to the transmitter at the end of the Dexcom flow (but before any iOS disconnect)? Just to be sure.
I'm not sure if it will make any difference, but on the other hand one could suppose the command isn't there for nothing and above all else: likely can’t hurt. Could we do the same and send the disconnect command to the transmitter at the end of the Dexcom flow (but before any iOS disconnect)? Just to be sure.
Possibly. Go ahead and give it a try. I think you could do it here after having processed glucose data, https://github.com/JohanDegraeve/xdripswift/blob/master/xdrip/BluetoothTransmitter/CGM/Dexcom/G5/CGMG5Transmitter.swift#L1349 and https://github.com/JohanDegraeve/xdripswift/blob/master/xdrip/BluetoothTransmitter/CGM/Dexcom/G5/CGMG5Transmitter.swift#L1367
= writeDataToPeripheral(data: Data(for: .disconnectTx), characteristicToWriteTo: writeControlCharacteristic, type: .withResponse) or (I'm not sure if appendingCRC needs to be added i, i thinkn ot) = writeDataToPeripheral(data: Data(for: .disconnectTx).appendingCRC(), characteristicToWriteTo: writeControlCharacteristic, type: .withResponse)
@JohanDegraeve Thanks! Like so? https://github.com/LiroyvH/xdripswift/compare/master...LiroyvH-DisconnectTx I've added that in and will give it a spin. :)
-edit- Adding that in as linked above makes the build fail with a couple of errors on the modified file:
ok, this should avoid the error
if let writeControlCharacteristic = writeControlCharacteristic { _ = writeDataToPeripheral(data: Data(for: .disconnectTx), characteristicToWriteTo: writeControlCharacteristic, type: .withResponse) }
@JohanDegraeve Yep, that made it built OK! Built and fingers crossed. :)
@JohanDegraeve Too bad, no difference. :( Very first thing it did was go in to a loop heh! Figured I'd watch it a bit longer, but after 2 no problem readings it fell in to another loop until foregrounded. (Though that's not the universal solution either.) Oh well, it would've been really nice if it was this simple. :D
Oh well, it would've been really nice if it was this simple. :D indeed
Just wondering if any progress has been made on this bug? I quite like to use Anubis direct to xDrip4iOS, since sometimes xD misses a few beats from the Dexcom app every so often. Always much more consistent without using the Dexcom app at all.
@swright87 No progress as far as I'm aware.
Logging it on GitHub as well so it's tracked and more people could weigh in if they like: several reports have been submitted, notably from the Anubis community - but also from ONE and G6 users, that their transmitters' batteries are drained way faster than expected when using xDrip4iOS. Official transmitters seem to die in about 45-60 days and Anubii with a larger batteries in 90-110 days or earlier. (Note: Anubis with a proper battery typically easily last double that.)
I've spent quite some time looking in to possible causes (including some time spent with Joshua from the Anubis project, whom I'd like to thank for his insights on the Dexcom firmware), and it keeps coming back to a problem I've mentioned on several occasions over the years where the transmitter goes in to a connection loop with xDrip4iOS. (Eg: you see it connect, disconnect, reconnect, disconnect, reconnect, disconnect and so on and on.)
From what I can see, but do correct me if I'm wrong and/or if the log output is deceiving, the problem lies with xDrip4iOS attempting to reconnect to the transmitter without an apparent reason. When xDrip4iOS initiates a disconnect, it also immediately attempts to reconnect. The Dexcom transmitter will still be awake* and responds to our request to connect. However, as xDrip4iOS then blocks the connection because "last connection was less than x seconds ago": the transmitter doesn't get anything from us. The connection times out after 10 seconds, after which the Dexcom disconnects again. However, as soon as that happens: xDrip4iOS once again tries to connect to the transmitter as indicated in the logs ("Trying to reconnect..."). Once again, the Dexcom transmitter allows this connection but subsequently again xDrip4iOS will not actually send anything to the transmitter because the last connection was less than x ago. After a while of this going on and on, the Dexcom transmitter will give up and phones in again at the original timestamp +5 minutes to send its new readings.
The problem is that this cannot always be reproduced. It's unclear to me why xDrip4iOS sometimes tries to reconnect and sometimes doesn't. It might also be the order of the slots in which it's connecting that might make a difference, but either way: xDrip isn't supposed to try to reconnect, especially not when xDrip itself sent the command to disconnect in the first place. I noticed today that during warm-up a similar issue occurs, but that has different log-output that I haven't analyzed yet. Did also send it to Paul.
I think the underlying issue must still lie within the original FireFly implementation where this behavior was noted, but I think was essentially "dirty patched". (Ignoring the transmitter, which inadvertently keeps it awake for 10 seconds until it times out. And then we ask it to connect again. It's like prank calling someone and every time they pick up you don't say anything.)
Here's an excerpt from the logfiles what that looks like:
And a longer look of such a cycle (including when it phones in again to update the values and then it goes straight back in to a loop):
It looks as if we don't yet expect a disconnect or that we do ask for it to disconnect, but another part of the code thinks its by error and tries to reconnect - but is then frustrated by the 2.1 minute thing. Note: in one of the very first implementations, of which I still have the source code laying around here if anyone's interested :P, this problem is continuous.
Anyway, I don't know IF this is the cause of the reported battery drains. But it seems very likely, as such: logging it as issue here. As an extra note: this seems to occur sooner for me when xDrip4iOS is woken up from slumber. (Eg: it got suspended, but transmitter wakes it up. I'll shamelessly plug my request for full implementation of Background Processing/Activity here which could potentially be good for overall stability (also compared to Loop, iAPS and the official Dexcom-app.))
* = The transmitter is still awake, because the Dexcom keeps listening for a brief moment on all 2 (or 3 in case of Anubis) connection slots to see if the second device (reader/pump) wants a connection as well or not. Instead, xDrip4iOS asks to be connected again - and it honors that request.