Merge branch 'schwifty/faster-provisioning' into main

This commit is contained in:
Schwifty 2026-03-23 03:50:41 +00:00
commit ce81a1a3d8
3 changed files with 15 additions and 4 deletions

View file

@ -365,8 +365,10 @@ class BeaconProvisioner: NSObject, ObservableObject {
isTerminating = true isTerminating = true
DebugLog.shared.log("BLE: Provisioning success!") DebugLog.shared.log("BLE: Provisioning success!")
state = .success state = .success
disconnectPeripheral() // Signal completion BEFORE disconnecting the disconnect delegate fires
// synchronously and ScanView needs writesCompleted=true before it sees it
completion?(.success(macAddress: nil)) completion?(.success(macAddress: nil))
disconnectPeripheral()
cleanup() cleanup()
} }

View file

@ -173,6 +173,15 @@ final class DXSmartProvisioner: NSObject, BeaconProvisioner {
for (index, (name, packet)) in commands.enumerated() { for (index, (name, packet)) in commands.enumerated() {
await diagnosticLog?.log("write", "[\(index + 1)/\(commands.count)] \(name) (\(packet.count) bytes)") await diagnosticLog?.log("write", "[\(index + 1)/\(commands.count)] \(name) (\(packet.count) bytes)")
// SaveConfig (last command) causes beacon MCU to reboot it never sends an ACK.
// Fire the BLE write and return immediately; the disconnect is expected.
if name == "SaveConfig" {
peripheral.writeValue(packet, for: writeChar, type: .withResponse)
await diagnosticLog?.log("write", "✅ [\(index + 1)/\(commands.count)] SaveConfig sent — beacon will reboot")
await diagnosticLog?.log("write", "✅ All commands written successfully")
return
}
// Retry each command up to 2 times beacon BLE stack can be flaky // Retry each command up to 2 times beacon BLE stack can be flaky
var lastError: Error? var lastError: Error?
for writeAttempt in 1...2 { for writeAttempt in 1...2 {
@ -193,8 +202,8 @@ final class DXSmartProvisioner: NSObject, BeaconProvisioner {
throw lastError throw lastError
} }
// 500ms between commands beacon needs time to process // 150ms between commands aggressive speedup (was 300ms, originally 500ms)
try await Task.sleep(nanoseconds: 500_000_000) try await Task.sleep(nanoseconds: 150_000_000)
} }
} }

View file

@ -698,7 +698,7 @@ struct ScanView: View {
try await provisioner.writeConfig(config) try await provisioner.writeConfig(config)
writesCompleted = true writesCompleted = true
provisioner.disconnect() // No explicit disconnect needed succeed() already disconnects
try await APIClient.shared.registerBeaconHardware( try await APIClient.shared.registerBeaconHardware(
businessId: business.id, businessId: business.id,