Make ESP32 OTA startup handle WiFi and WebConfig automatically

Report the upload address and required network, honor AP switches on an existing uploader, and keep delayed WebConfig cleanup from disabling OTA WiFi. Preserve actionable startup errors and account for OTA in wireless state controls.

Exercise the production OTA lifecycle and stock website console, including power-saving idle sessions, in host regression tests.
This commit is contained in:
mikecarper committed 2026-10-05 10:31:43 -07:00
1 parent 22e1e405f4
commit 47135e081c
23 files changed
+965 -46

No files matched your search

+7
View File
@@ -22,6 +22,9 @@ public:
}
uint8_t enabled() const override {
uint8_t mask = 0;
#ifdef ESP32
if (board.isOTAUpdateRunning()) mask |= mesh::wireless::WiFi;
#endif
#ifdef WITH_WEBCONFIG
if (the_mesh.isWebConfigActive()) mask |= mesh::wireless::WiFi;
#endif
@@ -56,6 +59,10 @@ public:
#if defined(ESP32) && (defined(WITH_WEBCONFIG) || defined(WITH_MQTT_BRIDGE))
if (service == mesh::wireless::WiFi) {
if (!on) {
if (board.isOTAUpdateRunning()) {
char reply[160];
if (!board.stopOTAUpdate(reply)) return Result::Failed;
}
if (!wifi_saved_) {
#ifdef WITH_WEBCONFIG
resume_web_ = the_mesh.isWebConfigActive();
+17 -4
View File
@@ -3349,13 +3349,26 @@ bool MyMesh::handleLocalControlCommand(const char* command, char* reply,
// Board implementations use the common 160-byte CLI reply contract.
// Binary Companion callers may supply a shorter buffer.
char ota_reply[160] = {0};
bool webconfig_stopped = false;
#ifdef WITH_WEBCONFIG
if (isWebConfigActiveOrStopping()) {
if (!_webconfig->stopForOTA(ota_reply)) {
snprintf(reply, reply_size, "%s", ota_reply);
return true;
}
webconfig_stopped = true;
ota_reply[0] = 0;
}
#endif
if (!board.startOTAUpdate(_prefs.node_name, ota_reply,
strcmp(command, "start ota ap") == 0)) {
snprintf(reply, reply_size, "%s",
ota_reply[0] ? ota_reply : "ERR: WiFi OTA unavailable");
} else {
snprintf(reply, reply_size, "%s", ota_reply);
if (!ota_reply[0]) strcpy(ota_reply, "ERR: WiFi OTA unavailable");
}
if (webconfig_stopped) {
const size_t used = strlen(ota_reply);
snprintf(ota_reply + used, sizeof(ota_reply) - used, "; WebConfig stopped");
}
snprintf(reply, reply_size, "%s", ota_reply);
return true;
}
if (strcmp(command, "stop ota") == 0) {
+9
View File
@@ -2337,6 +2337,12 @@ void halt() {
}
static bool finishStoppingCompanionWiFi() {
#ifdef COMPANION_RADIO_FULL
if (board.isOTAUpdateRunning()) {
char reply[160];
if (!board.stopOTAUpdate(reply)) return false;
}
#endif
cancelCompanionWiFiNtp(false);
stopCompanionWiFiServices();
#ifdef WITH_WEBCONFIG
@@ -2902,6 +2908,9 @@ public:
uint8_t enabled() const override {
uint8_t mask = 0;
#if defined(ESP32) && defined(WIFI_SSID)
#ifdef COMPANION_RADIO_FULL
if (board.isOTAUpdateRunning()) mask |= mesh::wireless::WiFi;
#endif
if (companion_wifi_requested || companion_wifi_active) mask |= mesh::wireless::WiFi;
#ifdef WITH_WEBCONFIG
if (the_mesh.isWebConfigActiveOrStopping()) mask |= mesh::wireless::WiFi;
+3
View File
@@ -1608,6 +1608,9 @@ public:
bool isWebConfigStopping() const { return _webconfig && _webconfig->isStopping(); }
bool hasWirelessNetworkClient() const { return _web_terminal != nullptr; }
bool stopWebConfig(char* reply) override;
bool stopWebConfigForOTA(char* reply) override {
return !_webconfig || _webconfig->stopForOTA(reply);
}
bool setWebUIEnabled(bool enabled, char* reply) override;
bool getWebUIStatus(char* reply) const override;
bool getWiFiSSID(char* reply) const override;
+3
View File
@@ -864,6 +864,9 @@ public:
bool isWebConfigStopping() const { return _webconfig && _webconfig->isStopping(); }
bool hasWirelessNetworkClient() const { return _web_terminal != nullptr; }
bool stopWebConfig(char* reply) override;
bool stopWebConfigForOTA(char* reply) override {
return !_webconfig || _webconfig->stopForOTA(reply);
}
bool setWebUIEnabled(bool enabled, char* reply) override;
bool getWebUIStatus(char* reply) const override;
bool getWiFiSSID(char* reply) const override;