Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dexcom connection loops and potential cause for battery drains #494

Open
LiroyvH opened this issue Jan 3, 2024 · 70 comments
Open

Dexcom connection loops and potential cause for battery drains #494

LiroyvH opened this issue Jan 3, 2024 · 70 comments
Labels
bug Something isn't working question Further information is requested

Comments

@LiroyvH
Copy link
Contributor

LiroyvH commented Jan 3, 2024

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:

2023-11-30 11:58:26.4810 4.12.0 4190 BlueToothTransmitter               error: The specified device has disconnected from us.
2023-11-30 11:58:26.4940 4.12.0 4190 BlueToothTransmitter               Will try to reconnect
2023-11-30 12:02:12.5240 4.12.0 4190 BlueToothTransmitter           connected to peripheral with name DexcomTS
2023-11-30 12:02:12.5830 4.12.0 4190 BlueToothTransmitter           didDiscoverServices for peripheral with name DexcomTS

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

2023-11-30 11:52:22.8360 4.12.0 4190 BlueToothTransmitter didDisconnect peripheral with name DexcomTS
2023-11-30 11:52:22.8410 4.12.0 4190 BluetoothPeripheralManager in didDisconnectFrom
2023-11-30 11:52:22.8490 4.12.0 4190 BlueToothTransmitter error: The specified device has disconnected from us.
2023-11-30 11:52:22.8540 4.12.0 4190 BlueToothTransmitter Will try to reconnect
2023-11-30 11:52:22.8620 4.12.0 4190 CGMG5 in sendGlucoseDataToDelegate
2023-11-30 11:52:22.8660 4.12.0 4190 CGMG5 glucoseDataArray has no values
2023-11-30 11:52:23.3290 4.12.0 4190 CGMG5 connected to peripheral with name DexcomTS, but last reading was less than 2.1 minute ago, will let the connection timeout
2023-11-30 11:52:38.1970 4.12.0 4190 BlueToothTransmitter didDisconnect peripheral with name DexcomTS
2023-11-30 11:52:38.2040 4.12.0 4190 BluetoothPeripheralManager in didDisconnectFrom
2023-11-30 11:52:38.2240 4.12.0 4190 BlueToothTransmitter error: The specified device has disconnected from us.
2023-11-30 11:52:38.2280 4.12.0 4190 BlueToothTransmitter Will try to reconnect
2023-11-30 11:52:38.2380 4.12.0 4190 CGMG5 in sendGlucoseDataToDelegate
2023-11-30 11:52:38.2410 4.12.0 4190 CGMG5 glucoseDataArray has no values
2023-11-30 11:52:38.6600 4.12.0 4190 CGMG5 connected to peripheral with name DexcomTS, but last reading was less than 2.1 minute ago, will let the connection timeout
2023-11-30 11:52:53.4010 4.12.0 4190 BlueToothTransmitter didDisconnect peripheral with name DexcomTS
2023-11-30 11:52:53.4060 4.12.0 4190 BluetoothPeripheralManager in didDisconnectFrom
2023-11-30 11:52:53.4150 4.12.0 4190 BlueToothTransmitter error: The specified device has disconnected from us.
2023-11-30 11:52:53.4180 4.12.0 4190 BlueToothTransmitter Will try to reconnect
2023-11-30 11:52:53.4250 4.12.0 4190 CGMG5 in sendGlucoseDataToDelegate
2023-11-30 11:52:53.4290 4.12.0 4190 CGMG5 glucoseDataArray has no values
2023-11-30 11:52:53.9860 4.12.0 4190 CGMG5 connected to peripheral with name DexcomTS, but last reading was less than 2.1 minute ago, will let the connection timeout
2023-11-30 11:53:08.7430 4.12.0 4190 BlueToothTransmitter didDisconnect peripheral with name DexcomTS
2023-11-30 11:53:08.7640 4.12.0 4190 BluetoothPeripheralManager in didDisconnectFrom
2023-11-30 11:53:08.7700 4.12.0 4190 BlueToothTransmitter error: The specified device has disconnected from us.
2023-11-30 11:53:08.7720 4.12.0 4190 BlueToothTransmitter Will try to reconnect
2023-11-30 11:53:08.7750 4.12.0 4190 CGMG5 in sendGlucoseDataToDelegate
2023-11-30 11:53:08.7800 4.12.0 4190 CGMG5 glucoseDataArray has no values
2023-11-30 11:53:09.2250 4.12.0 4190 CGMG5 connected to peripheral with name DexcomTS, but last reading was less than 2.1 minute ago, will let the connection timeout
2023-11-30 11:53:23.9850 4.12.0 4190 BlueToothTransmitter didDisconnect peripheral with name DexcomTS
2023-11-30 11:53:23.9890 4.12.0 4190 BluetoothPeripheralManager in didDisconnectFrom
2023-11-30 11:53:23.9960 4.12.0 4190 BlueToothTransmitter error: The specified device has disconnected from us.
2023-11-30 11:53:24.0000 4.12.0 4190 BlueToothTransmitter Will try to reconnect
2023-11-30 11:53:24.0030 4.12.0 4190 CGMG5 in sendGlucoseDataToDelegate
2023-11-30 11:53:24.0050 4.12.0 4190 CGMG5 glucoseDataArray has no values
2023-11-30 11:53:24.4660 4.12.0 4190 CGMG5 connected to peripheral with name DexcomTS, but last reading was less than 2.1 minute ago, will let the connection timeout
2023-11-30 11:53:39.2100 4.12.0 4190 BlueToothTransmitter didDisconnect peripheral with name DexcomTS
2023-11-30 11:53:39.2120 4.12.0 4190 BluetoothPeripheralManager in didDisconnectFrom
2023-11-30 11:53:39.2180 4.12.0 4190 BlueToothTransmitter error: The specified device has disconnected from us.
2023-11-30 11:53:39.2220 4.12.0 4190 BlueToothTransmitter Will try to reconnect
2023-11-30 11:53:39.2280 4.12.0 4190 CGMG5 in sendGlucoseDataToDelegate
2023-11-30 11:53:39.2310 4.12.0 4190 CGMG5 glucoseDataArray has no values
2023-11-30 11:53:39.7050 4.12.0 4190 CGMG5 connected to peripheral with name DexcomTS, but last reading was less than 2.1 minute ago, will let the connection timeout
2023-11-30 11:53:54.4550 4.12.0 4190 BlueToothTransmitter didDisconnect peripheral with name DexcomTS
2023-11-30 11:53:54.4590 4.12.0 4190 BluetoothPeripheralManager in didDisconnectFrom
2023-11-30 11:53:54.4640 4.12.0 4190 BlueToothTransmitter error: The specified device has disconnected from us.
2023-11-30 11:53:54.4710 4.12.0 4190 BlueToothTransmitter Will try to reconnect
2023-11-30 11:53:54.4740 4.12.0 4190 CGMG5 in sendGlucoseDataToDelegate
2023-11-30 11:53:54.4810 4.12.0 4190 CGMG5 glucoseDataArray has no values
2023-11-30 11:53:55.0340 4.12.0 4190 CGMG5 connected to peripheral with name DexcomTS, but last reading was less than 2.1 minute ago, will let the connection timeout
2023-11-30 11:54:09.7850 4.12.0 4190 BlueToothTransmitter didDisconnect peripheral with name DexcomTS
2023-11-30 11:54:09.7910 4.12.0 4190 BluetoothPeripheralManager in didDisconnectFrom
2023-11-30 11:54:09.7950 4.12.0 4190 BlueToothTransmitter error: The specified device has disconnected from us.
2023-11-30 11:54:09.7980 4.12.0 4190 BlueToothTransmitter Will try to reconnect
2023-11-30 11:54:09.8060 4.12.0 4190 CGMG5 in sendGlucoseDataToDelegate
2023-11-30 11:54:09.8110 4.12.0 4190 CGMG5 glucoseDataArray has no values
2023-11-30 11:54:10.3060 4.12.0 4190 CGMG5 connected to peripheral with name DexcomTS, but last reading was less than 2.1 minute ago, will let the connection timeout
2023-11-30 11:54:25.0260 4.12.0 4190 BlueToothTransmitter didDisconnect peripheral with name DexcomTS
2023-11-30 11:54:25.0320 4.12.0 4190 BluetoothPeripheralManager in didDisconnectFrom
2023-11-30 11:54:25.0370 4.12.0 4190 BlueToothTransmitter error: The specified device has disconnected from us.
2023-11-30 11:54:25.0430 4.12.0 4190 BlueToothTransmitter Will try to reconnect
2023-11-30 11:54:25.0500 4.12.0 4190 CGMG5 in sendGlucoseDataToDelegate
2023-11-30 11:54:25.0520 4.12.0 4190 CGMG5 glucoseDataArray has no values
2023-11-30 11:54:25.6060 4.12.0 4190 BlueToothTransmitter connected to peripheral with name DexcomTS
2023-11-30 11:54:25.7480 4.12.0 4190 BlueToothTransmitter didDiscoverServices for peripheral with name DexcomTS
2023-11-30 11:54:25.7520 4.12.0 4190 BlueToothTransmitter Call discovercharacteristics for service with uuid F8083532-849E-531C-C594-30F1F86A4EA5
2023-11-30 11:54:25.7560 4.12.0 4190 CGMG5 didDiscoverCharacteristicsFor
2023-11-30 11:54:25.7590 4.12.0 4190 CGMG5 characteristic : Communication
2023-11-30 11:54:25.7610 4.12.0 4190 CGMG5 characteristic UUID unknown : F8083538-849E-531C-C594-30F1F86A4EA5
2023-11-30 11:54:25.7640 4.12.0 4190 CGMG5 characteristic : Write_Control
2023-11-30 11:54:25.7660 4.12.0 4190 CGMG5 characteristic : Receive_Authentication
2023-11-30 11:54:25.7680 4.12.0 4190 CGMG5 calling setNotifyValue true for characteristic Receive_Authentication
2023-11-30 11:54:25.7710 4.12.0 4190 CGMG5 characteristic : Backfill
2023-11-30 11:54:25.7730 4.12.0 4190 CGMG5 characteristic UUID unknown : F8083537-849E-531C-C594-30F1F86A4EA5
2023-11-30 11:54:25.8090 4.12.0 4190 CGMG5 in peripheralDidUpdateNotificationStateFor. characteristic = Receive_Authentication
2023-11-30 11:54:25.8110 4.12.0 4190 CGMG5 characteristic : Receive_Authentication
2023-11-30 11:54:25.8160 4.12.0 4190 CGMG5 sending authMessage with data 01146a7282fd9d4c0f02
2023-11-30 11:54:25.8200 4.12.0 4190 BlueToothTransmitter in writeDataToPeripheral, for peripheral with name DexcomTS, for characteristic F8083535-849E-531C-C594-30F1F86A4EA5, data = 01146a7282fd9d4c0f02
2023-11-30 11:54:25.9280 4.12.0 4190 BlueToothTransmitter in didWriteValueFor. Characteristic F8083535-849E-531C-C594-30F1F86A4EA5
2023-11-30 11:54:26.0640 4.12.0 4190 BlueToothTransmitter didDisconnect peripheral with name DexcomTS
2023-11-30 11:54:26.0670 4.12.0 4190 BluetoothPeripheralManager in didDisconnectFrom
2023-11-30 11:54:26.0690 4.12.0 4190 BlueToothTransmitter error: The specified device has disconnected from us.
2023-11-30 11:54:26.0710 4.12.0 4190 BlueToothTransmitter Will try to reconnect
2023-11-30 11:54:26.0780 4.12.0 4190 CGMG5 in sendGlucoseDataToDelegate
2023-11-30 11:54:26.0810 4.12.0 4190 CGMG5 glucoseDataArray has no values
2023-11-30 11:57:11.8910 4.12.0 4190 BlueToothTransmitter connected to peripheral with name DexcomTS
2023-11-30 11:57:11.9840 4.12.0 4190 BlueToothTransmitter didDiscoverServices for peripheral with name DexcomTS
2023-11-30 11:57:11.9880 4.12.0 4190 BlueToothTransmitter Call discovercharacteristics for service with uuid F8083532-849E-531C-C594-30F1F86A4EA5
2023-11-30 11:57:11.9930 4.12.0 4190 CGMG5 didDiscoverCharacteristicsFor
2023-11-30 11:57:11.9960 4.12.0 4190 CGMG5 characteristic : Communication
2023-11-30 11:57:11.9980 4.12.0 4190 CGMG5 characteristic UUID unknown : F8083538-849E-531C-C594-30F1F86A4EA5
2023-11-30 11:57:11.9990 4.12.0 4190 CGMG5 characteristic : Write_Control
2023-11-30 11:57:12.0020 4.12.0 4190 CGMG5 characteristic : Receive_Authentication
2023-11-30 11:57:12.0060 4.12.0 4190 CGMG5 calling setNotifyValue true for characteristic Receive_Authentication
2023-11-30 11:57:12.0100 4.12.0 4190 CGMG5 characteristic : Backfill
2023-11-30 11:57:12.0130 4.12.0 4190 CGMG5 characteristic UUID unknown : F8083537-849E-531C-C594-30F1F86A4EA5
2023-11-30 11:57:12.0700 4.12.0 4190 CGMG5 in peripheralDidUpdateNotificationStateFor. characteristic = Receive_Authentication
2023-11-30 11:57:12.0740 4.12.0 4190 CGMG5 characteristic : Receive_Authentication
2023-11-30 11:57:12.0780 4.12.0 4190 CGMG5 sending authMessage with data 01175c1ab0b20e4a7802
2023-11-30 11:57:12.0810 4.12.0 4190 BlueToothTransmitter in writeDataToPeripheral, for peripheral with name DexcomTS, for characteristic F8083535-849E-531C-C594-30F1F86A4EA5, data = 01175c1ab0b20e4a7802
2023-11-30 11:57:12.1300 4.12.0 4190 BlueToothTransmitter in didWriteValueFor. Characteristic F8083535-849E-531C-C594-30F1F86A4EA5
2023-11-30 11:57:12.1320 4.12.0 4190 BlueToothTransmitter in peripheralDidUpdateValueFor, data = 037b70caf21993d9bd6da888f17ebf29c3
2023-11-30 11:57:12.1340 4.12.0 4190 CGMG5 in peripheralDidUpdateValueFor, characteristic uuid = Receive_Authentication
2023-11-30 11:57:12.1350 4.12.0 4190 CGMG5 opcode = authRequestRx
2023-11-30 11:57:12.1390 4.12.0 4190 CGMG5 sending authChallengeTxMessage with data 048aa9c577423dedca
2023-11-30 11:57:12.1410 4.12.0 4190 BlueToothTransmitter in writeDataToPeripheral, for peripheral with name DexcomTS, for characteristic F8083535-849E-531C-C594-30F1F86A4EA5, data = 048aa9c577423dedca
2023-11-30 11:57:12.1900 4.12.0 4190 BlueToothTransmitter in didWriteValueFor. Characteristic F8083535-849E-531C-C594-30F1F86A4EA5
2023-11-30 11:57:12.1930 4.12.0 4190 BlueToothTransmitter in peripheralDidUpdateValueFor, data = 050101
2023-11-30 11:57:12.1950 4.12.0 4190 CGMG5 in peripheralDidUpdateValueFor, characteristic uuid = Receive_Authentication
2023-11-30 11:57:12.1970 4.12.0 4190 CGMG5 opcode = authChallengeRx
2023-11-30 11:57:12.2000 4.12.0 4190 CGMG5 will set notifyValue for writeControlCharacteristic to true
2023-11-30 11:57:12.2020 4.12.0 4190 BlueToothTransmitter setNotifyValue, for peripheral with name DexcomTS, setting notify for characteristic F8083534-849E-531C-C594-30F1F86A4EA5, to true
2023-11-30 11:57:12.2040 4.12.0 4190 CGMG5 will set notifyValue for backfillCharacteristic to true
2023-11-30 11:57:12.2070 4.12.0 4190 BlueToothTransmitter setNotifyValue, for peripheral with name DexcomTS, setting notify for characteristic F8083536-849E-531C-C594-30F1F86A4EA5, to true
2023-11-30 11:57:12.2500 4.12.0 4190 CGMG5 in peripheralDidUpdateNotificationStateFor. characteristic = Write_Control
2023-11-30 11:57:12.2530 4.12.0 4190 CGMG5 characteristic : Write_Control
2023-11-30 11:57:12.2560 4.12.0 4190 CGMG5 start of firefly flow
2023-11-30 11:57:12.2610 4.12.0 4190 CGMG5 sending glucoseDataTxMessage with data 305336
2023-11-30 11:57:12.2640 4.12.0 4190 BlueToothTransmitter in writeDataToPeripheral, for peripheral with name DexcomTS, for characteristic F8083534-849E-531C-C594-30F1F86A4EA5, data = 305336
2023-11-30 11:57:12.2670 4.12.0 4190 CGMG5 in fireflyMessageFlow, did send glucoseTxMessage, setting glucoseTxSent to true
2023-11-30 11:57:12.3100 4.12.0 4190 CGMG5 in peripheralDidUpdateNotificationStateFor. characteristic = Backfill
2023-11-30 11:57:12.3130 4.12.0 4190 CGMG5 characteristic : Backfill
2023-11-30 11:57:12.3700 4.12.0 4190 BlueToothTransmitter in didWriteValueFor. Characteristic F8083534-849E-531C-C594-30F1F86A4EA5
2023-11-30 11:57:12.3740 4.12.0 4190 BlueToothTransmitter in peripheralDidUpdateValueFor, data = 31005007000050a808009e0006093a2c
2023-11-30 11:57:12.3760 4.12.0 4190 CGMG5 in peripheralDidUpdateValueFor, characteristic uuid = Write_Control
2023-11-30 11:57:12.3790 4.12.0 4190 CGMG5 opcode = glucoseRx
2023-11-30 11:57:12.3830 4.12.0 4190 CGMG5 in processGlucoseDataRxMessage, received glucoseDataRxMessage, value = 158.0, algorithm status = OK / Calibrated, transmitter status = 0
2023-11-30 11:57:12.3890 4.12.0 4190 CGMG5 start of firefly flow
2023-11-30 11:57:12.3910 4.12.0 4190 CGMG5 end of firefly flow
2023-11-30 11:57:12.3930 4.12.0 4190 CGMG5 will disconnect
2023-11-30 11:57:12.3950 4.12.0 4190 BlueToothTransmitter in disconnect, disconnecting, for peripheral with name DexcomTS
2023-11-30 11:57:12.4010 4.12.0 4190 BlueToothTransmitter didDisconnect peripheral with name DexcomTS
2023-11-30 11:57:12.4040 4.12.0 4190 BluetoothPeripheralManager in didDisconnectFrom
2023-11-30 11:57:12.4070 4.12.0 4190 BlueToothTransmitter Will try to reconnect
2023-11-30 11:57:12.4130 4.12.0 4190 CGMG5 in sendGlucoseDataToDelegate
2023-11-30 11:57:12.4210 4.12.0 4190 CGMG5 adding glucose data that was received in GlucoseDataRxMessage/DexcomG6GlucoseDataRxMessage, value = 158.0, date = 11:57:12 CET
2023-11-30 11:57:12.4230 4.12.0 4190 CGMG5 calling cgmTransmitterInfoReceived with 1 values
2023-11-30 11:57:12.4270 4.12.0 4190 RootView transmitterBatteryInfo not received
2023-11-30 11:57:12.4290 4.12.0 4190 RootView sensor time in days not received
2023-11-30 11:57:12.4310 4.12.0 4190 RootView glucoseData size = 1
2023-11-30 11:57:12.4360 4.12.0 4190 RootView glucoseData 0, value = 158.0, timestamp = 11:57:12 CET
2023-11-30 11:57:12.4400 4.12.0 4190 RootView calibrator = NoCalibrator
2023-11-30 11:57:12.4690 4.12.0 4190 RootView timeStampToDelete = 11:36:12 CET
2023-11-30 11:57:13.3340 4.12.0 4190 RootView new reading created, timestamp = donderdag 30 november 2023 om 11:57:12 Midden-Europese standaardtijd, calculatedValue = 158,0
2023-11-30 11:57:14.6890 4.12.0 4190 CGMG5 connected to peripheral with name DexcomTS, but last reading was less than 2.1 minute ago, will let the connection timeout
2023-11-30 11:57:22.3450 4.12.0 4190 BlueToothTransmitter didDisconnect peripheral with name DexcomTS
2023-11-30 11:57:22.3620 4.12.0 4190 BluetoothPeripheralManager in didDisconnectFrom
2023-11-30 11:57:22.3770 4.12.0 4190 BlueToothTransmitter error: The specified device has disconnected from us.
2023-11-30 11:57:22.3810 4.12.0 4190 BlueToothTransmitter Will try to reconnect
2023-11-30 11:57:22.4270 4.12.0 4190 CGMG5 in sendGlucoseDataToDelegate
2023-11-30 11:57:22.4370 4.12.0 4190 CGMG5 glucoseDataArray has no values
2023-11-30 11:57:22.9090 4.12.0 4190 CGMG5 connected to peripheral with name DexcomTS, but last reading was less than 2.1 minute ago, will let the connection timeout
2023-11-30 11:57:37.6950 4.12.0 4190 BlueToothTransmitter didDisconnect peripheral with name DexcomTS
2023-11-30 11:57:37.7020 4.12.0 4190 BluetoothPeripheralManager in didDisconnectFrom
2023-11-30 11:57:37.7220 4.12.0 4190 BlueToothTransmitter error: The specified device has disconnected from us.
2023-11-30 11:57:37.7240 4.12.0 4190 BlueToothTransmitter Will try to reconnect
2023-11-30 11:57:37.7290 4.12.0 4190 CGMG5 in sendGlucoseDataToDelegate
2023-11-30 11:57:37.7320 4.12.0 4190 CGMG5 glucoseDataArray has no values
2023-11-30 11:57:38.2410 4.12.0 4190 CGMG5 connected to peripheral with name DexcomTS, but last reading was less than 2.1 minute ago, will let the connection timeout
2023-11-30 11:57:52.9980 4.12.0 4190 BlueToothTransmitter didDisconnect peripheral with name DexcomTS
2023-11-30 11:57:53.0060 4.12.0 4190 BluetoothPeripheralManager in didDisconnectFrom
2023-11-30 11:57:53.0220 4.12.0 4190 BlueToothTransmitter error: The specified device has disconnected from us.
2023-11-30 11:57:53.0250 4.12.0 4190 BlueToothTransmitter Will try to reconnect
2023-11-30 11:57:53.0300 4.12.0 4190 CGMG5 in sendGlucoseDataToDelegate
2023-11-30 11:57:53.0340 4.12.0 4190 CGMG5 glucoseDataArray has no values
2023-11-30 11:57:53.5120 4.12.0 4190 CGMG5 connected to peripheral with name DexcomTS, but last reading was less than 2.1 minute ago, will let the connection timeout
2023-11-30 11:58:08.3560 4.12.0 4190 BlueToothTransmitter didDisconnect peripheral with name DexcomTS
2023-11-30 11:58:08.3800 4.12.0 4190 BluetoothPeripheralManager in didDisconnectFrom
2023-11-30 11:58:08.7320 4.12.0 4190 BlueToothTransmitter error: The specified device has disconnected from us.
2023-11-30 11:58:09.0170 4.12.0 4190 BlueToothTransmitter Will try to reconnect
2023-11-30 11:58:09.0740 4.12.0 4190 CGMG5 in sendGlucoseDataToDelegate
2023-11-30 11:58:09.1490 4.12.0 4190 CGMG5 glucoseDataArray has no values
2023-11-30 11:58:09.6680 4.12.0 4190 CGMG5 connected to peripheral with name DexcomTS, but last reading was less than 2.1 minute ago, will let the connection timeout
2023-11-30 11:58:25.1470 4.12.0 4190 BlueToothTransmitter didDisconnect peripheral with name DexcomTS
2023-11-30 11:58:25.4450 4.12.0 4190 BluetoothPeripheralManager in didDisconnectFrom
2023-11-30 11:58:26.4810 4.12.0 4190 BlueToothTransmitter error: The specified device has disconnected from us.
2023-11-30 11:58:26.4940 4.12.0 4190 BlueToothTransmitter Will try to reconnect
2023-11-30 11:58:26.8530 4.12.0 4190 CGMG5 in sendGlucoseDataToDelegate
2023-11-30 11:58:27.0280 4.12.0 4190 CGMG5 glucoseDataArray has no values
2023-11-30 12:02:12.5240 4.12.0 4190 BlueToothTransmitter connected to peripheral with name DexcomTS
2023-11-30 12:02:12.5830 4.12.0 4190 BlueToothTransmitter didDiscoverServices for peripheral with name DexcomTS
etc. etc.

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.

