Skip to content

Add WiFi reconnection to companion radio#2299

Open
swannman wants to merge 1 commit intomeshcore-dev:devfrom
swannman:wifi-reconnect
Open

Add WiFi reconnection to companion radio#2299
swannman wants to merge 1 commit intomeshcore-dev:devfrom
swannman:wifi-reconnect

Conversation

@swannman
Copy link
Copy Markdown

@swannman swannman commented Apr 13, 2026

Summary

  • Adds periodic WiFi health check (every 60s) in SerialWifiInterface::checkRecvFrame()
  • Only attempts reconnect after WiFi has successfully connected at least once (won't interfere with initial connection on startup)
  • Fixes issue where companion radio WiFi firmware never rejoins the AP after losing connectivity

Fixes #2300

Context

On ESP32 Arduino core 2.x (espressif32@6.11.0), the built-in WiFi.setAutoReconnect() is unreliable. This adds an explicit reconnection loop as a more dependable alternative.

Test plan

  • Build heltec_v4_companion_radio_wifi target
  • Flash and confirm WiFi connects on startup (IP shown on display)
  • Disable/reboot the AP, wait >60s, re-enable AP
  • Confirm device reconnects and IP reappears on display
  • Cold boot with AP unavailable — confirm no reconnect spam

The WiFi companion firmware previously had no reconnection handling after
the initial WiFi.begin() call. On ESP32 Arduino core 2.x, the built-in
auto-reconnect is unreliable, so if WiFi drops it never comes back.

This adds a periodic health check (every 60s) in checkRecvFrame() that
detects WiFi disconnection and calls WiFi.reconnect(). The check only
activates after WiFi has successfully connected at least once, so it
won't interfere with the initial connection attempt on startup.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@petrkr
Copy link
Copy Markdown

petrkr commented Apr 13, 2026

Is this needed? ESP IDF should take care about reconnects itself..
Atleast it works on other projects very well even if AP is down for days.

Would be better update SDK than making workarounds.

#2265

@swannman
Copy link
Copy Markdown
Author

Hi @petrkr - agreed that ESP-IDF has built-in reconnect support. We actually tried the simpler approach first (WiFi.mode(WIFI_STA) + WiFi.setAutoReconnect(true) before WiFi.begin()), but it didn't resolve the issue on this board with the current platform version (espressif32@6.11.0 / Arduino core 2.x).

Upgrading the SDK would be ideal long-term, but it's a significant change — the Arduino core 2.x to 3.x migration has breaking API changes across WiFi, BLE, SPI, etc., and would affect every ESP32 build target in the project. Felt too risky for this one fix.

@petrkr
Copy link
Copy Markdown

petrkr commented Apr 14, 2026

Only 1 change with import, nothing breaking.. claude said this to you? It is wrong. Check code as human programmer first, then you will not write those missleading informations

@swannman
Copy link
Copy Markdown
Author

Hi @petrkr, could you clarify what you're referring to as "1 change with import"?

I don't think you're suggesting that I fix this by bumping espressif32@6.11.0 in platformio.ini to 6.13.0, since that isn't where the WiFi reconnect behavior is implemented.

Are you suggesting that I take on the larger update to get us onto Arduino core 3.x with the ESP-IDF 5.x WiFi stack? If so, based on your PR #2265 this looks like a larger change with back-compat impact.

@petrkr
Copy link
Copy Markdown

petrkr commented Apr 14, 2026

One import is in elegant ota #2306

And for 3.0 upto 3.4 it's just 1 line in espnow
For 3.5 it's 2nd line in espnow

Everything is done in that PR and it is backward compatible

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.

2 participants