From 51d5e85042300deb4fa382797841e83a287db507 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Tue, 17 Jun 2025 23:05:19 -0700 Subject: [PATCH] Automatically disconnnect after 6 6 second want config fauilures so the pin dialog has a cheance to time out first --- Meshtastic/Helpers/BLEManager.swift | 10 ++++++---- Meshtastic/Views/Bluetooth/Connect.swift | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Meshtastic/Helpers/BLEManager.swift b/Meshtastic/Helpers/BLEManager.swift index d2c4df7f..930c8fb9 100644 --- a/Meshtastic/Helpers/BLEManager.swift +++ b/Meshtastic/Helpers/BLEManager.swift @@ -60,8 +60,8 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate private var wantConfigTimer: Timer? private var wantConfigRetryCount = 0 - private let maxWantConfigRetries = 2 - private let wantConfigTimeoutInterval: TimeInterval = 5.0 + private let maxWantConfigRetries = 6 + private let wantConfigTimeoutInterval: TimeInterval = 6.0 // MARK: init private override init() { @@ -525,7 +525,6 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate invalidVersion = true return } else { - // Send Heartbeat before wantConfig var heartbeatToRadio: ToRadio = ToRadio() heartbeatToRadio.payloadVariant = .heartbeat(Heartbeat()) @@ -569,13 +568,16 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate private func handleWantConfigTimeout() { guard isWaitingForWantConfigResponse else { return } wantConfigRetryCount += 1 + if wantConfigRetryCount == 1 { + allowDisconnect = true + } if wantConfigRetryCount < maxWantConfigRetries { Logger.mesh.warning("⏰ Want Config timeout, retrying... (attempt \(self.wantConfigRetryCount + 1)/\(self.maxWantConfigRetries))") sendWantConfig() } else { Logger.mesh.error("🚨 Want Config failed after \(self.maxWantConfigRetries) attempts, forcing disconnect") lastConnectionError = "Bluetooth connection timeout, keep your node closer or reboot your radio if the problem continues.".localized - allowDisconnect = true + disconnectPeripheral(reconnect: false) } } diff --git a/Meshtastic/Views/Bluetooth/Connect.swift b/Meshtastic/Views/Bluetooth/Connect.swift index 1176241a..e22e844a 100644 --- a/Meshtastic/Views/Bluetooth/Connect.swift +++ b/Meshtastic/Views/Bluetooth/Connect.swift @@ -282,7 +282,7 @@ struct Connect: View { .controlSize(.large) .padding() } - if bleManager.isConnecting { + if bleManager.allowDisconnect { Button(role: .destructive, action: { bleManager.cancelPeripheralConnection()