@JohanDegraeve
Copy link
Owner

this is reported already long time ago, with Dexcom G5 and Spike. xDrip4iOS works in the same way as Spike, except that it doesn't use the sound system to avoid that the app gets suspended

When this was reported for Spike, I did some tests where I would not explicitly disconnect, but let the Dexcom time out the connection, to see if that changed anything in the 'battery drain' (which I never experienced by the way, but I never used the Dexcom official app so I couldn't really compare).
you could try to comment out this line https://github.com/JohanDegraeve/xdripswift/blob/master/xdrip/BluetoothTransmitter/CGM/Dexcom/G5/CGMG5Transmitter.swift#L1676 and 'see' if that helps. I tried that with Spike but couldn't notice any difference and I remember this was tested by other people also.

"the problem lies with xDrip4iOS attempting to reconnect to the transmitter without an apparent reason."
=> xDrip4iOS must try to reconnect after a disconnect, no matter the cause of the disconnect. Otherwise it would never be able to reconnect. You could set a timer eg of 4 minutes after which you try to reconnect. But as you probably now timers don't work for apps in the background except if you play some kind of a sound every 5 seconds which keep the app alive (I think you know what I mean).

"_However, as xDrip4iOS then blocks the connection because "last connection was less than x seconds ago": the transmitter doesn't get anything from us.__"
That's not correct. In this case (ie reconnect less than 2.1 minutes after the last reading), the xDrip4iOS connects and doesn't disconnect. It let's the Dexcom do the timeout. You can see this here : https://github.com/JohanDegraeve/xdripswift/blob/master/xdrip/BluetoothTransmitter/CGM/Dexcom/G5/CGMG5Transmitter.swift#L691
You see this also in the logs at 2023-11-30 11:52:23.3290
Dexcom itself is disconnecting at 2023-11-30 11:52:38. That's 15 seconds later. It's the Dexcom that takes the initiative to disconnect. xDrip4iOS must try to reconnect.. this goes on for a while. With Dexcom G5 this was only for about 10 seconds if I remember well. For the newer Dexcom's it goes on longer.
Do I understand correctly that this goes on for ever? in that case not only the battery of the Dexcom is draining but also xDrip4iOS battery. What is the battery decrease of your iPhone if you sleep with it uncharged? (I mean no other usage). It should only be about 20 to 30% even if you're running xDrip4iOS, Loop and maybe even the official Dexcom app in parallel and if you sleep a normal night say 8 hours.

"but another part of the code thinks its by error and tries to reconnect"
that's not an error, it's by design. It's indeed another piece of code : https://github.com/JohanDegraeve/xdripswift/blob/master/xdrip/BluetoothTransmitter/Generic/BluetoothTransmitter.swift#L439

This code is generic for all types of bluetoothtransmitters (Libre 2, MiaoMiao, Dexcom, M5Stack, ..).
It may look strange that xDrip4iOS explicitly disconnects, knowing that the other part of the code will immediately try to reconnect, and that's probably not necessary. But even if you remove that disconnect, Dexcom will timeout after 15 seconds, and it will immediately reconnect. That's the behaviour of Dexcom.

"'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.)"
I think you want to say that xDrip4iOS needs a way to avoid that it get's suspended by iOS (here an explanation of suspended state : https://developer.apple.com/documentation/watchkit/life_cycles/handling_common_state_transitions)
The only way to achieve this is the sound system (ie playing a non -hearable sound of a few milliseconds every 2 to 5 seconds)
No way that Loop and official Dexcom app are using such mechanism. (I don't know about iAPS, iAPS was originally freeaps, freeaps has the word 'free' which I interpret as 'I do what I want', however I actually don't believe iAPS is doing it differently than all the other apps)

Interesting to read this :
https://developer.apple.com/library/archive/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/CoreBluetoothBackgroundProcessingForIOSApps/PerformingTasksWhileYourAppIsInTheBackground.html#//apple_ref/doc/uid/TP40013257-CH7-SW1

anyway that all doesn't solve the battery drain problem if xDrip4iOS is used with Dexcom, if it exists. I actually also think that it's not correctly developed, the disconnect/reconnect loops should be avoided. I tried to understand how Loop does it but it's quite difficult code to reverse engineer.

@joshbohmer
Copy link

"will timeout after 15 seconds, and it will immediately reconnect. That's the behaviour of Dexcom."

I think the problem is G6 needs to stay awake for a period of time (15 seconds) after the last disconnect in case a 2nd device needs to connect. Because xDrip4iOS immediately initiates a reconnect this timer constantly gets reset which prevents the nrf52 from entering sleep mode. It seems to have a 2 minute hard limit also, whereby it forcibly enters sleep if it's hasn't been able

As a test... if we introduce a 20s delay in the disconnect -> reconnect loop that should give G6 enough time to sleep correctly.

I can confirm the Dexcom battery drain issue is a thing. With Anubis we're seeing a very regular 60 day battery problem exclusively with xDrip4iOS.

@JohanDegraeve
Copy link
Owner

JohanDegraeve commented Jan 9, 2024

I can confirm the Dexcom battery drain issue is a thing. With Anubis we're seeing a very regular 60 day battery problem exclusively with xDrip4iOS.

with which app do you not see this problem? Do you use the official Dexcom app with Anubis?

@JohanDegraeve
Copy link
Owner

JohanDegraeve commented Jan 9, 2024

As a test... if we introduce a 20s delay in the disconnect -> reconnect loop that should give G6 enough time to sleep correctly.

did you test that with xDrip4iOS while running in the background and if so, it does reconnect successfully 4minutes and 4 seconds later? (meaning when Dex has a new reading). If that works that could be the solution

@JohanDegraeve
Copy link
Owner

I think the problem is G6 needs to stay awake for a period of time (15 seconds) after the last disconnect in case a 2nd device needs to connect.

Indeed, that's why Dexcom is different than other devices like Libre and MM or Bubble, those devices stay connected

@joshbohmer
Copy link

I can confirm the Dexcom battery drain issue is a thing. With Anubis we're seeing a very regular 60 day battery problem exclusively with xDrip4iOS.

with which app do you not see this problem? Do you use the official Dexcom app with Anubis?

All of them. I do the Anubis transmitters and support 1000's of users (iOS & Android) through that work

@JohanDegraeve
Copy link
Owner

All of them

what is all of them? is there another open source ios app that you use for that (other than Loop)

@joshbohmer
Copy link

All of them

what is all of them? is there another open source ios app that you use for that (other than Loop)

What I mean is across ALL Anubis users, which include all Official & Open Source apps.

Since we warranty Anubis exactly like Dexcom out to 100 days, when a battery dies early we hear about it. In almost every case that happens, it's been activated around 60 days and xDrip4iOS/Shuggah was used. Every other app lasts to 200+ days.

@JohanDegraeve
Copy link
Owner

I plan to switch to Dexcom (the real Dexcom) (Libre 3 is awful) in the coming 2 weeks, I'll try out the 20 second delay.
But I think adding a delay of 20 second before trying to reconnect will simple put xDrip4iOS to sleep (app will be suspended by iOS) and it will not be woken up as timers will not be fired.
That's why it would be interesting to see how other apps are doing this. Problem is Loop is so complex that I don't succeed to figure out how they do it. That's why I was wondering if you have another open source app.

@LiroyvH
Copy link
Contributor Author

LiroyvH commented Jan 9, 2024

Hi Johan,

First of all - thanks for taking the time to look in to this elaborately, much appreciated. :) And congratulations on moving to a proper CGM. (Sorry, couldn't resist. :P) Why not use the Anubis? Has some nice extra convenience features! :)
Also thanks to @joshbohmer for weighing in.

Just to note: I can confirm that the Dexcom battery drain/connection loops only occur with xDrip4iOS. It does not occur on the official Dexcom app (iOS) nor can I get it to that state on Android with xDrip+. It's something specifically with the instant reconnection. But what's the mindf- for me is that it doesn't always happen. (However, looking at my logs: it does happen far more often than I initially thought.) Amanda Vanosdol has mentioned that she(/her clients) has also seen the problem with xDrip4iOS + rebatteried Dexcom G5's - which seems to make sense when I read your explanation that the foundation is the same for all those transmitters. :)

