From 6ac09966ba7871527593a016491829972bfd1139 Mon Sep 17 00:00:00 2001 From: Sergey Lyubka Date: Fri, 22 Oct 2021 22:06:10 +0100 Subject: [PATCH] Fix #1374 - fix ESP32 build --- examples/esp32/main/main.c | 21 ++++++++++++++------- examples/esp32/sdkconfig.defaults | 1 + mongoose.h | 3 +-- src/arch_esp32.h | 6 +++--- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/examples/esp32/main/main.c b/examples/esp32/main/main.c index 4d508f4f..3727ef9c 100644 --- a/examples/esp32/main/main.c +++ b/examples/esp32/main/main.c @@ -9,6 +9,14 @@ #define WIFI_PASS "WIFI_PASSWORD" // SET THIS! #define FS_ROOT "/spiffs" +// SPIFFS is flat, so tell Mongoose that the FS root is a directory +// This cludge is not required for filesystems with directory support +static int my_stat(const char *path, size_t *size, time_t *mtime) { + int flags = mg_fs_posix.stat(path, size, mtime); + if (strcmp(path, FS_ROOT) == 0) flags |= MG_FS_DIR; + return flags; +} + // Event handler for an server (accepted) connection. Implemented endpoints: // /api/stats - return JSON object with ESP32 stats (free RAM) // any other - serve files from the filesystem @@ -18,18 +26,17 @@ static void cb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { if (mg_http_match_uri(hm, "/api/stats")) { mg_http_reply(c, 200, "", "{\"ram\": %lu}\n", xPortGetFreeHeapSize()); } else { - struct mg_http_serve_opts opts = {.root_dir = FS_ROOT}; + // mg_http_reply(c, 404, "", "Not found: %d\n", MG_PATH_MAX); + // return; + struct mg_fs fs = mg_fs_posix; + fs.stat = my_stat; + struct mg_http_serve_opts opts = {.root_dir = FS_ROOT, .fs = &fs}; + // opts.fs = NULL; mg_http_serve_dir(c, hm, &opts); } } } -// SPIFFS is flat, so tell Mongoose that the FS root is a directory -// This cludge is not required for filesystems with directory support -bool mg_is_dir(const char *path) { - return strcmp(path, FS_ROOT) == 0; -} - void app_main(void) { // Mount filesystem esp_vfs_spiffs_conf_t conf = { diff --git a/examples/esp32/sdkconfig.defaults b/examples/esp32/sdkconfig.defaults index 8ff365b1..607180e5 100644 --- a/examples/esp32/sdkconfig.defaults +++ b/examples/esp32/sdkconfig.defaults @@ -1,3 +1,4 @@ CONFIG_PARTITION_TABLE_CUSTOM=y CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv" CONFIG_PARTITION_TABLE_FILENAME="partitions.csv" +#CONFIG_ESP_MAIN_TASK_STACK_SIZE=8192 diff --git a/mongoose.h b/mongoose.h index f0b36538..02b73ae0 100644 --- a/mongoose.h +++ b/mongoose.h @@ -199,9 +199,8 @@ static __inline struct tm *localtime_r(time_t *t, struct tm *tm) { #define MG_DIRSEP '/' #define MG_INT64_FMT "%lld" -#ifndef MG_PATH_MAX +#undef MG_PATH_MAX #define MG_PATH_MAX 128 -#endif #undef MG_ENABLE_DIRLIST #define MG_ENABLE_DIRLIST 1 diff --git a/src/arch_esp32.h b/src/arch_esp32.h index 92f5a103..650880a8 100644 --- a/src/arch_esp32.h +++ b/src/arch_esp32.h @@ -17,12 +17,12 @@ #include #include +#undef MG_PATH_MAX +#undef MG_ENABLE_DIRLIST + #define MG_DIRSEP '/' #define MG_INT64_FMT "%lld" -#ifndef MG_PATH_MAX #define MG_PATH_MAX 128 -#endif -#undef MG_ENABLE_DIRLIST #define MG_ENABLE_DIRLIST 1 #endif