Files
Calendink/Provider/main/api/ota/status.cpp

36 lines
1.1 KiB
C++

// SDK
#include "cJSON.h"
#include "esp_http_server.h"
// Project
#include "appstate.hpp"
#include "types.hpp"
internal esp_err_t api_ota_status_handler(httpd_req_t *req)
{
httpd_resp_set_type(req, "application/json");
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
cJSON *root = cJSON_CreateObject();
cJSON_AddNumberToObject(root, "active_slot", g_Active_WWW_Partition);
cJSON_AddStringToObject(root, "active_partition",
g_Active_WWW_Partition == 0 ? "www_0" : "www_1");
cJSON_AddStringToObject(root, "target_partition",
g_Active_WWW_Partition == 0 ? "www_1" : "www_0");
const char *status_info = cJSON_Print(root);
httpd_resp_sendstr(req, status_info);
free((void *)status_info);
cJSON_Delete(root);
return ESP_OK;
}
internal const httpd_uri_t api_ota_status_uri = {.uri = "/api/ota/status",
.method = HTTP_GET,
.handler =
api_ota_status_handler,
.user_ctx = NULL};