xDrip4iOS must try to reconnect after a disconnect, no matter the cause of the disconnect. Otherwise it would never be able to reconnect. You could set a timer eg of 4 minutes after which you try to reconnect. But as you probably now timers don't work for apps in the background except if you play some kind of a sound every 5 seconds which keep the app alive (I think you know what I mean).

If I understand correctly, it could work like that when using the Background Modes as described in the link you provided: https://developer.apple.com/library/archive/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/CoreBluetoothBackgroundProcessingForIOSApps/PerformingTasksWhileYourAppIsInTheBackground.html.

Currently, xDrip4iOS doesn't implement this as far as I can see. I think refactoring it to leverage these modes may also solve the issue where xDrip4iOS won't always restore itself until the user manually opens it up again when the app had become unloaded because of memory constraints. (Whilst that's another story than the battery drain, may be worth mentioning why it might be a bonus: Currently, if the app is unloaded due to memory constraints whilst it seemingly hasn't started asking iOS to connect again: we never connect anymore (as described in the introduction of that article). So this could perhaps solve two problems at once?

Now this is anecdotal as N=1, but I'm one of the people that frequently get's hit with this issue as I use the phone camera a lot which slurps resources that my 13 Mini simply doesn't have. But: iAPS, the official Dexcom app and Loop all are restored within +/- 5 minutes; even if the app clearly got killed. The only app that won't always wake back up unless it's manually opened again for me is xDrip4iOS - even in master mode. I think it's related to this, as the only difference I was able to find is all those app employ background refresh modes whereas xDrip4iOS doesn't do that.)

It's the Dexcom that takes the initiative to disconnect.

Ah I thought we did by sending 0x09 + CRC16 (disconnectTx) as defined in https://github.com/JohanDegraeve/xdripswift/blob/master/xdrip/BluetoothTransmitter/CGM/Dexcom/Generic/DexcomTransmitterOpCode.swift#L22 However, running a quick search on the codebase: we don't use that. I've asked @joshbohmer about that, but it seems it's not really relevant to the problem at hand.

xDrip4iOS must try to reconnect.. this goes on for a while. With Dexcom G5 this was only for about 10 seconds if I remember well. For the newer Dexcom's it goes on longer.
Do I understand correctly that this goes on for ever? in that case not only the battery of the Dexcom is draining but also xDrip4iOS battery.

Yes, what seems to happen is when we attempt to reconnect: we do so instantly after disconnect. But doing that will be in the window @joshbohmer described wherein the Dexcom is still listening for other devices. (Further info: Dexcom has two device slots, only one can connect at the same time. So when "we" disconnect, it stays active for a bit to wait for another device to connect. Instead, we connect again. The slot isn't chosen until after the connection has been established, so the Dexcom can't "stop listening on that slot" either; it's just open for connection.)

This goes on for about 2 minutes (see logs, though if you want I have far more extensive logs of these occurrences) I think and then the Dexcom gives up and stops phoning in. Probably the hard-limit guardrail within the Dexcom that Joshua described above.

But even if you remove that disconnect, Dexcom will timeout after 15 seconds, and it will immediately reconnect. That's the behaviour of Dexcom.

I think we're causing that behavior as also mentioned by Joshua. We ask iOS to immediately reconnect to the Dexcom. But as the Dexcom can still be listening at that moment: it actually does reconnect. This then triggers xDrip4iOS to be woken up again, if it even got suspended at all, and then we start ignoring the transmitter. The transmitter gives up after 10 seconds, but what happens next is xDrip4iOS will then once again tell iOS to connect to it again. As the Dexcom is still awake, it once more obliges and connects to us and is once more frustrated by not hearing anything from us for 10 seconds. It disconnects again, but we ask....... and so on and on. :P Until finally after 2 minutes or so, the Dexcom is sick of the annoying kids prank calling him and stops listening entirely. As I'm sure Dexcom isn't the only BLE-device listening in this way, I can't escape the notion that - especially after reading that doc you linked - iOS has provisions for exactly that situation and we should somehow even in the background/suspended state be able to tell when iOS should reconnect (not instantly after Dexcom disconnects, but after x time has passed after that.).

I think you want to say that xDrip4iOS needs a way to avoid that it get's suspended by iOS (here an explanation of suspended state : https://developer.apple.com/documentation/watchkit/life_cycles/handling_common_state_transitions)
The only way to achieve this is the sound system (ie playing a non -hearable sound of a few milliseconds every 2 to 5 seconds)

No, sorry. I should've been specific. I meant the Background Refresh modes that are employed by Loop, iAPS, Dexcom official, etc. They implement background modes described in the Developers docs you linked and I repeated above. Specifically, the UIBackgroundModes used by those apps are:

bluetooth-central
bluetooth-peripheral
processing

Which helps with controlling BLE connections in the background (even if suspended) and waking up even after having been killed entirely to free up resources required elsewhere.

It's my theory, but as you know I'm not a coder and am just theorizing based on what I see xDrip does and what documentation says (plus some help from @joshbohmer), that this would
a.) offer a way for xDrip4iOS to solve the reconnection problem as we can probably make iOS wait X seconds before actually attempting to connect again without the need to do anything "illegal",
b.) increase performance: less battery drain on the phone and Dexcom transmitters if these loops never occur.
c.) increase stability: heavy apps hogging up resources will cause less trouble and the app will recover more easily.

At least, I hope so. But I'm going farrrrrrr beyond what is my comfort zone in terms of coding (and that zone is very very small :P) and handling BLE-devices, so maybe it's all BS. But I like to think it sounds logical and feasible based on the developer documentation and observing the behavior of xDrip4iOS and other apps communicating with BLE devices. :P

Greetings! :) Enjoy the cold weather... :/ It's snowing here.

@JohanDegraeve
Copy link
Owner

well I won't reply it all.
It's funny to see all apps have 'back ground processing' enabled while xDrip4iOS has not :)

If I go to my iOS settings (background refresh, in Dutch "ververs op achtergrond") i have about 20 apps where I can enable background refresh, but I've disabled them all, and all apps keep working.

Libre 2 and 3 also don't use that setting by the way (you will not find it in the list)
One exception is LibreLinkUp : that app needs background refresh enabled because a remote server is sending push notifications to the app, asking the app to wake up. Which is exactly what it's used for.
Try it out and go through those iOS settings, refresh background, disable it for all your apps ...

There's also a lot of misunderstanding about apps behaviour in the background. Apps don't get 'unloaded' because of memory constraints. Apps that go to the background (because you lock your phone or press the home button or open another app), and that have nothing else to do (like playing music or tracking your location with gps or ongoing communication with a BLE device), they will be pushed by iOS to 'suspend' mode within seconds.
In case of all those bluetooth apps (dexcom, libre, xdrip, ...) : they will be rewoken up as soon as the device either disconnects, connects, or sends data. There's a prerequisite for that, the app must really tell to iOS that it wants to reconnect after a disconnect.
(Note also that Spike was an exception, Spike wasn't forced woken up by iOS in those cases. Probably because Spike is using the Adobe action script framework - that's why Spike needed two sound wake up system .. i think you know what I mean)

