ESP32: How to create a config file with SPIFFS or LittleFS

Поділитися
Вставка
  • Опубліковано 15 лип 2024
  • When you power cycle or switch of the ESP32 all variables are lost. So how do you save your settings? In this video I show how to create a config file so you can store any number of variables. There are two versions of the code on Github, namely one using the SPIFFS library and one using the LittleFS library. If you are using the ESP32 board library v2.0.4 or newer, please use LittleFS, otherwise use SPIFFS. The video explains the SPIFFS version, but the LittleFS code works just the same.
    Github:
    github.com/mo-thunderz/Esp32C...
    Chapters:
    0:00 Introduction
    0:28 How to store multiple variables in a string with JSON
    1:02 Download from Github - NOTE: link has been updated in Video Description
    1:34 Explanation of code: libraries and general stuff
    2:50 Explanation of code: setup
    4:52 Explanation of code: saving variables to config file
    7:02 Explanation of code: saving variables from config file
    9:41 Explanation of code: main loop
    11:11 Testing code
    Corrections:
    01:08 I have renamed the Github Repository to "Esp32ConfigFile" as both SPIFFS and LittleFS versions are available now. The .ino file is renamed as well.
    01:23 If you are using the ESP32 board library v2.0.4 or newer, please use Esp32ConfigFileLittleFS, otherwise use Esp32ConfigFileSPIFFS. The video explains the SPIFFS version, but the LittleFS code works just the same.

КОМЕНТАРІ • 24

  • @johnheitz7517
    @johnheitz7517 Рік тому +1

    I love your video's ... Please keep them coming

  • @user-pu1ki7vk9v
    @user-pu1ki7vk9v Рік тому

    Thank you for the video’s 🙏

    • @mothunderz
      @mothunderz  Рік тому

      You are very welcome! Please note that I added an example now on Github as well for LittleFS. If you are using an ESP32 library of V2.0.4 or newer then Espressif recommends to use LittleFS instead of SPIFFS. Works exactly the same though :-)

  • @marcosgiovanni9682
    @marcosgiovanni9682 Рік тому

    Very good your videos, could implement the triggering of digital inputs and button triggers via websocket with a web interface

    • @mothunderz
      @mothunderz  Рік тому

      Yes, will do in my next video - stay tuned

  • @marshall100w6
    @marshall100w6 5 місяців тому

    Thank you for your video😉. I have a question, How many times could you write to the flash memory¿ I've read there is a limited write times. Thank you again.

    • @NathansHVAC
      @NathansHVAC 4 місяці тому +1

      typical is 10,000

    • @B..bsSeeker
      @B..bsSeeker 3 місяці тому

      ​@@NathansHVAC LittleFS should be better. It uses wear leveling in some form.

    • @mothunderz
      @mothunderz  3 місяці тому

      Yes, LittleFS is the better implementation

  • @jak_k
    @jak_k Рік тому

    Doesn't Espressif recommend using LitleFS now instead of SPIFFS? Thank you for another clear video.

    • @mothunderz
      @mothunderz  Рік тому +4

      Thank you for bringing this to my attention. For this small config file example there wont be a real difference, but yes: it is better to use LittleFS if your ESP32 library is v2.0.4 or newer. However, luckily the LIttleFS and SPIFFS libraries work exactly the same. I have added a LittleFS example on Github and have updated the video description. Hope it is clear like this.

  •  3 місяці тому

    Is this memory safe method? If you get bigger string and write it to the "named.json" next to second file "second.json" will it overwrite the content?

    •  3 місяці тому

      SPIFFS garbage collector looks for free space. If there is none it crashes :P If you delete file somtime it leave trash, and garbage collector gets confused. Anyway, if you add formatting case, it will format whole space and repair itself.

  • @ShawankumarParida
    @ShawankumarParida 11 місяців тому

    Can we set up a web server and store the data in the sd card connected to esp32 ?

    • @mothunderz
      @mothunderz  10 місяців тому +1

      Yes, that should be possible, just combine this code with that of the web server:
      ua-cam.com/video/DEFPSfLRObk/v-deo.html
      Good luck with your project!

    • @ShawankumarParida
      @ShawankumarParida 10 місяців тому

      @@mothunderz thank you!

  • @grahamheath3799
    @grahamheath3799 Рік тому

    There is a bug in the littlefs version spiffs seems okay. I guess you never ran the littlefs version.
    while(file.available()){
    String fileText = file.readString();
    }
    file.close();
    return fileText;
    I am told that that the line
    String fileText = file.readString(); declares another variable that only exists within the while loop.
    so value is never passed back to readconfig
    Thank you for speeding up my learning curve!

    • @mothunderz
      @mothunderz  Рік тому

      Thanks for pointing that out. No idea how that got in there. Think my compiler did not object as fileText was also defined above the while loop. So thank you for pointing this out, I corrected it on GitHub. Cheers!

    • @grahamheath3799
      @grahamheath3799 Рік тому

      @@mothunderz Really should have said earlier I am enjoying working through so me of your videos. Please don't give up the hard work.

    • @mothunderz
      @mothunderz  Рік тому

      Thank you very much for your encouraging words 😀 🙏

  • @ShawankumarParida
    @ShawankumarParida Рік тому

    What about making an AI desk robot like Anki Vector!

    • @mothunderz
      @mothunderz  Рік тому

      Cool idea, I have not looked into that yet...

    • @ShawankumarParida
      @ShawankumarParida Рік тому

      @mothunderz esp32 has everything. we just need a display module a few motors it'll be done.. You should try it!