• I've recently encountered this problem, in which I sometimes try to save some data (come configurations, no more than 100 characters in total) in a file using this function fs.writeFile(), but after like 2 or 3 tries, it just stop working, and the function returns false every time...

    I also tried to use the E.openFile() and File.close() pattern, but sadly I'm getting the same results. Does anyone else have this problem? I'm using firmware version 1.95 btw

  • Hmm, 1.95 is old, better upgrade and try again.

  • Same issue in 2.14. I think the filesystem just crashes silently if there are is not enough heap or too few variables.
    A webserver serving multiple files in parallel can crash the filesystem, or a webserver and some other background processes can lead to a crash (using E.pipe).
    It doesn't crash by repeated read access, if there's a sufficient free memory available. Storage is much more stable (require('Storage')).
    Disclaimer: My experience comes from the ESP8266 with a custom firmware build. Yet, I'm pretty sure there are some undiscovered bugs in the filesystem (require('fs')).

  • I only use Storage. Can you add a sample to reproduce the crash, or just add infos to https://github.com/espruino/Espruino/iss­ues/1777

  • For ESP8266 or ESP32? I'm busy atm, but I'll add some specialized code when I find the time to do so.
    If you want to run a web server on the ESP8266: https://github.com/GermanWarez/espruino-­esp8266-copy-file-to-storage
    It'll stop fs when serving two files in parallel. To prevent this I've implemented a sequential loader in index.html. But if you'd request the page in two browser windows in parallel it'll stop fs. Or if you change index.html to contain e.g. it'll stop fs.
    Other ways to stop fs:

    • Write to storage first (a lot), then try to copy from storage to fs. A reset between these two operations avoids the stop.
    • Write to fs often, e.g. 50kB of data in small chunks of 128 bytes.
      It looks like fs needs a lot of RAM, sometimes more than ESP8266 can offer. Storage seems like the better option for ESP8266, and maybe ESP32, too.
      For the ESP32 the limits might be higher, but being from the same family it's very likely to behave similar.
  • Hmm, my guess it that you overload the ESP8266. The ESP32 has much more memory and should handle it. Well fs is very memory hungry.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

fs.writeFile() and fs.readFile() not working properly in ESP32

Posted by Avatar for user139113 @user139113