Also this issue was about 'battery drain' for the transmitter. Now you talk about xDrip4iOS not being able to wake up unless you bring the app to the foreground?

PS please don't reply anymore. As as long as I don't have a Dexcom transmitter and sensor I can't do anything but keep on debating. I have an appointment next week at hospital and should get the Dexcom (I don't know actually if it's G6 or G7 here in Belgium)

It's cold indeed :) but it's better than all the rain we had last months

@joshbohmer
Copy link

@JohanDegraeve I can organise to send you a couple Anubis & a G6 Sensor Simulator to help development. Sorry, I thought you already had one.

"Also, this issue was about 'battery drain' for the transmitter. Now you talk about xDrip4iOS not being able to wake up unless you bring the app to the foreground?"

What's happening is Dexcom transmitters can't enter sleep mode fast enough because of the disconnect -> reconnect loop. The transmitter stays awake for x seconds after the last disconnect to give other devices an opportunity to download data. With how xDrip4iOS handles the BLE connection, the transmitter is kept awake each 5 minute cycle for up to 2 minutes (it's hard cut off) instead of the normal ~15 seconds. This longer than normal time with the nRF52 radio active is killing batteries early

The background handling conversation is an attempted to remove the reconnect loop requirement and let the transmitter sleep the radio sooner

@LiroyvH
Copy link
Contributor Author

LiroyvH commented Jan 10, 2024

I thought you had an Anubis + sensor simulator? If you don't, we should get them to you as they make playing around with it farrrrrr easier and ensure no sensors are wasted. (The simulator can also be used with Dexcom ONE transmitters.)
-edit- Ha, ninja'd by @joshbohmer :)

Last input then: according to both Apple and Dexcom, background refresh is critical (and the behaviour of apps with it implemented or enabled rather than disabled is, on my end, definitely far more reliable). (And with "unloaded" I was referring to this statement by Apple: "At some point, the system may need to terminate your app to free up memory for the current foreground app—causing any active or pending connections to be lost, for instance." and then goes on to state how this is solved with background modes).

If you don't want to implement it: ok, it's your call. :) I think it'd be a waste not to leverage these features, but if all problems can be sorted without it: all good, that's what matters in the end. :D

