Skip to content
This repository has been archived by the owner on Feb 4, 2023. It is now read-only.

Minor: examples/Async_ESP32_FSWebServer/ wrongly uses FileFS.begin(true) #47

Closed
robcazzaro opened this issue Apr 8, 2021 · 4 comments
Closed
Labels
enhancement New feature or request

Comments

@robcazzaro
Copy link

(please also see lorol/LITTLEFS#27 for more context)

I'm using your library and your examples as a starting point for my project. Thanks for sharing this!

I noticed that the following code

// Format SPIFFS if not yet
  if (!FileFS.begin(true))
  {
    Serial.print(FS_Name);
    Serial.println(F(" failed! AutoFormatting."));
  }

seems to assume that FileFS.begin(true) returns false if the SPIFFS was un-initialized and needed to be formatted. In reality that call returns true if the mount has been successful, even if that required an auto-format, false only when the mount fails for whatever reason.

If the debug output is enabled, the LittleFS library debug messages overwrite any debug print from the Arduino thread, causing additional comprehension problems

If the call FileFS.begin(true) fails, that means that there is no SPIFFS, and your example should abort

The above applies to all your examples using SPIFFS for ESP32

@khoih-prog
Copy link
Owner

Thanks for identifying the misleading message in the examples. It happened because time spent in them were so small, and not considered so serious.

I have been aware of this minor issue and knew it's better to have something like the following code, such as in BlynkSimpleEsp32_WM.h#L1510-L1520 or BlynkSimpleEsp8266_WM.h#L1467-L1480

I won't let it slipping this time and will fix it in next release.

  1. For ESP32
     // Format SPIFFS if not yet
      if (!FileFS.begin(true))
      {
        Serial.println(F("SPIFFS/LittleFS failed! Already tried formatting."));
        
        if (!FileFS.begin())
        {
          Serial.println(F("SPIFFS/LittleFS failed! Pls use EEPROM."));
          return false;
        }
      }
  1. For ESP8266
      if (!FileFS.begin())
      {
        FileFS.format();
        
        if (!FileFS.begin())
        {
#if USE_LITTLEFS
          Serial.println(F("LittleFS failed!. Please use SPIFFS or EEPROM."));
#else
          Serial.println(F("SPIFFS failed!. Please use LittleFS or EEPROM."));
#endif 
          return false;
        }
      }
  1. Combined, to be in new release
  // Format FileFS if not yet
#ifdef ESP32
  if (!FileFS.begin(true))
#else
  if (!FileFS.begin())
#endif
  {
#ifdef ESP8266
    FileFS.format();
#endif

    Serial.println(F("SPIFFS/LittleFS failed! Already tried formatting."));
  
    if (!FileFS.begin())
    {     
#if USE_LITTLEFS
      Serial.println(F("LittleFS failed!. Please use SPIFFS or EEPROM. Stay forever"));
#else
      Serial.println(F("SPIFFS failed!. Please use LittleFS or EEPROM. Stay forever"));
#endif

      while (true)
      {
        delay(1);
      }
    }
  }

@khoih-prog khoih-prog added the enhancement New feature or request label Apr 9, 2021
@robcazzaro
Copy link
Author

I know it's not really a meaningful contribution, but I'm glad to have been of help :)

Your new code looks great to me. I cannot thank you enough for contributing this library and the examples. It really helped me a lot, and I learned a lot just following the examples

Just keep in mind that, if using LittleFS at least, the debug messages from LittleFS will preempt your Serial.print() and the user won't see a debug message, just the code hanging. If you do something like the code below, on the other hand, the error message will be correctly displayed. Truly minor, but it took me a bit to figure out what was happening, and remembering that all ESP32 code is dual thread, unlike other Arduino platforms

  // Format FileFS if not yet
#ifdef ESP32
  if (!FileFS.begin(true))
#else
  if (!FileFS.begin())
#endif
  {
#ifdef ESP8266
    FileFS.format();
#endif

    Serial.println(F("SPIFFS/LittleFS failed! Already tried formatting."));
  
    if (!FileFS.begin())
    {     
       delay(100); // prevents debug info from the library to hide err message. The code stops anyway, so a delay is not an issue
#if USE_LITTLEFS
      Serial.println(F("LittleFS failed!. Please use SPIFFS or EEPROM. Stay forever"));
#else
      Serial.println(F("SPIFFS failed!. Please use LittleFS or EEPROM. Stay forever"));
#endif

      while (true)
      {
        delay(1);
      }
    }
  }

@khoih-prog
Copy link
Owner

khoih-prog commented Apr 9, 2021

That's great. I'll certainly use it and have some note about your contribution.
Regards,

khoih-prog added a commit that referenced this issue Apr 9, 2021
### Releases v1.6.2

1. Fix example misleading messages. Check [**Minor: examples/Async_ESP32_FSWebServer/ wrongly uses FileFS.begin(true)** #47](#47)
@khoih-prog
Copy link
Owner

The new ESPAsync_WiFiManager Release v1.6.2 has been published, with a note to thank you at Contributions and Thanks


Releases v1.6.2

  1. Fix example misleading messages. Check Minor: examples/Async_ESP32_FSWebServer/ wrongly uses FileFS.begin(true) #47

khoih-prog added a commit to khoih-prog/ESP_WiFiManager that referenced this issue Apr 9, 2021
### Releases v1.5.2

1. Fix example misleading messages. Check [**Minor: examples/Async_ESP32_FSWebServer/ wrongly uses FileFS.begin(true)** #47](khoih-prog/ESPAsync_WiFiManager#47)
khoih-prog added a commit to khoih-prog/ESP_WiFiManager that referenced this issue Apr 9, 2021
### Releases v1.5.2

1. Fix example misleading messages. Check [**Minor: examples/Async_ESP32_FSWebServer/ wrongly uses FileFS.begin(true)** #47](khoih-prog/ESPAsync_WiFiManager#47)
2. Tested with [**ESP32 Core 1.0.6**](https://github.com/espressif/arduino-esp32) and [**LittleFS_esp32 v1.0.6**](https://github.com/lorol/LITTLEFS)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants