diff --git a/components/protocols/CMakeLists.txt b/components/protocols/CMakeLists.txt index 7e2360e..997b1b2 100755 --- a/components/protocols/CMakeLists.txt +++ b/components/protocols/CMakeLists.txt @@ -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() diff --git a/components/protocols/include/rest.h b/components/protocols/include/rest.h index aa14d86..2cd390d 100755 --- a/components/protocols/include/rest.h +++ b/components/protocols/include/rest.h @@ -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_ */ diff --git a/components/protocols/src/protocols.c b/components/protocols/src/protocols.c index 0748fe1..173a289 100755 --- a/components/protocols/src/protocols.c +++ b/components/protocols/src/protocols.c @@ -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(); } \ No newline at end of file diff --git a/components/protocols/src/rest.c b/components/protocols/src/rest.c index 0a8dbc4..be60663 100755 --- a/components/protocols/src/rest.c +++ b/components/protocols/src/rest.c @@ -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, ...) \