Thanks in advance for fixing it! :)

P.S. the primary concern is indeed the rapid battery drain on Dexcom transmitters - that's a critical problem. The manual intervention after termination was solely mentioned as a bonus issue that might be solved.

@JohanDegraeve
Copy link
Owner

@JohanDegraeve I can organise to send you a couple Anubis & a G6 Sensor Simulator to help development. Sorry, I thought you already had one.

"Also, this issue was about 'battery drain' for the transmitter. Now you talk about xDrip4iOS not being able to wake up unless you bring the app to the foreground?"

What's happening is Dexcom transmitters can't enter sleep mode fast enough because of the disconnect -> reconnect loop. The transmitter stays awake for x seconds after the last disconnect to give other devices an opportunity to download data. With how xDrip4iOS handles the BLE connection, the transmitter is kept awake each 5 minute cycle for up to 2 minutes (it's hard cut off) instead of the normal ~15 seconds. This longer than normal time with the nRF52 radio active is killing batteries early

Yes that's probably all correct.
but the way to solve it as discussed above is not what will fix it. I mean it's not about the background processing settings.

I've seen in the Loop code (but can't find it back anymore) that they wait 2 seconds before attempting to reconnect, the comment added is very interesting https://github.com/LoopKit/G7SensorKit/blob/main/G7SensorKit/G7CGMManager/G7BluetoothManager.swift#L218
(they call it scanForPeripheral but in the end they also just reconnect to an already known device)

I had already seen this before but didn't want to implement it because I think it's very risky as iOS in the beginning it takes more seconds before it suspends the app (in the beginning I mean right after it's launched), but after a while the suspension goes faster and faster. The follower mode for xDrip4iOS works with the sound every 5 seconds and sometimes that's even too short.

I was aware about all the communication ongoing with Dexcom, and indeed with G5 it was much shorter (I think 15 seconds as you say), and G6 or G7 it's much longer. I wans't sure actually if it would drain the battery or not.

@JohanDegraeve
Copy link
Owner

I thought you had an Anubis + sensor simulator? If you don't, we should get them to you as they make playing around with it farrrrrr easier and ensure no sensors are wasted. (The simulator can also be used with Dexcom ONE transmitters.) -edit- Ha, ninja'd by @joshbohmer :)

Last input then: according to both Apple and Dexcom, background refresh is critical (and the behaviour of apps with it implemented or enabled rather than disabled is, on my end, definitely far more reliable). (And with "unloaded" I was referring to this statement by Apple: "At some point, the system may need to terminate your app to free up memory for the current foreground app—causing any active or pending connections to be lost, for instance." and then goes on to state how this is solved with background modes).

If you don't want to implement it: ok, it's your call. :) I think it'd be a waste not to leverage these features, but if all problems can be sorted without it: all good, that's what matters in the end. :D

Thanks in advance for fixing it! :)

P.S. the primary concern is indeed the rapid battery drain on Dexcom transmitters - that's a critical problem. The manual intervention after termination was solely mentioned as a bonus issue that might be solved.

sure also Apple says background processing is critical?

"At some point, the system may need to terminate your app to free up memory for the current foreground app—causing any active or pending connections to be lost, for instance." and then goes on to state how this is solved with background modes).
=>can you show me where apple says "and then goes on to state how this is solved with background modes)"

There's another interesting feature that makes sure the app gets relaunched when necessary, it's this https://developer.apple.com/documentation/corebluetooth/cbcentralmanagerdelegate/1518819-centralmanager
I tested this : after 3 readings, make a divison by 0. This crashes the app, but depending on the device you're using, the app relaunches. In case of for instande MM, that's within a few milliseconds. Because due the the crash, the MM is losing connection, it immediately starts advertising again, iOS detects this and relaunches the app. In case of Libre this may take a bit longer, because Libre always needs a minute before restarting advertising. Dexcom it depends if it went to sleep or not

"definitely far more reliable"
==> it should be 100% reliable, there's nothing more than 100 :)

"I think it'd be a waste not to leverage these features"
=> they cause confusing and save work for the moderators on the Facebook group. xDrip4iOS moderators can't ask whether people have enabled the background mode in the iOS settings, because it's not there.

"I thought you had an Anubis ", sorry I may have one but can't find it back.

Actually I don't believe that all that communication has a significant impact on the battery. I think some transmitters just don't last long enough (especially Anubis?) and then developers start looking at the xDrip4iOS logs and see all that communication ongoing so you think this is the cause. It happened before with Spike also (Spike used the same mechanisms as xDrip4iOS just not the restorestate - I know background refresh was enabled in Spike but that doesn't make any difference)

@LiroyvH
Copy link
Contributor Author

LiroyvH commented Jan 13, 2024

can you show me where apple says "and then goes on to state how this is solved with background modes)"

Just continue reading the link you gave. :) It opens with the terminator quote and then goes on to explain the options to prevent it from happening. Probably the parts from "Core Bluetooth Background Execution Modes" and "The bluetooth-central Background Execution Mode" bits are most relevant and explains why it prevents the quoted scenario from occurring.

This should allow for better connection management even if the app gets suspended or even terminated. (By iOS anyway. User invoked termination is probably different.)

they cause confusing and save work for the moderators on the Facebook group.

