AndroidAPS icon indicating copy to clipboard operation
AndroidAPS copied to clipboard

No connection to Insight with AAPS 3.3.1.3

Open kneuZ opened this issue 11 months ago • 24 comments

Hello,

I can no longer connect to my Accu Check Insight insulin pump with version 3.3.1.3. It makes no difference whether I do an update or a complete reinstallation.

I find the pump during the pairing process, but when I select it nothing happens or the message “Connection failed” appears.

With version 3.2.0.2 the connection works without any problems.

My smartphone is a Xiaomi Redmi Note 9 pro with Adroid 12. All authorizations have been set and the energy-saving measures have been deactivated.

I have attached a log file from the “Pump Control” version.

AndroidAPS.log

Image Image Image

kneuZ avatar Feb 22 '25 12:02 kneuZ

@Philoul

MilosKozak avatar Feb 22 '25 14:02 MilosKozak

Within pump UI If you go to device settings, communication. list of connected devices (don't know menu names in your language, mine is in french 😉). Do you have one or several devices recorded?

If yes remove them, and try pairing a new device.

  • most of the time pairing works on first trial, but from time to time you have to try 2 or 3 times.

Philoul avatar Feb 22 '25 16:02 Philoul

in our case we needed to install the mysugr app and pair via that app first. We keep the BT connection via mysugr app and then pair in AndroidAPS.

KelvinKramp avatar Feb 22 '25 17:02 KelvinKramp

in our case we needed to install the mysugr app and pair via that app first. We keep the BT connection via mysugr app and then pair in AndroidAPS.

I don't understand, AFAIK you cannot have several app connected to your pump at the same time but only one...

Can you remove pairing with mysugr app and then try again pairing with AAPS and verify if it works correctly ?

Philoul avatar Feb 22 '25 18:02 Philoul

Within pump UI If you go to device settings, communication. list of connected devices (don't know menu names in your language, mine is in french 😉). Do you have one or several devices recorded?

If yes remove them, and try pairing a new device.

* most of the time pairing works on first trial, but from time to time you have to try 2 or 3 times.

I have deleted all connected devices in my pump. I have tried very often to pair the devices, unfortunately without success.

I have also just tried with the mysugr app, also without success.

So I have deleted the connection in my cell phone and in the pump, I get the pump displayed for pairing but no connection is established. In the old version it works without any problems.

When I update the AAPS to version 3.3.1.3 with a paired pump, I only get a time out under the new version.

kneuZ avatar Feb 22 '25 18:02 kneuZ

When I update the AAPS to version 3.3.1.3 with a paired pump, I only get a time out under the new version.

Very strange, update from 3.2 to 3.3 should keep the settings and the pairing... So an Insight pump paired and working with AAPS 3.2 should continue to work directly after the update of AAPS in 3.3 (without pairing again your pump).

Do you have another phone to test if pairing issue is the same?

Another possible test is to temporary downgrade AAPS to 3.2, pair again pump with AAPS and then upgrade to 3.3 (you will loose database, but an NSClient full sync should recover it) 🤔

@MilosKozak @TebbeUbben Do you have any ideas on how to track this issue? Unfortunatly I don't have the skills to analyse BT connection or analyse pairing process (when I managed the migration of Insight driver to kotlin, I made hundred of verification to keep communication and pairing working the same way).

Philoul avatar Feb 22 '25 19:02 Philoul

Just managed quickly on my dev conf a new pairing, in less than 20s Î saw the pump, selected it, approved the key on both sides and connection was ok.

Philoul avatar Feb 22 '25 20:02 Philoul

@Philoul your right also works without mysugrapp.

KelvinKramp avatar Feb 22 '25 23:02 KelvinKramp

my sugr app not installed (in none of my phones, loop or dev)

Philoul avatar Feb 22 '25 23:02 Philoul

I remember that A-C Insight has always supported two BT connections at the same time. For example one between pump and A-C remote controller, one between pump and Android phone. I have not tested with mySugr app.

reijoahola-nightscout avatar Feb 23 '25 07:02 reijoahola-nightscout

Insigh version in this issue seems to be 3.0. In my Insight the version is 2.01. This could cause some differences in BT pairing behaviour.

reijoahola-nightscout avatar Feb 23 '25 07:02 reijoahola-nightscout

I have now used AAPS with Insight over 4 years. I have always had some problems with BT pairing, typically it has never paired with the first try and several times is needed. A couple of times it did not succeed without special operations. The document mentions that when problems with pairing "... turn off bluetooth on pump AND smartphone for about 10 seconds and then turn it back on.". This has always solved the problem.

reijoahola-nightscout avatar Feb 23 '25 07:02 reijoahola-nightscout

Insigh version in this issue seems to be 3.0. In my Insight the version is 2.01. This could cause some differences in BT pairing behaviour.

No, pairing works with both versions, v2 and v3.

I have always had some problems with BT pairing, typically it has never paired with the first try and several times is needed.

I agree that pairing process is the most tricky part within driver. On my side I never got so bad results but efficiency of pairing process can be linked to BT implementation within phone. During driver migration in kotlin hundred of pairing has been done but only with my dev and loop phone: Android 11 for both phones (Samsung A10 and Power U20), Insight pump v2 and v3. About 90% pairing worked the 1rst time, and 10% It succeed on second trial.

... turn off bluetooth on pump AND smartphone for about 10 seconds and then turn it back on.". This has always solved the problem.

👍Good idea, on pump this can be done from menu, or just by removing battery

Philoul avatar Feb 23 '25 08:02 Philoul

Today I tried again. The pump is coupled with version 3.2.0.2. I update to Verision 3.3.1.3, the pump is still paired, but no connection is established (log attached).

Image

AndroidAPS(After Update).log

I decoupled the pump, deleted the connection in the pump and switched off the cell phone and pump for over 10 seconds. As soon as I try to pair the pump again, the message “Connection failed” appears immediately. I have also made logs of this.

AndroidAPS(New Paring).log

After the “downgrade” to version 3.2.0.2, the pairing works again immediately and without any problems.

Unfortunately, I don't have another smartphone to test. I have been using AAPS with the Insight for several years, and unfortunately the problems only started with this version.

kneuZ avatar Feb 26 '25 14:02 kneuZ

When I look within log, I find this:

15:22:14.372   [RecoveryTimer] I/PUMP: [InsightConnectionService.setState():244]: Insight   state changed: CONNECTING
--
15:22:14.379 [Thread-24] I/PUMP:   [InsightConnectionService.handleException():327]: Exception occurred:   ConnectionFailedException
15:22:14.380 [Thread-24] I/PUMP:   [InsightConnectionService.setState():244]: Insight state changed: RECOVERING
15:22:22.400 [RecoveryTimer] I/PUMP:   [InsightConnectionService.setState():244]: Insight state changed: CONNECTING
15:22:22.412 [Thread-26] I/PUMP:   [InsightConnectionService.handleException():327]: Exception occurred:   ConnectionFailedException
15:22:22.419 [Thread-26] I/PUMP:   [InsightConnectionService.setState():244]: Insight state changed: RECOVERING
15:22:26.474 [main] I/PUMP:   [InsightConnectionService.withdrawConnectionRequest():272]: Last connection   lock released, will disconnect in 5 seconds
15:22:26.479 [main] I/PUMP:   [InsightConnectionService.setState():244]: Insight state changed: NOT_PAIRED
15:24:51.228 [DefaultDispatcher-worker-1]   D/PUMP: [VirtualPumpPlugin.refreshConfiguration():405]: Pump in   configuration: Accu-Chek Combo, PumpType object: ACCU_CHEK_COMBO
15:24:51.230 [DefaultDispatcher-worker-1]   D/PUMP: [VirtualPumpPlugin.refreshConfiguration():407]: New pump   configuration found (ACCU_CHEK_COMBO), changing from previous (null)
15:26:01.787 [main] I/PUMP:   [InsightConnectionService.pair():379]: Pairing initiated
15:26:01.805 [main] I/PUMP:   [InsightConnectionService.setState():244]: Insight state changed: CONNECTING
15:26:01.823 [Thread-17] I/PUMP:   [InsightConnectionService.handleException():327]: Exception occurred:   ConnectionFailedException
15:26:01.827 [Thread-17] I/PUMP:   [InsightConnectionService.setState():244]: Insight state changed: NOT_PAIRED
15:26:04.941 [main] I/PUMP:   [InsightConnectionService.pair():379]: Pairing initiated
15:26:04.952 [main] I/PUMP:   [InsightConnectionService.setState():244]: Insight state changed: CONNECTING
15:26:04.962 [Thread-18] I/PUMP:   [InsightConnectionService.handleException():327]: Exception occurred:   ConnectionFailedException
15:26:04.977 [Thread-18] I/PUMP:   [InsightConnectionService.setState():244]: Insight state changed: NOT_PAIRED
15:26:09.647 [main] I/PUMP:   [InsightConnectionService.pair():379]: Pairing initiated
15:26:09.662 [main] I/PUMP:   [InsightConnectionService.setState():244]: Insight state changed: CONNECTING

It's the first time I see this kind of error, but everything seems to be within InsightConnectionService.kt file... My 2 different ideas are:

  • maybe increase some timeout during connection???
  • Revert this file from InsightConnectionService.kt to InsightConnectionService.java (but complicated because a lot of refactoring has been done between 3.2 and 3.3)

@TebbeUbben during driver migration to kotlin, I was not able to convert ConnectionEstablisher.java file to kt (it's the only file remaining in java...)

  • communication worked with kt version (see ConnectionEstablisherXX.kt file within kotlin+java folder), but it was impossible to manage pairing with kt version...

Do you think we can adjust something to make the driver more "tolerant"? to allow pairing with ConnectionEstablisher.kt ? or just fix this issue with the java version of ConnectionEstablisher combine with kotlin for the other files of this driver like InsightConnectionService ? BluetoothAdapterExtensionKt.safeEnable(bluetoothAdapter, 2000, null); increase 2000 to wait more ? increase TIMEOUT_DURING_HANDSHAKE_NOTIFICATION_THRESHOLD or RESPONSE_TIMEOUT in InsightConnectionService ? other ? I'm a bit lost with my poor knowledge of BLuetooth management...

Philoul avatar Feb 26 '25 21:02 Philoul

@Philoul The first step in Insight pairing is always low-level Bluetooth pairing. If the pump is already listed as a paired device in the Android system settings, you must first remove it before establishing a new connection, so that a new pairing is established upon connection. The system cannot reuse an existing pairing. However, this also means that any issues at this stage are likely deeper within the system's Bluetooth stack and beyond the driver's scope.

In order to ensure that the system initiates a pairing, the previous bond is deleted using the following code in ConnectionEstablisher.java:

if (forPairing && bluetoothDevice.getBondState() != BluetoothDevice.BOND_NONE) {
    try {
        Method removeBond = bluetoothDevice.getClass().getMethod("removeBond", (Class[]) null);
        removeBond.invoke(bluetoothDevice, (Object[]) null);
    } catch (ReflectiveOperationException e) {
        if (!isInterrupted()) callback.onConnectionFail(e, 0);
        return;
    }
}

Unfortunately, removeBond is a hidden system API, so we can't invoke it directly using the Android SDK. However, as can be seen, using some reflection hacks, we can still call it.

Please pay very careful attention to (Class[]) null and (Object[]) null. Class::getMethod and Method::invoke use vararg parameters, i.e. they allow you to provide an arbitary amount of parameters of a certain type, which are converted to an array by the compiler. You can also pass an array directly and not make use of the vararg nature of the method at all, which is what the code above does. Casting null ensures null is passed as an array rather than an array containing null.

Now, let's look at your Kotlin code:

if (forPairing && bluetoothDevice.bondState != BluetoothDevice.BOND_NONE) {
    try {
        val removeBond = bluetoothDevice.javaClass.getMethod("removeBond", null)
        removeBond.invoke(bluetoothDevice, null)
    } catch (e: ReflectiveOperationException) {
        if (!isInterrupted) callback.onConnectionFail(e, 0)
        return
    }
}

This code will do the latter and create an array containing null. My assumption is that this leads to the reflective operation failing and thus not unpairing the pump. In Kotlin, you have to explicitly instruct the compiler to use a provided array for varargs using the spread operator (*). You can also try to just remove the null parameter at all and see if that works. Alternatives might be *emptyArray() or *null, *(null as Array<Class>?), *(null as Array<Any>?) to stay closer to the Java version. However, I haven't tested and verified this. You can also try to manually delete the pump in the system settings to see if the issue really boils down to removeBond not being called.

TebbeUbben avatar Feb 27 '25 13:02 TebbeUbben

@TebbeUbben Thanks for the hints and explainations, this gives me solutions to migrate the latest java file. But I'm afraid it will not fix current issue:

  • here an Insight pump correctly paired with AAPS 3.2 stop to connect with AAPS after 3.3 update 🤔 (with ConnectionFailedException) Never got this issue despite hundred of tests done, so I can't reproduce it.

I think this ConnectionFailedException prevent communication (with a pump correctly paired previously) or for new pairing trials (same ConnectionFailedException error)

Do you know if we can adjust some parameters or values to make connection more "tolerant" (increase timeout? other?)

Philoul avatar Mar 02 '25 09:03 Philoul

@Philoul ConnectionFailedException is a very general exception. It just indicates that the phone was not able to establish a connection on the Bluetooth/link layer. The connection fails before the driver has any means to do something. I can't think of anything that might cause this issue going from 3.2 to 3.3 since the code responsible for the Bluetooth connection remained unchanged.

Possible debugging endpoints might be:

  • This line and closer inspect the original exception thrown by the Android system to see if it provides a more detailed error description.
  • Inspect the Android system logs with regards to the Bluetooth stack.

It might also be worthwhile to disable and re-enable Bluetooth on the pump, take out the battery and delete the pairing on the pump. Sometimes, it might refuse to pair when you mess too much with it.

TebbeUbben avatar Mar 04 '25 01:03 TebbeUbben

@kneuZ can you please test my PR #3875 and tell me if you can connect with your Insight pump with this version ?

Philoul avatar Mar 09 '25 22:03 Philoul

@kneuZ do you still have this issue with latest master 3.3.2.0?

Philoul avatar Jun 07 '25 13:06 Philoul

Hello,

I apologize for my late response. I had been looping with the Medtrum pump in the meantime and had completely forgotten about the Insight problem. Today I switched back to the Insight due to allergic reactions. Unfortunately, it doesn't work with version 3.3.2 either. I get the pump displayed for pairing, but the app crashes as soon as I select the pump. Unfortunately, sending a log does not work either. Nothing happens when I press the button.

Is there any other idea what I can try?

Image

Image

kneuZ avatar Jun 27 '25 08:06 kneuZ

Just after the crash few minutes max, can you connect your phone to a computer an open file browser to manually find log files //Phone/Android/data/info.nightscout/androidaps/files/*.zip Take the 2 most recent zip files starting by AndroidAPS.2025... and the file AndroidAPS.log file too

Philoul avatar Jun 27 '25 08:06 Philoul

I have the folder \android\Android\data\info.nightscout.androidaps\files

but it is empty even after the crash :-(

EDIT: Okay, I found a logfile. Here it is.

AndroidAPS (2).log

kneuZ avatar Jun 27 '25 09:06 kneuZ

Today I tried again to connect my Insight in version 3.2.0.4. This worked without any problems. I then updated to version 3.3.2.0 and the insulin pump remained connected. As soon as I try to connect to the pump, AAPS crashes and shuts down completely.

AndroidAPS.log

kneuZ avatar Jul 01 '25 12:07 kneuZ