cesanta / mongoose

Embedded Web Server
https://mongoose.ws
Other
11.15k stars 2.73k forks source link

ESP8266 SPIFFS http file/dir server problem #1389

Closed tipeter closed 3 years ago

tipeter commented 3 years ago

Hello! I tested the fix on ESP8266. The directory listing now appears, but the files are missing from the list. (Empty list) The SPIFFS partition contains files (see the listing in the log). MCU still crashes.

Environment

My log:

Toolchain path: /home/ptihanyi/esp8266/xtensa-lx106-elf/bin/xtensa-lx106-elf-gcc
Toolchain version: esp-2020r3-49-gd5524c1
Compiler version: 8.4.0
Python requirements from /home/ptihanyi/esp8266/ESP8266_RTOS_SDK/requirements.txt are satisfied.
Project is not inside a git repository, or git repository has no commits
will not use 'git describe' to determine PROJECT_VER.
App "mongoose-example" version: 1
Flashing binaries to serial port /dev/ttyUSB0 (app at offset 0x10000)...
esptool.py v2.4.0
Connecting....
Chip is ESP8266EX
Features: WiFi
MAC: 80:7d:3a:75:d0:bf
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 921600
Changed.
Configuring flash size...
Compressed 10432 bytes to 7024...
Wrote 10432 bytes (7024 compressed) at 0x00000000 in 0.1 seconds (effective 1004.2 kbit/s)...
Hash of data verified.
Compressed 523152 bytes to 336280...
Wrote 523152 bytes (336280 compressed) at 0x00010000 in 29.9 seconds (effective 139.8 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 98...
Wrote 3072 bytes (98 compressed) at 0x00008000 in 0.0 seconds (effective 7779.6 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...
MONITOR
--- idf_monitor on /dev/ttyUSB0 74880 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---

 ets Jan  8 2013,rst cause:2, boot mode:(3,5)

load 0x40100000, len 7040, room 16 
tail 0
chksum 0xe2
load 0x3ffe8408, len 24, room 8 
tail 0
chksum 0x5b
load 0x3ffe8420, len 3324, room 8 
tail 4
chksum 0x7e
csum 0x7e
I (59) boot: ESP-IDF v3.4-49-g0f200b46 2nd stage bootloader
I (59) boot: compile time 18:46:23
I (68) qio_mode: Enabling default flash chip QIO
I (69) boot: SPI Speed      : 80MHz
I (73) boot: SPI Mode       : QIO
I (79) boot: SPI Flash Size : 1MB
I (85) boot: Partition Table:
I (91) boot: ## Label            Usage          Type ST Offset   Length
I (102) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (114) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (125) boot:  2 factory          factory app      00 00 00010000 000d0000
I (137) boot:  3 storage          Unknown data     01 82 000e0000 00020000
I (149) boot: End of partition table
I (155) esp_image: segment 0: paddr=0x00010010 vaddr=0x40210010 size=0x678f8 (424184) map
0x40210010: _stext at ??:?

I (291) esp_image: segment 1: paddr=0x00077910 vaddr=0x40277908 size=0x12584 ( 75140) map
I (314) esp_image: segment 2: paddr=0x00089e9c vaddr=0x3ffe8000 size=0x00674 (  1652) load
I (315) esp_image: segment 3: paddr=0x0008a518 vaddr=0x40100000 size=0x00080 (   128) load
I (325) esp_image: segment 4: paddr=0x0008a5a0 vaddr=0x40100080 size=0x055c8 ( 21960) load
I (344) boot: Loaded app from partition at offset 0x10000
I (367) system_api: Base MAC address is not set, read default base MAC address from EFUSE
I (369) system_api: Base MAC address is not set, read default base MAC address from EFUSE
phy_version: 1166.0, 7f5855b, Aug 19 2021, 15:51:14, RTOS new
I (431) phy_init: phy ver: 1166_0
I (564) wifi:state: 0 -> 2 (b0)
I (567) wifi:state: 2 -> 3 (0)
I (570) wifi:state: 3 -> 5 (10)
I (581) wifi:connected with Petra&Peter2G, aid = 2, channel 10, HT20, bssid = b0:4e:26:bb:d6:44
I (1359) tcpip_adapter: sta ip: 192.168.8.199, mask: 255.255.255.0, gw: 192.168.8.1
1970-01-01 00:00:01 2 wifi.c:43:event_handler    got ip:192.168.8.199
1970-01-01 00:00:01 2 wifi.c:74:wifi_init        connected to ap SSID:Petra&Peter2G password:Gzp%vQ59?r
I (1381) MAIN: Initialize hw_timer for callback1
I (1389) MAIN: Set hw_timer timing time 1000us with reload
I (1398) fs: Initializing SPIFFS
I (1409) fs: Partition size: total: 113201, used: 7279

List of Directory [/spiffs]
-----------------------------------
T  Size      Date/Time         Name
-----------------------------------
f      1150  01/01/1970 00:00  favicon.ico
f       950  01/01/1970 00:00  chat.html
f      4105  01/01/1970 00:00  chat-client.js
-----------------------------------
       6205 in 3 file(s)
-----------------------------------
SPIFFS: free 103 KB of 110 KB
-----------------------------------

1970-01-01 00:00:01 2 mongoose.c:3337:mg_listen  1 accepting on http://0.0.0.0:80 (port 80)
1970-01-01 00:00:01 2 main.c:126:run_mongoose    Starting Mongoose web server v7.4
1970-01-01 00:00:34 3 mongoose.c:3242:accept_con 2 accepted 192.168.8.192:60364
1970-01-01 00:00:34 3 mongoose.c:1513:mg_http_se / /spiffs 4
1970-01-01 00:00:34 3 mongoose.c:3242:accept_con 3 accepted 192.168.8.192:60366
1970-01-01 00:00:34 3 mongoose.c:1513:mg_http_se /favicon.ico /spiffs/favicon.ico 3
Guru Meditation Error: Core  0 panic'ed (LoadProhibited). Exception was unhandled.
Core 0 register dump:
PC      : 0x40265024  PS      : 0x00000030  A0      : 0x4022a0fd  A1      : 0x3fff74a0  
0x40265024: memchr at /builds/idf/crosstool-NG/.build/xtensa-lx106-elf/src/newlib/newlib/libc/string/memchr.c:120

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

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

A6      : 0x3fff7550  A7      : 0x00000000  A8      : 0x3fff7533  A9      : 0x3fff76cc  
A10     : 0x4027d34c  A11     : 0x00000064  A12     : 0x00000000  A13     : 0x3fff75a0  
A14     : 0x4022965c  A15     : 0x3fff74f0  SAR     : 0x0000001f  EXCCAUSE: 0x0000001c  
0x4022965c: __ssputs_r at /builds/idf/crosstool-NG/.build/xtensa-lx106-elf/src/newlib/newlib/libc/stdio/nano-vfprintf.c:179

Backtrace: 0x40265024:0x3fff74a0 0x4022a0fd:0x3fff74a0 0x402299d8:0x3fff74f0 0x4022bd25:0x3fff75a0 0x4022bd79:0x3fff7620 0x40224ed1:0x3fff7650 0x40225fd0:0x3fff7680 Guru Meditation Error: Core  0 panic'ed (LoadStoreAlignment). Exception was unhandled.
0x40265024: memchr at /builds/idf/crosstool-NG/.build/xtensa-lx106-elf/src/newlib/newlib/libc/string/memchr.c:120

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

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

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

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

0x40224ed1: mg_vasprintf at /home/ptihanyi/esp8266/workspace/mongoose_example/main/mongoose.c:4378

0x40225fd0: mg_vprintf at /home/ptihanyi/esp8266/workspace/mongoose_example/main/mongoose.c:2357

Core 0 register dump:
PC      : 0x4023f775  PS      : 0x00000033  A0      : 0x4023f6e8  A1      : 0x3ffea1e0  
0x4023f775: xt_retaddr_callee at /home/ptihanyi/esp8266/ESP8266_RTOS_SDK/components/esp8266/source/backtrace.c:83

0x4023f6e8: xt_retaddr_callee at /home/ptihanyi/esp8266/ESP8266_RTOS_SDK/components/esp8266/source/backtrace.c:47

A2      : 0x00015fc0  A3      : 0x00000024  A4      : 0x3fff76b1  A5      : 0x3fff76ad  
A6      : 0x000007fe  A7      : 0x000000a1  A8      : 0x000000c0  A9      : 0x3fff76cc  
A10     : 0x4027d34c  A11     : 0x00000064  A12     : 0x40225fd0  A13     : 0x3ffea220  
0x40225fd0: mg_vprintf at /home/ptihanyi/esp8266/workspace/mongoose_example/main/mongoose.c:2357

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

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

Backtrace: 0x4023f775:0x3ffea1e0 0x4021fde7:0x3ffea210 0x40100c80:0x3ffea260 0x4023f6e8:0x3ffea280 
0x4023f775: xt_retaddr_callee at /home/ptihanyi/esp8266/ESP8266_RTOS_SDK/components/esp8266/source/backtrace.c:83

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

0x40100c80: _heap_caps_malloc at /home/ptihanyi/esp8266/ESP8266_RTOS_SDK/components/heap/src/esp_heap_caps.c:98

0x4023f6e8: xt_retaddr_callee at /home/ptihanyi/esp8266/ESP8266_RTOS_SDK/components/esp8266/source/backtrace.c:47

��*�P*V��ET����T��K��u�U+UZ���T��T
                                  ����ŪTQT�QQ��jPE*��u�����ZT�(E����Q�UEu�����*�B����B�u��E+��TT)UZV���Eu����ŪQB���U�*�u���ZT�(UE����QV�E�j*QV�E��UU�QUU���Z�U�**P�+U���UETT��T�+V
�u�u�UZ��UE��UU�QUU���Z�UX��i�UP��U�U��UE��UU�Q,U�Vu�ե��ԢJ��(U�j*
                                                                 UZ�)UX��UUU�TU�U��T��u�
                                                                                        UTU�UT���
                                                                                                 �UT�UU�TU�U��T��u�
                                                                                                                   UTU+UP���
                                                                                                                            ��UUU�TU�U��T�*�u�
                                                                                                                                              UT�Z�UU���UJU�TU�U��T�*�u�
                                                                                                                                                                        Q�����(*RUZ��UE��UU�Q��u�
                                                                                                                                                                                                 �
�T��(�������UP�����.�U�]UZJP�UV����UE��UU�QTU�u�
                                                ���-��������R��������Q�Q�Q�QQE�U�TU�U��T��B�u�
                                                                                              �
�ծժ
   ����U)���������Q
QQUQ�QQ��U�TU�U��T�UB�u�
                        ��UR�Z�����R�ZE,P��Q�QQQ�QQQEQ��UE��UU�Q���u�
                                                                     ��-�ZԪ������UV�V�����Q
��Q�QQQEQ��UE��UU�QT�*�u�
                         �+��P�K����ZTT�UU�TU�U��T�UB�X��V���VU�ZQ
                                                                  ��T�Q(Q�TQ��T�QTU�TQ�U��\��XQ����U(JU�����UUP�UU-�UV���VU�Z�
                                                                                                                              ��T�Q(Q�VQ��T�QTU���U��\�*�Q�U�E*U(JU�����UUP��*U-�UV���VU�ZU
                                                                                                                                                                                           ��T�Q(Q�����T�Q���Q�U��\Q�*Q(�UU�T��UE��UU�QUU*U-�UV���VU�ZU
                                  ��T�Q(QE����T�QT�QQ����Q(QQQ(���B�T��UE��UU�QUUU-�UV���VU�Z�
                                                                                              ��T�Q(QE�(��T�QT�Q�����Q�U��BU�E*�T��UE��UU�QUUU���Z�TJPXU몱T������]UZJPqQQ��U�I
cpq commented 3 years ago

Why not figuring it out and creating a PR ?

Did you reduce max PATH for ESP8266 the same way was done on ESP32? Reducing max path prevented stack overflow on ESP32.

tipeter commented 3 years ago

Thanks for the idea, I will look into it. Although with ESP8266 it is an additional complication that the only somewhat working debug solution is printf. I have tried JTAG, it works for the most part but in practice it is not very useful.

Why not figuring it out and creating a PR ?

You're right, but I've only been working with ESP8266 for a few weeks and the documentation for the platform is inadequate to say the least. I develop primarily on STM32, it's a whole different world. My biggest problem with the ESP8266 is that I don't know which SDK to use in the long run. I would like to develop on it at least approximately like I did on the STM32. I am currently trying ESP8266_RTOS_SDK and the SMING Framework. I favor the former because of FreeRTOS, but Espressif doesn't really keep it up anymore. Perhaps you as an experienced developer would recommend? ESP32 is currently out of the question, I need to find a solution for ESP8266. Many thanks!

cpq commented 3 years ago

@tipeter thanks for the context.

For ESP8266, there are historically two SDKs: a baremetal non-OS and FreeRTOS-based. Espressif supports only the 2nd one, FreeRTOS based, in the long run. However many projects (like arduino infrastructure for ESP8266) are still on non-OS due to various reasons.

So to answer your question: on ESP8266, an rtos-based SDK should be used. SMING is nonOS based, and from a first glance, looks kinda familiar to Mongoose OS, another product of ours. If you plan to use a framework, take a look at mongoose os.

tipeter commented 3 years ago

@cpq Thanks a lot for the advice!

cpq commented 3 years ago

@tipeter Out of curiosity, could you elaborate on why to switch from STM32 line to ESP8266? ST provides its own connectivity options.

tipeter commented 3 years ago

I have not changed at all! However, I have a project I need to solve with EPS8266. Basically, the ESP8266 as a device is interesting to me, but I didn't think it would be so problematic... :)

cpq commented 3 years ago

From what I can tell, ESP8266 is obsoleted by ESP32S2 (which is a cut-down version of ESP32, without bluetooth). There are many projects that employ ESP8266 historically, but I can see no justification sticking to ESP8266 for any new development.

For a production project that needs security, ESP8266 is basically a no-go. Too many issues to even consider it.

cpq commented 3 years ago

@tipeter please modify mongoose.h in the following way:

diff --git a/mongoose.h b/mongoose.h
index e4ce27f8..09a9a6d5 100644
--- a/mongoose.h
+++ b/mongoose.h
@@ -229,8 +229,13 @@ static __inline struct tm *localtime_r(time_t *t, struct tm *tm) {

 #include <esp_system.h>

+#undef MG_PATH_MAX
+#undef MG_ENABLE_DIRLIST
+
 #define MG_DIRSEP '/'
 #define MG_INT64_FMT "%lld"
+#define MG_PATH_MAX 128
+#define MG_ENABLE_DIRLIST 1

 #endif

Then rebuild and report.

tipeter commented 3 years ago

Hello! Thanks for addressing this issue! Unfortunately, I had a very busy week and only now was able to address this topic. I have made the changes. The file list is now displayed in the browser, but it still restarts the MCU with stack owerflow. I'll try to debug it in the next few days and report back! Yesterday I tried Mongoose OS. I followed the quick start guide using ESP8266 and ESP32. The ESP8266 (1M and 4M flash models) crashed with a stack overflow error. The ESP32 worked. Maybe ESP8266's limited SRAM is causing the issue.

cpq commented 3 years ago

Closing this issue.

I also noticed that the current ESP8266 example does not even use the filesystem.

Feel free to reopen when you have time to reproduce. Make sure to include the full source code, and use the latest codebase.