Skip to content

wifi: retry saved networks and reconnect after runtime drops - #2

Merged
jtruland merged 1 commit into
bitz-v0.2-buildfrom
fix/wifi-retry
Oct 16, 2026
Merged

jtruland merged 1 commit into
bitz-v0.2-buildfrom
fix/wifi-retry

Conversation

@jtruland

Copy link
Copy Markdown
Owner

Why

On 2026-10-15 the robot dropped off eyja's hotspot at 11:32:51 and never tried to rejoin: eyja logged no association, auth or DHCP attempt afterwards. Three power-cycles then all fell back to the setup AP (192.168.4.1), and a fourth boot finally connected.

Two gaps in wifi_connect.cpp:

  • Runtime: arduino-esp32 3.3 only auto-reconnects for the reasons in _is_staReconnectableReason. A deauth for inactivity (4) or leaving (3) is never retried. Hypothesis for the 10/15 drop; unproven until a reason gets logged.
  • Boot: saved networks got one attempt, then the setup AP opened and stayed open.

What

Only src/network/wifi_connect.cpp changes. wifiConnected() semantics are unchanged.

  • Boot: 3 rounds over the saved networks, with a radio restart between rounds, before opening the setup AP.
  • Runtime: logs the disconnect reason. After a 10 s grace it reconnects to the last-good network with 15 s → 5 min backoff (a full radio restart after the first reconnect()), and restarts mDNS once it is back.
  • Fallback setup AP: only when it opened because saved WiFi failed, reboots after 5 min if no client has joined. It never reboots while someone is connected.

Testing

  • pio run -e esp32-c3-devkitm-1 builds cleanly
  • Flash and confirm it boots and connects (blocked: the robot's USB power cable is broken)
  • Kick the robot off the AP and confirm WIFI lost, reason N and a reconnect in the serial log
  • With the AP down at boot, confirm 3 rounds, the setup AP, then a reboot 5 min later

🤖 Generated with Claude Code

The core only auto-reconnects for some disconnect reasons, so an AP that
deauthenticates the robot (e.g. for inactivity) leaves it offline until a
power cycle, and one missed connect at boot drops it into the setup AP.

- Boot: try saved networks for 3 rounds, restarting the radio between rounds,
  before opening the setup AP.
- Runtime: log the disconnect reason; after a 10 s grace, reconnect to the
  last-good network with 15 s..5 min backoff (full radio restart after the
  first attempt).
- Setup AP opened only because saved WiFi failed: reboot after 5 min if no
  client has joined, to retry the saved networks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jtruland
jtruland marked this pull request as ready for review October 16, 2026 16:24
@jtruland
jtruland merged commit 61d6417 into bitz-v0.2-build Oct 16, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant