Add two types, system and alert.

This commit is contained in:
Terrence
2025-04-14 16:02:41 +08:00
parent d5d8b34b2b
commit 6e73a11ac9

View File

@@ -466,6 +466,28 @@ void Application::Start() {
thing_manager.Invoke(command);
}
}
} else if (strcmp(type->valuestring, "system") == 0) {
auto command = cJSON_GetObjectItem(root, "command");
if (command != NULL) {
ESP_LOGI(TAG, "System command: %s", command->valuestring);
if (strcmp(command->valuestring, "reboot") == 0) {
// Do a reboot if user requests a OTA update
Schedule([this]() {
Reboot();
});
} else {
ESP_LOGW(TAG, "Unknown system command: %s", command->valuestring);
}
}
} else if (strcmp(type->valuestring, "alert") == 0) {
auto status = cJSON_GetObjectItem(root, "status");
auto message = cJSON_GetObjectItem(root, "message");
auto emotion = cJSON_GetObjectItem(root, "emotion");
if (status != NULL && message != NULL && emotion != NULL) {
Alert(status->valuestring, message->valuestring, emotion->valuestring, Lang::Sounds::P3_VIBRATION);
} else {
ESP_LOGW(TAG, "Alert command requires status, message and emotion");
}
}
});
protocol_->Start();