Compare commits
5 commits
a82a3697da
...
ce81a1a3d8
| Author | SHA1 | Date | |
|---|---|---|---|
| ce81a1a3d8 | |||
| fcf427ee57 | |||
| 4bf4435feb | |||
| f082eeadad | |||
| 3720f496bd |
3 changed files with 15 additions and 4 deletions
|
|
@ -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()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue