Mongoose on Nuttx RTOS - serving static files from FS #1439
-
I want to try mongoose web server on Nuttx. When run program getting following error in screen: NuttShell (NSH) NuttX-10.2.0 on web browser (192.168.1.67), instead of index.html file getting response Index of /Name | Modified | Size Mongoose v.7.5OK, mongoose see files on directory /www but can't read and submit to client index.html, instead sending something else. Problem is, mongoose can't read properly files from spiffs (flat filesystem). |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Mongoose uses "virtual" file system API to access files. By default, it implements a POSIX interface, and a "packed" interface. User can implement its own custom interface, using whatever filesystem available. The filesystem interface can be specified as a So, the answer to your question is: implement your own custom filesystem API, and specify it in the mongoose/examples/esp32/main/main.c Lines 29 to 32 in 2000752 Your source code should look like this: static int my_stat(const char *path, size_t *size, time_t *mtime) {
...
}
static void my_list(const char *path, void (*fn)(const char *, void *), void *userdata) {
...
}
static void *my_open(const char *path, int flags) {
...
}
static void my_close(void *fd) {
...
}
static size_t my_read(void *fd, void *buf, size_t len) {
...
}
static size_t my_write(void *fd, const void *buf, size_t len) {
...
}
static size_t my_seek(void *fd, size_t offset) {
...
}
static void cb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = ev_data;
struct mg_fs fs = {my_stat, my_list, my_open, my_close, my_read, my_write, my_seek};
struct mg_http_serve_opts opts = {.root_dir = "/www", .fs = &fs};
mg_http_serve_dir(c, hm, &opts);
}
} |
Beta Was this translation helpful? Give feedback.
Mongoose uses "virtual" file system API to access files. By default, it implements a POSIX interface, and a "packed" interface. User can implement its own custom interface, using whatever filesystem available. The filesystem interface can be specified as a
struct mg_http_serve_opt :: fs
member. If it is left as NULL, then whatever available API is used (which is POSIX).So, the answer to your question is: implement your own custom filesystem API, and specify it in the
struct mg_http_serve_opts
. You can take a look at the example atmongoose/examples/esp32/main/main.c
Lines 29 to 32 in 2000752