fix: auto-reconnect on disconnect during device info read #5

Closed
schwifty wants to merge 0 commits from schwifty/fix-device-info-disconnect-retry into main
Collaborator

Problem

Beacon drops BLE connection during the optional MAC address query (0x30) after auth succeeds. This triggers: "Disconnected while reading device information..."

The MAC read is a nice-to-have (we use it in the success callback) but not required for provisioning.

Fix

  • On disconnect during device info read, reconnect instead of failing
  • Set skipDeviceInfoRead flag so the retry skips the MAC query and goes straight to config write
  • Uses existing connectionRetryCount / MAX_CONNECTION_RETRIES (up to 3 attempts)
  • Only fails if all retries exhausted

What changed

  • New skipDeviceInfoRead flag in provisioning state
  • Disconnect handler reconnects + resets BLE state instead of calling fail()
  • dxSmartReadDeviceInfoBeforeWrite() checks skip flag and bypasses MAC read
  • Flag properly reset in all cleanup/init paths
## Problem Beacon drops BLE connection during the optional MAC address query (0x30) after auth succeeds. This triggers: **"Disconnected while reading device information..."** The MAC read is a nice-to-have (we use it in the success callback) but not required for provisioning. ## Fix - On disconnect during device info read, **reconnect** instead of failing - Set `skipDeviceInfoRead` flag so the retry skips the MAC query and goes straight to config write - Uses existing `connectionRetryCount` / `MAX_CONNECTION_RETRIES` (up to 3 attempts) - Only fails if all retries exhausted ## What changed - New `skipDeviceInfoRead` flag in provisioning state - Disconnect handler reconnects + resets BLE state instead of calling `fail()` - `dxSmartReadDeviceInfoBeforeWrite()` checks skip flag and bypasses MAC read - Flag properly reset in all cleanup/init paths
schwifty added 3 commits 2026-03-21 23:32:28 +00:00
- Add isTerminating flag to guard succeed()/fail() against double invocation
  from racing didWriteValueFor + didDisconnectPeripheral callbacks
- Only call cancelPeripheralConnection when peripheral.state == .connected
  (avoids triggering spurious didDisconnectPeripheral on already-disconnected peripheral)
- Handle disconnect during device info read (post-auth) with specific error message
- Include state info in unexpected disconnect errors for easier debugging
- Early-return structure in disconnect handler for clearer control flow

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The comment said "treat as non-fatal" but the code calls fail() — which
is correct behavior since we can't write config without a connection.
Updated comment to accurately describe the fail-with-retry-prompt flow.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The beacon sometimes drops BLE connection during the optional MAC address
query (0x30) after auth. Previously this failed with "Disconnected after
auth during device info read". Now we reconnect and skip the MAC read on
retry, going straight to config write. MAC is nice-to-have, not required.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
koda closed this pull request 2026-03-21 23:38:21 +00:00

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: payfrit/payfrit-beacon-ios#5
No description provided.