From e387b9ceb12ee55ac3386c293c48574e924a584b Mon Sep 17 00:00:00 2001 From: Schwifty Date: Sat, 21 Mar 2026 22:28:47 +0000 Subject: [PATCH] fix: handle expected BLE disconnect after SaveConfig command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The DX-Smart CP28 beacon reboots after receiving SaveConfig (0x60) to persist config to flash. This drops the BLE connection before the write callback fires, causing the app to report "Unexpected disconnect" even though the config was successfully saved. Now we check if we're on the last command (SaveConfig) when disconnect occurs — if so, treat it as success instead of failure. Co-Authored-By: Luna --- PayfritBeacon/BeaconProvisioner.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/PayfritBeacon/BeaconProvisioner.swift b/PayfritBeacon/BeaconProvisioner.swift index 256903d..89e8bd8 100644 --- a/PayfritBeacon/BeaconProvisioner.swift +++ b/PayfritBeacon/BeaconProvisioner.swift @@ -974,6 +974,11 @@ extension BeaconProvisioner: CBCentralManagerDelegate { } else if state != .success && state != .idle { if case .failed = state { // Already failed + } else if state == .writing && dxSmartWriteIndex >= dxSmartCommandQueue.count - 1 { + // SaveConfig (last command) was sent — beacon rebooted to apply config + // This is expected behavior, treat as success + DebugLog.shared.log("BLE: Disconnect after SaveConfig — treating as success") + succeed() } else { fail("Unexpected disconnect", code: .disconnected) }