From 128b7df3f55bf8f4845bc53e394f3a08108208ca Mon Sep 17 00:00:00 2001 From: Benjamin Faershtein <119711889+RCGV1@users.noreply.github.com> Date: Tue, 17 Jun 2025 19:06:54 -0700 Subject: [PATCH 1/2] Fixed connection issues by first sending heartbeat then wantConfig to not do a packet dupe that gets ignored --- Meshtastic/Helpers/BLEManager.swift | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Meshtastic/Helpers/BLEManager.swift b/Meshtastic/Helpers/BLEManager.swift index 84c22341..057defa1 100644 --- a/Meshtastic/Helpers/BLEManager.swift +++ b/Meshtastic/Helpers/BLEManager.swift @@ -525,11 +525,20 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate invalidVersion = true return } else { + + // Send Heartbeat before wantConfig + var heartbeatToRadio: ToRadio = ToRadio() + heartbeatToRadio.payloadVariant = .heartbeat(Heartbeat()) + guard let heartbeatBinaryData: Data = try? heartbeatToRadio.serializedData() else { + Logger.mesh.error("Failed to serialize Heartbeat ToRadio message") + return + } + connectedPeripheral!.peripheral.writeValue(heartbeatBinaryData, for: TORADIO_characteristic, type: .withResponse) let nodeName = connectedPeripheral?.peripheral.name ?? "Unknown".localized let logString = String.localizedStringWithFormat("Issuing Want Config to %@".localized, nodeName) Logger.mesh.info("🛎️ \(logString, privacy: .public)") - + // BLE Characteristics discovered, issue wantConfig var toRadio: ToRadio = ToRadio() configNonce = UInt32(NONCE_ONLY_DB) @@ -567,6 +576,7 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate } 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 + disconnectPeripheral(reconnect: false) } } From 527a1b7966e26c67ba8fa61756d9c64c06e68393 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Tue, 17 Jun 2025 20:44:52 -0700 Subject: [PATCH 2/2] Remove disconnect that overrides pin screen and allow disconnect if device gets hung up --- Meshtastic/Helpers/BLEManager.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Meshtastic/Helpers/BLEManager.swift b/Meshtastic/Helpers/BLEManager.swift index 057defa1..d2c4df7f 100644 --- a/Meshtastic/Helpers/BLEManager.swift +++ b/Meshtastic/Helpers/BLEManager.swift @@ -538,7 +538,6 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate let nodeName = connectedPeripheral?.peripheral.name ?? "Unknown".localized let logString = String.localizedStringWithFormat("Issuing Want Config to %@".localized, nodeName) Logger.mesh.info("🛎️ \(logString, privacy: .public)") - // BLE Characteristics discovered, issue wantConfig var toRadio: ToRadio = ToRadio() configNonce = UInt32(NONCE_ONLY_DB) @@ -576,7 +575,7 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate } 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 - disconnectPeripheral(reconnect: false) + allowDisconnect = true } }