Fix #1374 - fix ESP32 build

This commit is contained in:
Sergey Lyubka 2021-10-22 22:06:10 +01:00
parent af9a7617f5
commit 6ac09966ba
4 changed files with 19 additions and 12 deletions

View File

@ -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 = {

View File

@ -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

View File

@ -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

View File

@ -17,12 +17,12 @@
#include <sys/types.h>
#include <time.h>
#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