Added Reboot and Manual FW Update commands
This commit is contained in:
@@ -1035,6 +1035,12 @@ void CommandHandler::handleSystemCommand(JsonVariant contents, const MessageCont
|
||||
handleSetMqttLogLevelCommand(contents, context);
|
||||
} else if (action == "set_mqtt_enabled") {
|
||||
handleSetMqttEnabledCommand(contents, context);
|
||||
} else if (action == "restart" || action == "reboot") {
|
||||
handleRestartCommand(context);
|
||||
} else if (action == "force_update") {
|
||||
handleForceUpdateCommand(contents, context);
|
||||
} else if (action == "custom_update") {
|
||||
handleCustomUpdateCommand(contents, context);
|
||||
} else {
|
||||
LOG_WARNING("Unknown system action: %s", action.c_str());
|
||||
sendErrorResponse("system", "Unknown action: " + action, context);
|
||||
@@ -1172,3 +1178,103 @@ void CommandHandler::handleSetMqttEnabledCommand(JsonVariant contents, const Mes
|
||||
}
|
||||
}
|
||||
|
||||
// ════════════════════════════════════════════════════════════════════════════
|
||||
// RESTART COMMAND
|
||||
// ════════════════════════════════════════════════════════════════════════════
|
||||
|
||||
void CommandHandler::handleRestartCommand(const MessageContext& context) {
|
||||
LOG_WARNING("🔄 Device restart requested via command");
|
||||
sendSuccessResponse("restart", "Device will restart in 2 seconds", context);
|
||||
|
||||
// Small delay to ensure response is sent
|
||||
delay(2000);
|
||||
|
||||
// Restart the ESP32
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
// ════════════════════════════════════════════════════════════════════════════
|
||||
// FORCE UPDATE COMMAND
|
||||
// ════════════════════════════════════════════════════════════════════════════
|
||||
|
||||
void CommandHandler::handleForceUpdateCommand(JsonVariant contents, const MessageContext& context) {
|
||||
LOG_WARNING("🔄 Force OTA update requested via command");
|
||||
|
||||
// Check if player is active
|
||||
if (_player && _player->isPlaying()) {
|
||||
sendErrorResponse("force_update", "Cannot update while playback is active", context);
|
||||
LOG_WARNING("Force update rejected - player is active");
|
||||
return;
|
||||
}
|
||||
|
||||
// Get optional channel parameter (defaults to "stable")
|
||||
String channel = "stable";
|
||||
if (contents.containsKey("channel")) {
|
||||
channel = contents["channel"].as<String>();
|
||||
}
|
||||
|
||||
sendSuccessResponse("force_update",
|
||||
"Starting forced OTA update from channel: " + channel + ". Device may reboot.", context);
|
||||
|
||||
// Small delay to ensure response is sent
|
||||
delay(1000);
|
||||
|
||||
// Perform the update
|
||||
bool result = _otaManager.performManualUpdate(channel);
|
||||
|
||||
// Note: If update succeeds, device will reboot and this won't be reached
|
||||
if (!result) {
|
||||
LOG_ERROR("Force update failed");
|
||||
// Error response may not be received if we already restarted
|
||||
}
|
||||
}
|
||||
|
||||
// ════════════════════════════════════════════════════════════════════════════
|
||||
// CUSTOM UPDATE COMMAND
|
||||
// ════════════════════════════════════════════════════════════════════════════
|
||||
|
||||
void CommandHandler::handleCustomUpdateCommand(JsonVariant contents, const MessageContext& context) {
|
||||
LOG_WARNING("🔥 Custom OTA update requested via command");
|
||||
|
||||
// Validate required parameters
|
||||
if (!contents.containsKey("firmware_url")) {
|
||||
sendErrorResponse("custom_update", "Missing firmware_url parameter", context);
|
||||
return;
|
||||
}
|
||||
|
||||
String firmwareUrl = contents["firmware_url"].as<String>();
|
||||
|
||||
// Optional parameters
|
||||
String checksum = contents.containsKey("checksum") ?
|
||||
contents["checksum"].as<String>() : "";
|
||||
size_t fileSize = contents.containsKey("file_size") ?
|
||||
contents["file_size"].as<size_t>() : 0;
|
||||
|
||||
// Check if player is active
|
||||
if (_player && _player->isPlaying()) {
|
||||
sendErrorResponse("custom_update", "Cannot update while playback is active", context);
|
||||
LOG_WARNING("Custom update rejected - player is active");
|
||||
return;
|
||||
}
|
||||
|
||||
LOG_INFO("Custom update: URL=%s, Checksum=%s, Size=%u",
|
||||
firmwareUrl.c_str(),
|
||||
checksum.isEmpty() ? "none" : checksum.c_str(),
|
||||
fileSize);
|
||||
|
||||
sendSuccessResponse("custom_update",
|
||||
"Starting custom OTA update. Device may reboot.", context);
|
||||
|
||||
// Small delay to ensure response is sent
|
||||
delay(1000);
|
||||
|
||||
// Perform the custom update
|
||||
bool result = _otaManager.performCustomUpdate(firmwareUrl, checksum, fileSize);
|
||||
|
||||
// Note: If update succeeds, device will reboot and this won't be reached
|
||||
if (!result) {
|
||||
LOG_ERROR("Custom update failed");
|
||||
// Error response may not be received if we already restarted
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -153,4 +153,9 @@ private:
|
||||
|
||||
// MQTT Control Commands
|
||||
void handleSetMqttEnabledCommand(JsonVariant contents, const MessageContext& context);
|
||||
|
||||
// Device Control Commands
|
||||
void handleRestartCommand(const MessageContext& context);
|
||||
void handleForceUpdateCommand(JsonVariant contents, const MessageContext& context);
|
||||
void handleCustomUpdateCommand(JsonVariant contents, const MessageContext& context);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user