If a handful of users randomly start flipping switches of features they shouldn’t be disabling (without checking), that’s their fault tbh. It can be noted in the docs. And it’s not like we don't have to ask them about other bad choices all day anyway; such as enabling Bluetooth on LibreLink which is located in the exact same settings as where Background Refresh would be. ;)

I think some transmitters just don't last long enough (especially Anubis?) and then developers start looking at the xDrip4iOS logs and see all that communication ongoing so you think this is the cause.

No it’s not like that at all and I’m sad to hear that you think I’d say something like this if I hadn’t properly looked in to it and hadn’t tried eliminating other potential culprits. Heck, I even tried pinning it down to older/cheaper iPhone's but then got logs sent to me from people on the 15 Pro.

Background to this problem:
Multiple people (and not just a handful) are reporting severe battery drains on their transmitters when using xDrip4iOS, myself included. These problems immediately disappear when xDrip4iOS is taken out of the equation. Whether it’s replaced with the official G6 app or xDrip+ doesn’t matter - the problem stops when xDrip4iOS isn’t used anymore and returns when xDrip4iOS is being used again.

It’s been several months of observing this behaviour between various groups of people, including the Anubis team and the Designs & Replacement team (whom are the first groups of people to detect large amounts of complaints), to establish the culprit. Subsequently, we (me and @joshbohmer) started looking in to what could be causing this problem so that a substantiated problem report could be submitted. The connection loops are a very fine candidate, because the dexcom is supposed to be awake for +/- 10-20 seconds and then go to sleep; but instead it is kept awake and keeps broadcasting for nearly 2 minutes because of xDrip4iOS. Sometimes for days on end.

Adding background refresh leveraging Apple's described framework was just a suggestion for a potential route to solve the problem btw, no idea if there are more roads that'll lead to Rome or if it's the road at all; I'm just going by what the docs say. :)

If you have another idea of what could cause the problem: ok, this was simply the best theory we could come up with. It makes sense and it’s months of looking in to it - not just some random users’ j’accuse. ;)

Maybe it isn’t xDrip4iOS, maybe it is but it’s another problem than what we found. But it cannot be denied that it’s extremely suspicious that every time these issues occur: they’re fixed when people switch away from xDrip4iOS.

And lest not forget… There were ONE users complaining about this phenomenon as well, but we dismissed it because one or two experienced it with ONE and naturally complaints ceased completely when they were all forced to let the Dexcom app take the lead as xDrip4iOS doesn’t support the new auth mechanism. Yet.

it should be 100% reliable, there's nothing more than 100 :)

In an ideal world, absolutely. But just like 100% secure, 100% reliable is an utopia for any app. However, let me put it this way: xDrip4iOS became so unreliable for me as a source for loop data, and the battery drain so high, that I was forced to abandon it and switch to the official G6 app - which has been 99.9% reliable and all battery drainage stopped. And I really really hate the official app and I really like xDrip4iOS - so it’s absolutely not a decision I took lightly, believe me. But, let's focus on the battery drain - stability is another (potentially bonus) matter.

Anyway, since I can’t possibly add any more information or arguments to this - I’ll leave it at this and hope the problem will be addressed. :)

Thanks either way for your consideration. :)

@joshbohmer
Copy link

"Actually I don't believe that all that communication has a significant impact on the battery"

One note in relation to this. The problem isn't the increased communication exactly... It's that the nRF52 can't enter low power mode while this extra comms are taking place and those extra CPU cycles (~120s vs ~15s) are what drains the battery prematurely.

During the development of Anubis I triggered a similar issue where the battery was draining faster than expected. It took me weeks of research and a power profiler to workout the cause of that battery drain problem. That fix was to resolve the low power mode also.

I'm not taking a guess at the problem here... I have explicit experience fixing this in Dexcom hardware.

@JohanDegraeve
Copy link
Owner

Intereseting : I google for "At some point, the system may need to terminate your app to free up memory for the current foreground app—causing any active or pending connections to be lost, for instance"

the first google result brings me to an issue in stackoverflow https://stackoverflow.com/questions/32563512/push-notification-app-running-in-background-when-ble-is-connected

the last answer is intereseting
image

@JohanDegraeve
Copy link
Owner

"Actually I don't believe that all that communication has a significant impact on the battery"

One note in relation to this. The problem isn't the increased communication exactly... It's that the nRF52 can't enter low power mode while this extra comms are taking place and those extra CPU cycles (~120s vs ~15s) are what drains the battery prematurely.

During the development of Anubis I triggered a similar issue where the battery was draining faster than expected. It took me weeks of research and a power profiler to workout the cause of that battery drain problem. That fix was to resolve the low power mode also.

I'm not taking a guess at the problem here... I have explicit experience fixing this in Dexcom hardware.

I wonder if there's an explicit command to put the Dex in a sleep mode.
Or is this the solution https://github.com/LoopKit/G7SensorKit/blob/main/G7SensorKit/G7CGMManager/G7BluetoothManager.swift#L224
which is delay 2 seconds before trying to reconnect
That would be strange because Dex is awake and restarts advertising for longer than 2 seconds

@JohanDegraeve
Copy link
Owner

Just continue reading the link you gave. :) It opens with the terminator quote and then goes on to explain the options to prevent it from happening. Probably the parts from "Core Bluetooth Background Execution Modes" and "The bluetooth-central Background Execution Mode" bits are most relevant and explains why it prevents the quoted scenario from occurring.

Liroy , the way it's implemented in xDrip4iOS is exactly as it's described in that Apple documentation.

@joshbohmer
Copy link

joshbohmer commented Jan 13, 2024

"Actually I don't believe that all that communication has a significant impact on the battery"
One note in relation to this. The problem isn't the increased communication exactly... It's that the nRF52 can't enter low power mode while this extra comms are taking place and those extra CPU cycles (~120s vs ~15s) are what drains the battery prematurely.
During the development of Anubis I triggered a similar issue where the battery was draining faster than expected. It took me weeks of research and a power profiler to workout the cause of that battery drain problem. That fix was to resolve the low power mode also.
I'm not taking a guess at the problem here... I have explicit experience fixing this in Dexcom hardware.

I wonder if there's an explicit command to put the Dex in a sleep mode. Or is this the solution https://github.com/LoopKit/G7SensorKit/blob/main/G7SensorKit/G7CGMManager/G7BluetoothManager.swift#L224 which is delay 2 seconds before trying to reconnect That would be strange because Dex is awake and restarts advertising for longer than 2 seconds

A sleep command would prevent other devices from retrieving data. As such there is no sleep command, only 0x09 disconnect

I'm not sure about the 2 second thread delay but it's worth a try.

@LiroyvH
Copy link
Contributor Author

LiroyvH commented Jan 22, 2024

Liroy , the way it's implemented in xDrip4iOS is exactly as it's described in that Apple documentation.

Huh? How's that possible without adding the background modes about which that Apple doc says they're mandatory for proper functioning and processing whilst suspended? oO (Honestly a genuine question and curiosity, not trying to be a pain :))

(From "Core Bluetooth Background Execution Modes" quote: "If your app needs to run in background to perform certain Bluetooth-related tasks, it must declare that it supports a Core Bluetooth background execution mode in its Information property list (Info.plist) file. When your app declares this, the system wakes it up from a suspended state to allow it to handle Bluetooth-related events. This support is important for apps that interact with Bluetooth low energy devices that deliver data at regular intervals, such as a heart rate monitor.")

I'll be happy to declare those and then give it a try if the rest of the requires foundation is already implemented if that helps? :) (Note: that'd just be to see about stability/re-launch after termination, I assume this won't fix connection loops.)

@JohanDegraeve
Copy link
Owner

"If your app needs to run in background to perform certain Bluetooth-related tasks, it must declare that it supports a Core Bluetooth background execution mode"
=> see https://github.com/JohanDegraeve/xdripswift/blob/master/xdrip/Supporting%20Files/Info.plist#L54

