feat: Implement HTTP server with static file serving from LittleFS, system APIs, and network connectivity management.
This commit is contained in:
@@ -8,7 +8,7 @@ idf_component_register(SRCS "main.cpp"
|
||||
if(CONFIG_CALENDINK_DEPLOY_WEB_PAGES)
|
||||
set(WEB_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../frontend")
|
||||
if(EXISTS ${WEB_SRC_DIR}/dist)
|
||||
littlefs_create_partition_image(www ${WEB_SRC_DIR}/dist FLASH_IN_PROJECT)
|
||||
littlefs_create_partition_image(www_0 ${WEB_SRC_DIR}/dist FLASH_IN_PROJECT)
|
||||
else()
|
||||
message(FATAL_ERROR "'${WEB_SRC_DIR}/dist' doesn't exist. Run 'npm run build' in frontend/ first.")
|
||||
endif()
|
||||
|
||||
@@ -5,3 +5,4 @@
|
||||
// Shared Application State (Unity Build)
|
||||
internal bool g_Ethernet_Initialized = false;
|
||||
internal bool g_Wifi_Initialized = false;
|
||||
internal uint8_t g_Active_WWW_Partition = 0;
|
||||
|
||||
@@ -178,7 +178,7 @@ internal httpd_handle_t start_webserver(void)
|
||||
#ifdef CONFIG_CALENDINK_DEPLOY_WEB_PAGES
|
||||
esp_vfs_littlefs_conf_t conf = {};
|
||||
conf.base_path = "/www";
|
||||
conf.partition_label = "www";
|
||||
conf.partition_label = g_Active_WWW_Partition == 0 ? "www_0" : "www_1";
|
||||
conf.format_if_mount_failed = false;
|
||||
conf.dont_mount = false;
|
||||
esp_err_t ret = esp_vfs_littlefs_register(&conf);
|
||||
@@ -253,7 +253,8 @@ internal void stop_webserver(httpd_handle_t server)
|
||||
{
|
||||
httpd_stop(server);
|
||||
#ifdef CONFIG_CALENDINK_DEPLOY_WEB_PAGES
|
||||
esp_vfs_littlefs_unregister("www");
|
||||
esp_vfs_littlefs_unregister(g_Active_WWW_Partition == 0 ? "www_0"
|
||||
: "www_1");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,12 @@
|
||||
#include "esp_log.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"
|
||||
@@ -28,7 +30,33 @@ extern "C" void app_main()
|
||||
|
||||
httpd_handle_t web_server = NULL;
|
||||
|
||||
ESP_ERROR_CHECK(nvs_flash_init());
|
||||
esp_err_t err = nvs_flash_init();
|
||||
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND)
|
||||
{
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
err = nvs_flash_init();
|
||||
}
|
||||
ESP_ERROR_CHECK(err);
|
||||
|
||||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
nvs_close(my_handle);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Error opening NVS handle!\n");
|
||||
}
|
||||
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
|
||||
setup_led();
|
||||
|
||||
Reference in New Issue
Block a user