The Mistake: Using a short supervision timeout (e.g., 1 second) for a BLE connection to a peripheral that uses peripheral latency to skip connection events, resulting in unexpected disconnections during normal operation when no data is being exchanged.
Why It Happens: Developers set aggressive timeouts thinking βfaster disconnect detection is better,β without accounting for the interaction between connection interval, peripheral latency, and supervision timeout. If peripheral latency allows skipping 10 events at 400ms intervals, the peripheral may not respond for 4 secondsβtriggering a 1-second timeout.
The Fix: The supervision timeout must accommodate the worst-case response time based on your connection parameters. Use this formula:
Minimum supervision timeout = (1 + peripheral_latency) Γ connection_interval Γ 2
Example calculations:
Scenario A (fast response, no latency):
- Connection interval: 50ms
- Peripheral latency: 0 (respond every event)
- Minimum timeout: (1 + 0) Γ 50ms Γ 2 = 100ms
- Recommended: 500ms-1s (margin for retries)
Scenario B (power-optimized sensor):
- Connection interval: 400ms (maximum for iOS)
- Peripheral latency: 4 (skip up to 4 events when idle)
- Minimum timeout: (1 + 4) Γ 400ms Γ 2 = 4000ms
- Recommended: 6-10 seconds
Scenario C (ultra-low-power with max latency):
- Connection interval: 4s (BLE maximum)
- Peripheral latency: 0 (required at max interval)
- Minimum timeout: (1 + 0) Γ 4s Γ 2 = 8s
- Recommended: 16-32 seconds (BLE max is 32s)
Common mistake:
- CI: 200ms, Latency: 10, Timeout: 2s
- Worst-case response: (1+10) Γ 200ms = 2.2s > 2s timeout
- Result: Random disconnections when peripheral is idle!
Always verify: timeout > (1 + latency) Γ interval Γ safety_factor where safety_factor >= 2.