Merge pull request #1 from PlxEV/codex/corrigir-e-melhorar-componentes-rest

Fix REST initialization to serve web content
This commit is contained in:
2025-06-06 22:21:08 +01:00
committed by GitHub
4 changed files with 15 additions and 4 deletions

View File

@@ -10,3 +10,8 @@ idf_component_register(SRCS "${srcs}"
PRIV_INCLUDE_DIRS "src"
PRIV_REQUIRES nvs_flash esp_http_server esp_netif esp_https_ota app_update json mqtt vfs spiffs # Use spiffs aqui
REQUIRES config api logger)
set(WEB_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/webfolder")
if(EXISTS ${WEB_SRC_DIR})
spiffs_create_partition_image(data ${WEB_SRC_DIR} FLASH_IN_PROJECT)
endif()

View File

@@ -1,10 +1,14 @@
#ifndef REST_H_
#define REST_H_
#include "esp_err.h"
/**
* @brief Init rest server
*
* @brief Initialize REST server
*
* @param base_path Path on the SPIFFS filesystem where static files reside
* @return ESP_OK on success, ESP_FAIL otherwise
*/
void rest_init(void);
esp_err_t rest_init(const char *base_path);
#endif /* REST_H_ */

View File

@@ -7,7 +7,8 @@
void protocols_init(void)
{
date_time_init();
rest_init();
/* Serve static files from the SPIFFS data partition */
rest_init("/data");
//mqtt_init();
//modbus_tcp_init();
}

View File

@@ -14,6 +14,7 @@
#include "esp_log.h"
#include "esp_vfs.h"
#include "cJSON.h"
#include "rest.h"
static const char *REST_TAG = "esp-rest";
#define REST_CHECK(a, str, goto_tag, ...) \