Looking for an mg_http_serve_* example ESP8266_RTOS_SDK

I have of course looked at examples/esp8266, which only contains mg_http_reply(c, 200, “”, “Hello from ESP!\n”);, but now I would need to find a working example code using mg_http_serve_dir(c, ev_data, &opts); (or mg_http_serve_file()), like used in examples/http-server.

One SPIFFS specific pitfall I did figure out, the mg_is_dir(), so this is not “invalid web root” issue. This is something else…

I get core panic (LoadProhibited) using either of the functions mentioned above. However, if I manually read the file content, I can serve it with mg_http_reply() just fine. mg_http_serve_file() and mg_http_serve_dir() crash, no matter what I try.

Is there a working example of either being used with ESP8266_RTOS_SDK from which I could try to read what is it that I did not yet discover?

Adding the error here, although I cannot believe there would be a problem like this in the server.

Guru Meditation Error: Core 0 panic’ed (LoadProhibited). Exception was unhandled.
Core 0 register dump:
PC : 0x402629fc PS : 0x00000030 A0 : 0x40228e5d A1 : 0x3fff45d0
0x402629fc: memchr at /builds/idf/crosstool-NG/.build/xtensa-lx106-elf/src/newlib/newlib/libc/string/memchr.c:120

0x40228e5d: _printf_i at /builds/idf/crosstool-NG/.build/xtensa-lx106-elf/src/newlib/newlib/libc/stdio/nano-vfprintf_i.c:221

A2 : 0x000000ab A3 : 0x00000000 A4 : 0x000000aa A5 : 0x402283bc
0x402283bc: __ssputs_r at /builds/idf/crosstool-NG/.build/xtensa-lx106-elf/src/newlib/newlib/libc/stdio/nano-vfprintf.c:179

A6 : 0x3fff4680 A7 : 0x00000000 A8 : 0x3fff4663 A9 : 0x3fff4808
A10 : 0x4027adba A11 : 0x00000064 A12 : 0x000000ab A13 : 0x3fff46d0
A14 : 0x402283bc A15 : 0x3fff4620 SAR : 0x0000001f EXCCAUSE: 0x0000001c
0x402283bc: __ssputs_r at /builds/idf/crosstool-NG/.build/xtensa-lx106-elf/src/newlib/newlib/libc/stdio/nano-vfprintf.c:179

Backtrace: 0x402629fc:0x3fff45d0 0x40228e5d:0x3fff45d0 0x40228738:0x3fff4620 0x4022a7b9:0x3fff46d0 0x4022a80d:0x3fff4750 0x4022524d:0x3fff4780 0x40225fc8:0x3fff47b0 Guru Meditation Error: Core 0 panic’ed (LoadStoreAlignment). Exception was unhandled.
0x402629fc: memchr at /builds/idf/crosstool-NG/.build/xtensa-lx106-elf/src/newlib/newlib/libc/string/memchr.c:120

0x40228e5d: _printf_i at /builds/idf/crosstool-NG/.build/xtensa-lx106-elf/src/newlib/newlib/libc/stdio/nano-vfprintf_i.c:221

0x40228738: _svfprintf_r at /builds/idf/crosstool-NG/.build/xtensa-lx106-elf/src/newlib/newlib/libc/stdio/nano-vfprintf.c:636

0x4022a7b9: _vsnprintf_r at /builds/idf/crosstool-NG/.build/xtensa-lx106-elf/src/newlib/newlib/libc/stdio/vsnprintf.c:71 (discriminator 4)

0x4022a80d: vsnprintf at /builds/idf/crosstool-NG/.build/xtensa-lx106-elf/src/newlib/newlib/libc/stdio/vsnprintf.c:41

0x4022524d: mg_vasprintf at /home/esp/esp/RoyalMarine/components/mongoose/mongoose.c:4103

0x40225fc8: mg_vprintf at /home/esp/esp/RoyalMarine/components/mongoose/mongoose.c:2129