In the issue you started with "I'll shamelessly plug my request for full implementation of Background Processing/Activity"
well I don't know exactly what you mean but I know that some other applications are also adding "fetch" and/or "remote-notification" and/or "processing"
Loop for instance uses "remote-notification" and "processing", see https://github.com/LoopKit/Loop/blob/c6b058b4276681600979aaeba518c635f06ac135/Loop/Info.plist#L79
remote-notification is definitely not necessary (Loop is not using push notifications)
"processing" is necessary to run BGTaskScheduler tasks, Loop is using this for exporting critical event logs, see https://github.com/LoopKit/Loop/blob/c6b058b4276681600979aaeba518c635f06ac135/Loop/Managers/DeviceDataManager.swift#L1531

Please stop this discussion.

@LiroyvH
Copy link
Contributor Author

LiroyvH commented Jan 25, 2024

Yes let's focus on fixing the reconnection loops as that's currently a more prudent problem and the primary subject for this issue. I'll try working on fixing the relaunch/stability issues on my own.

@paulplant paulplant added the bug Something isn't working label Feb 13, 2024
@dnzxy
Copy link
Contributor

dnzxy commented Feb 26, 2024

Since we warranty Anubis exactly like Dexcom out to 100 days, when a battery dies early we hear about it. In almost every case that happens, it's been activated around 60 days and xDrip4iOS/Shuggah was used. Every other app lasts to 200+ days.

No it’s not like that at all and I’m sad to hear that you think I’d say something like this if I hadn’t properly looked in to it and hadn’t tried eliminating other potential culprits. Heck, I even tried pinning it down to older/cheaper iPhone's but then got logs sent to me from people on the 15 Pro.

Just want to comment there to chime in and second this comment by @joshbohmer and @LiroyvH Had 2 Anubis as well as a stock G6 TX die prematurely while using xDrip4iOS. I was one of the people providing logs to Liroy from an old iPhone as well as an iPhone 15 Pro.

My last TX that died early after not even 60 days (57 days IIRC) was an Anubis, so I turned to the Anubis FB group and learned battery drainage and prematurely drained batteries are a known issue associated with xDiOS. When using the stock G6 app with either Anubis or stock G6 TX this does not happen.

@JohanDegraeve
Copy link
Owner

@dnzxy can you build the app in xcode? I could make a change and then you could test to see if it improves. Needs to be tested for longer period.

@dnzxy
Copy link
Contributor

dnzxy commented Feb 26, 2024

@JohanDegraeve I can build with Xcode or via fastlane, patch-based, branch-based, however you’d like. I will be out of country next week until the week after and will be switching to a fresh Anubis (re-battery’d) this week, so I could read battery voltage before and then after or during. How long does this test need to run for? Would you like to connect on Discord or somewhere else?

@JohanDegraeve
Copy link
Owner

Here's the branch to test https://github.com/JohanDegraeve/xdripswift/commits/issue494/

First thing would be to see if that solves the connect loops.

It would also be useful to start with a shorter value for delayInSeconds, if you set this to 1.0 295b64b#diff-92e251c9866fabfbf175d735eb29d37cf187f760453fc7765a7948d38f0ce689R292

If it does solve the loops : install it and use it for a longer period (days, weeks, months). I expect that UI will not respond every 5 minutes for about 1-2 seconds. If that's experienced as an issue we could find another way to introduce this delay.
We also need to see if the app remains stable, ie keeps on running for ever.

If 1 seconds doesn't solve it try with 2 seconds. Longer waiting period is probably not a good idea because there's a change that iOS will crash the app.

And then off course to see if that solves the battery drain issue. Only people who experienced the drain will be able to test that.

@JohanDegraeve
Copy link
Owner

Would you like to connect on Discord or somewhere else?
Let's continue here for the moment. But don't add logs here. If needed send logs to [email protected] but I think you can already analyse the logs yourself also?

@bjornoleh
Copy link
Contributor

I briefely tested setting delayInSeconds to 1 second. The app still works. Will monitor if the frequency of "Will try to reconnect" in logs change compared to having delayInSeconds set to 2 seconds.

@JohanDegraeve
Copy link
Owner

this looks very good actually. The 2 seconds give the Dex time to go to sleep.

@bjornoleh
Copy link
Contributor

Looks like delayInSeconds = 1 second doesn't quite do the trick, there are more "Will try to reconnect" than once every five minutes in this little sample:

2024-03-22 00:00:51.6910 5.0.2 4193 BlueToothTransmitter               Will try to reconnect
2024-03-22 00:01:08.0530 5.0.2 4193 BlueToothTransmitter               Will try to reconnect
2024-03-22 00:05:51.5960 5.0.2 4193 BlueToothTransmitter               Will try to reconnect
2024-03-22 00:06:07.8980 5.0.2 4193 BlueToothTransmitter               Will try to reconnect
2024-03-22 00:10:50.8330 5.0.2 4193 BlueToothTransmitter               Will try to reconnect
2024-03-22 00:15:54.2920 5.0.2 4193 BlueToothTransmitter               Will try to reconnect

@JohanDegraeve
Copy link
Owner

interesting

@bjornoleh
Copy link
Contributor

interesting

This was a very short test with 1 second, so someone might want to test this again to confirm if 1 second is too little.

I am now starting to use the patch with 2 seconds for longer term testing on our looping phones.

@bjornoleh
Copy link
Contributor

That was a short test, someone else might want to confirm if 1 sec is too little. We are starting to use 2 seconds for longer term testing now.

For other testers, the logs can be sent to oneself by email from the “Send Issue Report” feature. To see relevant logs in Xcode, toggle on OSLog first. Timestamps can be displayed by a setting in the bottom of the debug window.

image

develop...issue494

@paulplant
Copy link
Collaborator

Nice job on this one 👏

@bjornoleh
Copy link
Contributor

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.

@JohanDegraeve
Copy link
Owner

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

@bjornoleh
Copy link
Contributor

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.

@JohanDegraeve
Copy link
Owner

ok clear

@paulplant
Copy link
Collaborator

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.

@bjornoleh
Copy link
Contributor

Thanks, @paulplant that’s great, I thought the regression was introduced here, I had not previously tested recent dev.

@paulplant
Copy link
Collaborator

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

@paulplant paulplant added the question Further information is requested label Mar 29, 2024
@LiroyvH
Copy link
Contributor Author

LiroyvH commented Apr 3, 2024

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.

@bjornoleh
Copy link
Contributor

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.

@LiroyvH
Copy link
Contributor Author

LiroyvH commented Apr 4, 2024

@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. :(

@bjornoleh
Copy link
Contributor

bjornoleh commented Apr 4, 2024

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
Copy link
Owner

@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 :)

@LiroyvH
Copy link
Contributor Author

LiroyvH commented Apr 7, 2024

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

@JohanDegraeve
Copy link
Owner

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)

@LiroyvH
Copy link
Contributor Author

LiroyvH commented Apr 7, 2024

@JohanDegraeve Thanks! Like so? LiroyvH/xdripswift@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:

  • Value of optional type 'CBCharacteristic?' must be unwrapped to a value of type 'CBCharacteristic'
  • Coalesce using '??' to provide a default when the optional value contains 'nil'
  • Force-unwrap using '!' to abort execution if the optional value contains 'nil'

@JohanDegraeve
Copy link
Owner

ok, this should avoid the error

if let writeControlCharacteristic = writeControlCharacteristic {
_ = writeDataToPeripheral(data: Data(for: .disconnectTx), characteristicToWriteTo: writeControlCharacteristic, type: .withResponse)
}

@LiroyvH
Copy link
Contributor Author

LiroyvH commented Apr 7, 2024

@JohanDegraeve Yep, that made it built OK! Built and fingers crossed. :)

@LiroyvH
Copy link
Contributor Author

LiroyvH commented Apr 7, 2024

@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

@JohanDegraeve
Copy link
Owner

Oh well, it would've been really nice if it was this simple. :D
indeed

@swright87
Copy link

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.

@LiroyvH
Copy link
Contributor Author

LiroyvH commented Aug 5, 2024

@swright87 No progress as far as I'm aware.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

7 participants