Made everything needed to update firmware. Added the bundle to upload both front and backendin a bundle. Added magic number for more safety

This commit is contained in:
2026-03-03 22:45:41 -05:00
parent fdb13d62d4
commit 85dc698a8d
17 changed files with 467 additions and 44 deletions

View File

@@ -3,9 +3,13 @@
// SDK
#include "cJSON.h"
#include "esp_http_server.h"
#include "esp_image_format.h"
#include "esp_littlefs.h"
#include "esp_log.h"
#include "esp_ota_ops.h"
#include "esp_partition.h"
#include "esp_vfs.h"
#include <string.h>
// Project
#include "appstate.hpp"
@@ -58,11 +62,16 @@ internal esp_err_t api_ota_status_handler(httpd_req_t *req)
esp_app_desc_t app_desc;
if (esp_ota_get_partition_description(p, &app_desc) == ESP_OK)
{
// This is a bit of a hack as we don't have a direct "binary size" in
// the header but we can at least show it's occupied. For simplicity, if
// it's a valid app, we'll mark some space as used. Actually, without a
// better way to get the exact bin size, we'll just show it's an App.
cJSON_AddStringToObject(p_obj, "app_version", app_desc.version);
// Get the true binary size from image metadata
esp_image_metadata_t data;
const esp_partition_pos_t pos = {.offset = p->address, .size = p->size};
if (esp_image_get_metadata(&pos, &data) == ESP_OK)
{
cJSON_AddNumberToObject(p_obj, "used", data.image_len);
cJSON_AddNumberToObject(p_obj, "free", p->size - data.image_len);
}
}
}