fix: skip ACK wait on SaveConfig — beacon reboots, never ACKs
SaveConfig (0x60) causes the beacon MCU to reboot and save to flash. It never sends an ACK, so writeToCharAndWaitACK would wait for the 5s timeout, during which the beacon disconnects. The disconnect handler fires while writesCompleted is still false, causing a false "Unexpected disconnect: beacon timed out" error. Fix: fire-and-forget the SaveConfig write and return immediately. The BLE-level write (.withResponse) confirms delivery. writeConfig() returns before the disconnect callback runs, so writesCompleted gets set to true in time. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
3720f496bd
commit
f082eeadad
1 changed files with 9 additions and 0 deletions
|
|
@ -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 {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue