Skip to content

Optional STA rejoin from the setup fallback - #1150

Merged
luc-github merged 3 commits into
luc-github:3.1from
Mainfurr:upstream-sta-retry
Oct 29, 2026
Merged

luc-github merged 3 commits into
luc-github:3.1from
Mainfurr:upstream-sta-retry

Conversation

@Mainfurr

Copy link
Copy Markdown
Contributor

If STA can't connect at boot (for example while the router is rebooting) and sta fallback mode is setup, ESP3D switches to the setup AP and stays there until someone restarts it. This PR adds an opt-in setting so it rejoins on its own once the network is back.

Changes

  • New byte setting ESP_STA_FALLBACK_RETRY (position 1257, the first free byte after ESP_USB_SERIAL_BAUD_RATE), shown in [ESP400] as "sta fallback retry" under network/sta. It's no/yes with a default of no, so behaviour is unchanged unless it's turned on.
  • When it's on, the radio mode is STA, and the setup AP is running as the STA fallback, WiFiConfig::handle() starts an async scan every 2 minutes (STA_FALLBACK_RETRY_INTERVAL). If the configured SSID shows up, it calls NetConfig::begin(). If that connection fails again, the normal fallback applies.
  • No scan runs while a client is connected to the setup AP, because the channel hopping would disrupt it.
  • Settings saved by older builds have 0xFF at the new position. ESP3DSettings::begin() replaces an invalid value there with the default.

Testing

  • This branch builds for esp32-c3 and esp8266dev.
  • The same two commits run on an ESP32-C3 with Marlin, on DevZTH's fork of 3.1.3 (only the base differs). With the extender off, I power-cycled the printer so it came up in setup mode. After the extender was switched back on, the printer rejoined STA by itself.

Limitations

  • A hidden SSID never appears in a scan, so it won't be rejoined.
  • With a wrong saved password, it retries every 2 minutes, and each attempt briefly drops the setup AP.

@luc-github

Copy link
Copy Markdown
Owner

what about AP never show up ? it will scan every 2 min and stay in STA mode without beeing configured again ?

@Mainfurr

Copy link
Copy Markdown
Contributor Author

It stays in setup AP mode the whole time and remains configurable at the setup IP. It scans every 2 minutes only while no client is connected to the AP, so configuring isn't disturbed. If you prefer, I can add a limit, e.g. stop after N attempts or back off to longer intervals.

New setting ESP_STA_FALLBACK_RETRY (pos 1257, "sta fallback retry" in
network/sta, default off). When it is on and the STA connection failed
over to the setup AP, ESP3D scans every 2 minutes (while no client is
connected to the AP) and restarts the network once the configured SSID
is visible again. If that attempt fails it falls back to setup mode as
before.

Settings saved by older builds read 0xFF at the new position; the
default is written at startup when the stored value is not valid.
@luc-github

Copy link
Copy Markdown
Owner

no need extra settings to keep it simple, but I think it would be good to add an ESP command for it, to disable easily it if necessary and to get the status if connected by serial

[ESP109] shows or sets the sta fallback retry setting (ON/OFF, admin to
set), so it can be turned off without [ESP401]. When the setup fallback
starts with the retry on, "Waiting for STA network" is sent to all
clients, next to the existing "STA network found, reconnecting".
Documented in espXXX.md, Commands.md and authentication.md.
isValidByteSetting() returns true for any value of an on/off setting, so
[ESP109]MAYBE stored 255. Only ON and OFF are written now, anything else
gets "Invalid parameter". The 0xFF init check for the setting compares
the value directly for the same reason.
@Mainfurr

Copy link
Copy Markdown
Contributor Author

Thanks, makes sense. I've added [ESP109] to show or set the rejoin (ON/OFF, set needs admin), and when the setup fallback starts with the rejoin on it now sends "Waiting for STA network" to all clients (serial included), next to the existing "STA network found, reconnecting". No new settings. Docs updated in espXXX.md, Commands.md and authentication.md.

@luc-github
luc-github merged commit 4af9394 into luc-github:3.1 Oct 29, 2026
@luc-github

Copy link
Copy Markdown
Owner

merged thank you

@all-contributors please add @Mainfurr for code enhancement

@allcontributors

Copy link
Copy Markdown
Contributor

@luc-github

I've put up a pull request to add @Mainfurr! 🎉

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