feat: Add API endpoints for system reboot and retrieving system information.

This commit is contained in:
2026-03-02 23:05:10 -05:00
parent a010b0c352
commit 37291557eb
2 changed files with 107 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
#pragma once
#include "cJSON.h"
#include "esp_http_server.h"
#include "esp_system.h"
#include "esp_timer.h"
static void restart_timer_callback(void *arg) { esp_restart(); }
static esp_err_t api_system_reboot_handler(httpd_req_t *req) {
httpd_resp_set_type(req, "application/json");
cJSON *root = cJSON_CreateObject();
cJSON_AddStringToObject(root, "status", "rebooting");
const char *response_text = cJSON_Print(root);
httpd_resp_sendstr(req, response_text);
free((void *)response_text);
cJSON_Delete(root);
const esp_timer_create_args_t restart_timer_args = {
.callback = &restart_timer_callback,
.arg = (void *)0,
.dispatch_method = ESP_TIMER_TASK,
.name = "restart_timer"};
esp_timer_handle_t restart_timer;
esp_timer_create(&restart_timer_args, &restart_timer);
// Schedule reboot 1 second from now to allow HTTP response to flush
esp_timer_start_once(restart_timer, 1000000);
return ESP_OK;
}
static const httpd_uri_t api_system_reboot_uri = {.uri = "/api/system/reboot",
.method = HTTP_POST,
.handler =
api_system_reboot_handler,
.user_ctx = NULL};