Add MQTT device commands (reboot, factory reset, version-pinned fwupgrade)#1212
Open
gskjold wants to merge 5 commits into
Open
Add MQTT device commands (reboot, factory reset, version-pinned fwupgrade)#1212gskjold wants to merge 5 commits into
gskjold wants to merge 5 commits into
Conversation
New per-handler config flag (default off) that will gate destructive MQTT
commands (reboot / factory reset). Uses the MqttConfig.magic migration (new
magic 0xB6) instead of bumping the global EEPROM version, defaulting the field
to false for existing configs. Exposed in the configuration JSON ("q":{"dc"}),
the web save form (qdc), and the MQTT setconfig parser.
Also adds REBOOT_CAUSE_MQTT_REBOOT / _FACTORY_RESET / _FIRMWARE_UPGRADE for
tagging MQTT-initiated reboots.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…upgrade
Move the generic device commands into AmsMqttHandler::handleCommand so all
payload handlers share them, and wire JSON, Raw and Home Assistant onMessage to
call it (replacing their duplicated fwupgrade handling):
- fwupgrade: now accepts an optional "version" ({"action":"fwupgrade","version":
"vX.Y.Z"}); falls back to the latest detected version. Always allowed.
- reboot: gated by MqttConfig.allowDestructiveCommands.
- factoryreset: gated by the flag AND requires {"confirm":true}.
Accepts plain payloads ("reboot") or JSON ({"action":"reboot"}). MQTT-initiated
reboots are tagged with the new REBOOT_CAUSE_MQTT_* causes when a
ResetDataContainer is wired in (set on the main handler in the bridge).
Works on both ESP8266 and ESP32 (unlike getconfig/setconfig).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Render a checkbox in the MQTT configuration section bound to q.dc, posting qdc to /save, so the destructive-commands flag is configurable from the web UI (not only via MQTT setconfig). Adds the conf.mqtt.allowdestructive source string and rebuilds ui/dist. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Drop the "(reboot, factory reset)" parenthetical for a cleaner label; the specific commands will be covered in documentation instead. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Relocate the day/month plot requests from JsonMqttHandler into the shared AmsMqttHandler::handleCommand, so Raw and Home Assistant can request plots too (Domoticz and Passthrough keep their empty handlers by design). Moves the AmsDataStorage pointer to the base handler (set via setDataStorage in the bridge) since the plot generators need it. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
🔧 PR Build ArtifactsVersion: All environments built successfully. Download the zip files:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds remote device commands over MQTT — reboot, factory reset, version-pinned firmware upgrade, and day/month plot requests — shared across the JSON, Raw and Home Assistant payload handlers, plus a per-device config flag that gates the destructive ones. Requested by a client.
Commands
Sent to the device's command topic (the configured
subscribeTopic, or<publishTopic>/commandwhen blank). Accepts a JSON object or a plain payload:{"action":"fwupgrade"}or{"action":"fwupgrade","version":"v2.5.6"}{"action":"dayplot"}→ published to<publishTopic>/dayplot{"action":"monthplot"}→ published to<publishTopic>/monthplot{"action":"reboot"}allowDestructiveCommands{"action":"factoryreset","confirm":true}"confirm":truefwupgradenow accepts an optionalversion(falls back to the latest detected version) — so a specific release can be pinned.Destructive-actions flag
New
MqttConfig.allowDestructiveCommands(default off). Reboot and factory reset are no-ops unless it's enabled; factory reset additionally requires an explicitconfirm. The only authorization boundary for MQTT is the broker's auth/ACLs, so destructive actions are opt-in per device.Configurable from the web UI (Configuration → MQTT checkbox), the web
/saveform (qdc), and MQTTsetconfig(q.dc); exposed inconfiguration.json(q.dc).Stored via the
MqttConfig.magicmigration (new magic0xB6) rather than a globalEEPROM_EXPECTED_VERSIONbump — existing configs default the field to false on read.Implementation notes
AmsMqttHandler::handleCommand()(base class);JsonMqttHandler,RawMqttHandlerandHomeAssistantMqttHandlercall it fromonMessage, replacing their duplicatedfwupgradehandling. JSON keeps its extragetconfig/setconfig(ESP32-only).AmsDataStoragemoved to the base handler (set viasetDataStoragein the bridge) so the shared plot commands can generate their JSON.getconfig/setconfig, which remain ESP32-only).REBOOT_CAUSE_MQTT_REBOOT/_FACTORY_RESET/_FIRMWARE_UPGRADE(via aResetDataContainerwired to the active handler), so the reboot reason shows up in sysinfo.Testing
Builds on all targets (
esp8266,esp32,esp32s2,esp32solo,esp32c3,esp32s3); native decoder tests unaffected. ESP8266 flash ~97.4%.Verified on a live ESP32-S2 (broker = RabbitMQ), in both JSON and Home Assistant payload formats:
11); flag persists across reboot.confirm→ no-op, config intact).v2.5.6— real download+flash from the cloud, device booted intov2.5.6.<publishTopic>/dayplot.qdcsave path toggles the flag.Not exercised on hardware (covered by code + gating tests): a real factory reset (would wipe to AP mode).
Follow-ups