Skip to content

fix: increase WiFi shutdown delay before restart to fix MQTT reconnect after OTA - #55

Closed
netscout2001 wants to merge 1 commit into
21cncstudio:mainfrom
netscout2001:main
Closed

netscout2001 wants to merge 1 commit into
21cncstudio:mainfrom
netscout2001:main

Conversation

@netscout2001

Copy link
Copy Markdown

Problem

After any software-triggered restart (OTA update, web dashboard restart button,
MQTT restart command) the device fails to reconnect to the MQTT broker and
requires a full power cycle to restore the connection.

Root cause

All three restart paths call esp_wifi_stop() followed by a short delay()
before safe_restart_via_core0(). The delay is too short for the WiFi and TCP
stacks to complete their shutdown sequences. As a result the MQTT broker still
considers the previous TCP session active when the device comes back up, causing
the reconnect to fail.

Fix

Increased the delay from its current value to 250 ms in all three restart paths.
250 ms is sufficient for WiFi to send the Disassociation frame and for the TCP
stack to send RST on all open sockets including the MQTT connection.

src/main.cpp — OTA reboot path

-    delay(50);
+    delay(300);

The additional delay is imperceptible during a reboot sequence that already
takes several seconds.

Checklist

  • I have read CONTRIBUTING.md and agree to the CLA.
  • I tested my changes or explained why tests are not applicable.
  • I updated documentation if needed.

@21cncstudio

Copy link
Copy Markdown
Owner

Please retest the latest beta firmware that includes the network/web runtime refactor originally introduced in commit 5f4e9d8 (Refactor network and web runtime architecture).

Recommended test build:
project_aura_1.1.2-beta-4a1e694_ota_firmware.bin

This refactor changed the internal architecture of networking, MQTT, web runtime handling, OTA flow, and cross-thread interaction between the web layer, UI layer, and network task.

Copy link
Copy Markdown
Owner

Hi @netscout2001,

Thank you again for investigating the MQTT reconnect problem after OTA!

Your finding that Wi-Fi and TCP needed more time to shut down before restart was incorporated into the final implementation. I used an explicit Wi-Fi disconnect followed by a 250 ms shutdown window, together with the broader restart cleanup, in 507abec.

I’m now improving how Project Aura records community contributions. The project has an Individual Contributor License Agreement, and I’d appreciate it if you could read the current CLA. If you’re happy with it, please post the following exact text as a separate comment containing only this sentence:

I have read and agree to the Project Aura Individual Contributor License Agreement v2.0, and I hereby sign it.

Separately from the CLA, I’d like to record this PR properly and credit you for the shutdown-timing finding. If you would like commit-level co-author attribution where appropriate, one reply with your preferred name and GitHub-associated email (a GitHub noreply address is fine) is enough for all your accepted Aura contributions.

Thanks again for helping make OTA restarts more reliable!

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