Core 0 register dump:
PC : 0x4023d349 PS : 0x00000033 A0 : 0x4023d2bc A1 : 0x3ffea190
0x4023d349: xt_retaddr_callee at /home/esp/esp/ESP8266_RTOS_SDK/components/esp8266/source/backtrace.c:83

0x4023d2bc: xt_retaddr_callee at /home/esp/esp/ESP8266_RTOS_SDK/components/esp8266/source/backtrace.c:47

A2 : 0x00015fb8 A3 : 0x00000024 A4 : 0x3fff47e1 A5 : 0x3fff47dd
A6 : 0x000007fe A7 : 0x000000a1 A8 : 0x000000c0 A9 : 0x3fff4808
A10 : 0x4027adba A11 : 0x00000064 A12 : 0x40225fc8 A13 : 0x3ffea1d0
0x40225fc8: mg_vprintf at /home/esp/esp/RoyalMarine/components/mongoose/mongoose.c:2129

A14 : 0x40228e5d A15 : 0x40228e5d SAR : 0x0000001f EXCCAUSE: 0x00000009
0x40228e5d: _printf_i at /builds/idf/crosstool-NG/.build/xtensa-lx106-elf/src/newlib/newlib/libc/stdio/nano-vfprintf_i.c:221

0x40228e5d: _printf_i at /builds/idf/crosstool-NG/.build/xtensa-lx106-elf/src/newlib/newlib/libc/stdio/nano-vfprintf_i.c:221

Backtrace: 0x4023d349:0x3ffea190 0x4021fdc7:0x3ffea1c0 0x40100c78:0x3ffea210 0x4023d2bc:0x3ffea230
0x4023d349: xt_retaddr_callee at /home/esp/esp/ESP8266_RTOS_SDK/components/esp8266/source/backtrace.c:83

0x4021fdc7: panic_frame at /home/esp/esp/ESP8266_RTOS_SDK/components/freertos/port/esp8266/panic.c:109
(inlined by) panicHandler at /home/esp/esp/ESP8266_RTOS_SDK/components/freertos/port/esp8266/panic.c:168

0x40100c78: _heap_caps_malloc at /home/esp/esp/ESP8266_RTOS_SDK/components/heap/src/esp_heap_caps.c:98

0x4023d2bc: xt_retaddr_callee at /home/esp/esp/ESP8266_RTOS_SDK/components/esp8266/source/backtrace.c:47

Code is (practically what is found in general examples):

static void http_server_handler(
struct mg_connection *conn,
int ev,
void *ev_data,
void *fn_data
)
{
if (ev == MG_EV_HTTP_MSG)
{
struct mg_http_message *hm = (struct mg_http_message *)ev_data;
struct mg_http_serve_opts opts = {
.root_dir = cfg.webroot,
.ssi_pattern = NULL,
.extra_headers = NULL
};
mg_http_serve_dir(conn, hm, &opts); // BOOM!
}
}

Webroot (SPIFFS mount point) is “/html” and if request URI points to a non-existing file, there is no crash (browser receives “Not found”). If requested file exists, it will crash.

Something SPIFFS specific that I should do?

AFAIK, SPIFFS is flat, i.e. no directories.

Yes, SPIFFS is flat and it does not have directories. However, SPIFFS partitions have mount points (the “directories” you see in the code). You cannot use SPIFFS without a mount point and the mount point cannot be the root.

I would be surprised if SPIFFS is the issue here, since the RTOS SDK included HTTPD works fine with the files. It just lacks almost all the features I would like to use, which is why I was trying to get Mongoose to work.

At this point, I am convinced that Mongoose no longer works for ESP8266_RTOS_SDK. Some changes along the way must have broken it, and guessing from the error message, this is likely an alignment error within the Mongoose code.

I was unable to find any Mongoose repositories for ESP8266, so I am dropping Mongoose (possibly also ESP8266 in favor of ESP32, which has a different SDK which is supposed to have websockets and all the stuff I need).