Squashed commit of the following:
commite8b53dc953Author: Patedam <pgillen.pro@gmail.com> Date: Tue Mar 3 01:15:17 2026 -0500 Updated backend to make sure it works properly with frontend. Fixed one frontend issue (free heap was not correctly named) commit3428808f83Author: Patedam <pgillen.pro@gmail.com> Date: Tue Mar 3 00:36:01 2026 -0500 Fixing various build errors. Activated minimal build commit59364ac22dAuthor: Patedam <pgillen.pro@gmail.com> Date: Tue Mar 3 00:03:24 2026 -0500 Added info and reboot api into the backend. Created the basics for a backend server. commit37291557ebAuthor: Patedam <pgillen.pro@gmail.com> Date: Mon Mar 2 23:05:10 2026 -0500 feat: Add API endpoints for system reboot and retrieving system information. commita010b0c352Author: Patedam <pgillen.pro@gmail.com> Date: Mon Mar 2 22:56:13 2026 -0500 Added AgentTasks into git ignore we will use it to store current tasks so we can createnew contexts chat when its too big commit75bab78137Author: Patedam <pgillen.pro@gmail.com> Date: Mon Mar 2 22:42:29 2026 -0500 feat: Initialize ESP-IDF project with core build configuration, component dependencies, and web frontend deployment. commitbba4c63f93Author: Patedam <pgillen.pro@gmail.com> Date: Mon Mar 2 22:21:52 2026 -0500 docs: Add backend architecture documentation for the ESP32-S3 provider.
This commit is contained in:
66
Provider/main/api/system/info.cpp
Normal file
66
Provider/main/api/system/info.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
// SDK
|
||||
#include "cJSON.h"
|
||||
#include "esp_app_format.h"
|
||||
#include "esp_chip_info.h"
|
||||
#include "esp_http_server.h"
|
||||
#include "esp_ota_ops.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_timer.h"
|
||||
|
||||
// Project
|
||||
#include "appstate.hpp"
|
||||
#include "types.hpp"
|
||||
|
||||
internal esp_err_t api_system_info_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();
|
||||
|
||||
esp_chip_info_t chip_info;
|
||||
esp_chip_info(&chip_info);
|
||||
|
||||
const char *model = "ESP32-S3";
|
||||
if (chip_info.model == CHIP_ESP32) {
|
||||
model = "ESP32";
|
||||
} else if (chip_info.model == CHIP_ESP32S2) {
|
||||
model = "ESP32-S2";
|
||||
} else if (chip_info.model == CHIP_ESP32S3) {
|
||||
model = "ESP32-S3";
|
||||
} else if (chip_info.model == CHIP_ESP32C3) {
|
||||
model = "ESP32-C3";
|
||||
}
|
||||
|
||||
cJSON_AddStringToObject(root, "chip", model);
|
||||
|
||||
uint32_t free_heap = esp_get_free_heap_size();
|
||||
cJSON_AddNumberToObject(root, "free_heap", free_heap);
|
||||
|
||||
uint64_t uptime_sec = esp_timer_get_time() / 1000000;
|
||||
cJSON_AddNumberToObject(root, "uptime", uptime_sec);
|
||||
|
||||
const esp_app_desc_t *app_desc = esp_app_get_description();
|
||||
cJSON_AddStringToObject(root, "firmware", app_desc->version);
|
||||
|
||||
const char *conn_type = "offline";
|
||||
if (g_Ethernet_Initialized) {
|
||||
conn_type = "ethernet";
|
||||
} else if (g_Wifi_Initialized) {
|
||||
conn_type = "wifi";
|
||||
}
|
||||
cJSON_AddStringToObject(root, "connection", conn_type);
|
||||
|
||||
const char *sys_info = cJSON_Print(root);
|
||||
httpd_resp_sendstr(req, sys_info);
|
||||
|
||||
free((void *)sys_info);
|
||||
cJSON_Delete(root);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
internal const httpd_uri_t api_system_info_uri = {.uri = "/api/system/info",
|
||||
.method = HTTP_GET,
|
||||
.handler =
|
||||
api_system_info_handler,
|
||||
.user_ctx = NULL};
|
||||
43
Provider/main/api/system/reboot.cpp
Normal file
43
Provider/main/api/system/reboot.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include "cJSON.h"
|
||||
#include "esp_http_server.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_timer.h"
|
||||
|
||||
#include "types.hpp"
|
||||
|
||||
internal void restart_timer_callback(void *arg) { esp_restart(); }
|
||||
|
||||
internal esp_err_t api_system_reboot_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_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",
|
||||
.skip_unhandled_events = false};
|
||||
esp_timer_handle_t restart_timer;
|
||||
esp_timer_create(&restart_timer_args, &restart_timer);
|
||||
|
||||
// Schedule reboot 1 second (in microseconds) from now to allow HTTP response
|
||||
// to flush
|
||||
esp_timer_start_once(restart_timer, 1'000'000);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
internal const httpd_uri_t api_system_reboot_uri = {
|
||||
.uri = "/api/system/reboot",
|
||||
.method = HTTP_POST,
|
||||
.handler = api_system_reboot_handler,
|
||||
.user_ctx = NULL};
|
||||
Reference in New Issue
Block a user