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.
I love your video's ... Please keep them coming
Thank you very much!
Thank you for the video’s 🙏
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 :-)
Very good your videos, could implement the triggering of digital inputs and button triggers via websocket with a web interface
Yes, will do in my next video - stay tuned
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.
typical is 10,000
@@NathansHVAC LittleFS should be better. It uses wear leveling in some form.
Yes, LittleFS is the better implementation
Doesn't Espressif recommend using LitleFS now instead of SPIFFS? Thank you for another clear video.
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.
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?
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.
Can we set up a web server and store the data in the sd card connected to esp32 ?
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!
@@mothunderz thank you!
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!
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!
@@mothunderz Really should have said earlier I am enjoying working through so me of your videos. Please don't give up the hard work.
Thank you very much for your encouraging words 😀 🙏
What about making an AI desk robot like Anki Vector!
Cool idea, I have not looked into that yet...
@mothunderz esp32 has everything. we just need a display module a few motors it'll be done.. You should try it!