From 8ff4e1e945f7cb69161dcccef985d2dba673b124 Mon Sep 17 00:00:00 2001 From: Erik Johansson Date: Thu, 12 Apr 2018 19:34:07 +0200 Subject: [PATCH] Improve bluetooth connection sequence By adding a sleep after the service discovery I can now connect every time to the scale, something that didn't work before. --- .../openscale/core/bluetooth/BluetoothCommunication.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothCommunication.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothCommunication.java index cd8f6887..ceb82a5e 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothCommunication.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothCommunication.java @@ -491,6 +491,15 @@ public abstract class BluetoothCommunication { descriptorRequestQueue = new LinkedList<>(); openRequest = false; + try { + // Sleeping a while after discovering services fixes connection problems. + // See https://github.com/NordicSemiconductor/Android-DFU-Library/issues/10 + // for some technical background. + Thread.sleep(1000); + } + catch (Exception e) { + // Empty + } btMachineState = BT_MACHINE_STATE.BT_INIT_STATE; nextMachineStateStep();