-
My goal is: to set up a mongoose webserver on the esp32 in c++ with direcory listening
-
My actions are:
if (ev == MG_EV_HTTP_MSG) { struct mg_http_message *hm = (struct mg_http_message *) ev_data; if (mg_http_match_uri(hm, "/api/config/get")) { ESP_LOGD(LOG_TAG, "api/config/get"); char *s = stringify_config(&s_config); mg_printf(c, "HTTP/1.1 200 OK\r\nContent-Length: %d\r\n\r\n%s\n", (int) strlen(s) + 1, s); free(s); } else if (mg_http_match_uri(hm, "/api/config/set")) { ESP_LOGD(LOG_TAG, "/api/config/set"); if (update_config(hm, &s_config)) notify_config_change((struct mg_mgr*) fn_data); mg_printf(c, "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"); } else if (mg_http_match_uri(hm, "/api/config/watch")) { ESP_LOGD(LOG_TAG, "/api/config/watch"); c->label[0] = 'W'; // Mark ourselves as a config watcher mg_printf(c, "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"); } else { ESP_LOGD(LOG_TAG, "else"); struct mg_http_serve_opts opts = {.root_dir = "/www"}; //mg_http_serve_file(c, (struct mg_http_message*) ev_data, "/www/index.html", "text/html", "AA: bb\r\nCC: dd\r\n"); mg_http_serve_dir(c, (struct mg_http_message*) ev_data, &opts); } }
I serve a web directory (www) but the files are not available in the mongoose context.
To be sure the files are available I did the following:
FileSystem *file = new FileSystem();
std::vector<File> test = file->getDirectoryContents("/www");
for(int i = 0; i < test.size(); i++) {
cout << test[i].getName();
}
-
The result I see is: The output returns all filename, so they are available at the filesystem.
I tried to do this with mg_http_serve_dir but it didn’t work. -
My expectation & question is: Whats going wrong and why can’t mongoose find the files on the server? Can someone help me?