[OTA] Report the version actually requested after a successful update (#2374)

On HTTP_UPDATE_OK the pre-reboot RLStoMQTT reported
`installed_version = latestVersion` unconditionally. That is only correct for
a "latest" request: "dev" installs from RELEASE_LINK_DEV, "vX.Y.Z" installs
that tag, and a caller-supplied URL installs an arbitrary image whose
`version` field is just a label (the WebUI sends "test"). On ESP8266
latestVersion is never populated, so every successful OTA there published an
empty installed_version.

Report the version that was actually requested when the URL was derived from
it, and omit the field for a caller-supplied URL rather than publish a label
as a version. The decision is keyed on systemUrl (non-empty only on the
derived branches) rather than on `version`, because `{"url": ...,
"version": "latest"}` takes the url branch and must not be reported as the
latest release. The value is stored as a String so ArduinoJson 6.18.5 copies
it into the document instead of referencing the caller's buffer.

Scope and evidence, stated plainly: this corrects the message when it lands,
and on current development it usually does not. ESPRestart(6) clears
jsonQueue before the drain task publishes, so the pre-reboot "Update success
!" message was dropped on 3 of 3 successful OTAs on a Theengs Bridge,
including one where this code was certified to be the firmware performing the
update. The change is therefore verified by inspection and by clean builds
(theengs-bridge-v11 on ESP32, nodemcuv2-rf on ESP8266, no new warnings), not
by observing the corrected field on hardware. The authoritative
installed_version is republished from OMG_VERSION after the reboot, which was
correct in every run. Making the pre-reboot message survive the restart, or
dropping it in favour of that republish, is a separate change.

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
FlorianandClaude Opus 5 authored and GitHub committed 2026-09-19 19:46:59 -05:00
1 parent 4e49049b27
commit 827c37542a
1 file changed
+11 -1
+11 -1
View File
@@ -3441,7 +3441,17 @@ void MQTTHttpsFWUpdate(const char* topicOri, JsonObject& HttpsFwUpdateData) {
case HTTP_UPDATE_OK:
THEENGS_LOG_NOTICE(F("HTTP_UPDATE_OK" CR));
jsondata["release_summary"] = "Update success !";
jsondata["installed_version"] = latestVersion;
// Report what was installed, not the latest release: latestVersion only
// describes a "latest" request, while "dev" and "vX.Y.Z" install what the
// caller asked for. systemUrl is filled in only when we built the URL from
// version; for a caller supplied URL the version is just a label with no
// guarantee (the WebUI sends "test"), so the field is omitted rather than
// published wrong; the value is republished from OMG_VERSION after reboot.
// The version is stored as a String so its content is copied into the
// document instead of being referenced from the caller's document.
if (systemUrl.length()) {
jsondata["installed_version"] = strcmp(version, "latest") == 0 ? latestVersion : String(version);
}
jsondata["origin"] = subjectRLStoMQTT;
enqueueJsonObject(jsondata);
# if !MQTT_BROKER_MODE