feat: Implement web dashboard with system information, reboot, and OTA update functionality.

This commit is contained in:
2026-03-03 22:17:58 -05:00
parent 849d126ce0
commit fdb13d62d4
8 changed files with 547 additions and 253 deletions

View File

@@ -3,14 +3,14 @@
// SDK
#include "esp_log.h"
#include "esp_ota_ops.h"
#include "esp_system.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "nvs.h"
#include "nvs_flash.h"
#include "sdkconfig.h"
#include "soc/gpio_num.h"
// Project headers
#include "appstate.hpp"
#include "types.hpp"
@@ -26,7 +26,7 @@ internal constexpr bool kBlockUntilEthernetEstablished = false;
extern "C" void app_main()
{
printf("Hello, Worldi!\n");
printf("Hello, Calendink OTA! [V1.1]\n");
httpd_handle_t web_server = NULL;
@@ -41,11 +41,27 @@ extern "C" void app_main()
nvs_handle_t my_handle;
if (nvs_open("storage", NVS_READWRITE, &my_handle) == ESP_OK)
{
err = nvs_get_u8(my_handle, "www_part", &g_Active_WWW_Partition);
if (err != ESP_OK && err != ESP_ERR_NVS_NOT_FOUND)
// If we are running from the factory partition, force the www partition to
// 0 This ensures that after a USB flash (which only writes to www_0), we
// aren't stuck looking at an old www_1.
const esp_partition_t *running = esp_ota_get_running_partition();
if (running && running->subtype == ESP_PARTITION_SUBTYPE_APP_FACTORY)
{
printf("Error reading www_part from NVS: %s\n", esp_err_to_name(err));
printf(
"Running from factory: resetting www_part to 0 for consistency.\n");
g_Active_WWW_Partition = 0;
nvs_set_u8(my_handle, "www_part", 0);
nvs_commit(my_handle);
}
else
{
err = nvs_get_u8(my_handle, "www_part", &g_Active_WWW_Partition);
if (err != ESP_OK && err != ESP_ERR_NVS_NOT_FOUND)
{
printf("Error reading www_part from NVS: %s\n", esp_err_to_name(err));
}
}
if (g_Active_WWW_Partition > 1)
{
g_Active_WWW_Partition = 0;
@@ -151,6 +167,9 @@ extern "C" void app_main()
printf("Connected!\n");
// Mark the current app as valid to cancel rollback
esp_ota_mark_app_valid_cancel_rollback();
// Start the webserver
web_server = start_webserver();