mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 14:12:16 +03:00
update little fs lib to last version
This commit is contained in:
@@ -3,15 +3,15 @@
|
|||||||
"chipID": "",
|
"chipID": "",
|
||||||
"apssid": "IoTmanager",
|
"apssid": "IoTmanager",
|
||||||
"appass": "",
|
"appass": "",
|
||||||
"routerssid": "home",
|
"routerssid": "rise",
|
||||||
"routerpass": "kisa3333",
|
"routerpass": "hostel3333",
|
||||||
"timezone": 2,
|
"timezone": 2,
|
||||||
"ntp": "pool.ntp.org",
|
"ntp": "pool.ntp.org",
|
||||||
"mqttServer": "91.204.228.124",
|
"mqttServer": "91.204.228.124",
|
||||||
"mqttPort": 1883,
|
"mqttPort": 1883,
|
||||||
"mqttPrefix": "/iotTeam",
|
"mqttPrefix": "/iotTest",
|
||||||
"mqttUser": "test",
|
"mqttUser": "rise",
|
||||||
"mqttPass": "test",
|
"mqttPass": "23ri22se32",
|
||||||
"scen": "1",
|
"scen": "1",
|
||||||
"pushingboxid": "v7C133E426B0C69E",
|
"pushingboxid": "v7C133E426B0C69E",
|
||||||
"weblogin": "admin",
|
"weblogin": "admin",
|
||||||
|
|||||||
@@ -3,7 +3,9 @@
|
|||||||
//
|
//
|
||||||
// Firmware
|
// Firmware
|
||||||
//
|
//
|
||||||
|
|
||||||
#define FIRMWARE_NAME "esp8266-iotm"
|
#define FIRMWARE_NAME "esp8266-iotm"
|
||||||
|
|
||||||
#define FIRMWARE_VERSION 258
|
#define FIRMWARE_VERSION 258
|
||||||
#define FLASH_4MB true
|
#define FLASH_4MB true
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +1,30 @@
|
|||||||
# LITTLEFS
|
# LittleFS_esp32
|
||||||
|
|
||||||
## LittleFS library for arduino-esp32
|
## LittleFS library for arduino-esp32
|
||||||
|
|
||||||
#### Warning: Tested only with git arduino-esp32 #b92c58d core, which is for ESP-IDF 3.3! </br> With other versions/releases of the core including release 1.0.4, especially against different IDF this will NOT not work.
|
- A LittleFS wrapper for Arduino ESP32 of [ARMmbed LittleFS](https://github.com/ARMmbed/littlefs)
|
||||||
|
|
||||||
- A LittleFS wrapper for Arduino ESP32 of [Mbed LittleFS](https://github.com/ARMmbed/littlefs)
|
|
||||||
- Based on [ESP-IDF port of joltwallet/esp_littlefs](https://github.com/joltwallet/esp_littlefs) , thank you Brian!
|
- Based on [ESP-IDF port of joltwallet/esp_littlefs](https://github.com/joltwallet/esp_littlefs) , thank you Brian!
|
||||||
- Functionality is the same and SPIFFS partition scheme and data folder meaning are kept
|
- As a reference, see [LillteFS library for ESP8266 core](https://github.com/esp8266/Arduino/tree/master/libraries/LittleFS)
|
||||||
- You can use either LITTLEFS or SPIFFS but not both simultaneously on given Arduino project
|
- [PR at esp32 core development](https://github.com/espressif/arduino-esp32/pull/4096)
|
||||||
- A PR to embed it to esp32 core is made too. See the [PR status here](https://github.com/espressif/arduino-esp32/pull/4096)
|
- [PR at esp-idf development](https://github.com/espressif/esp-idf/pull/5469)
|
||||||
|
- The functionality is similar to SPIFFS
|
||||||
|
|
||||||
### Installation
|
### Installation
|
||||||
|
|
||||||
- Copy <b>LITTLEFS</b> folder to Arduino IDE embedded libraries place
|
- Use **Arduino Library Manager**
|
||||||
- For Win, the default place of arduino-esp32 core libraries is somewhere like:
|
- Or download / use **git** to have latest repository of **LITTLEFS** added to Arduino IDE **/libraries** folder
|
||||||
```C:\Users\<username>\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries ```
|
(File > Preferences > Sketchbook location).
|
||||||
- Alternatively, you can put it to your usual libraries place
|
- See ``` #define CONFIG_LITTLEFS_FOR_IDF_3_2 ``` in **esp_littlefs.c**.
|
||||||
|
When defined, code builds with any IDF 3.2 - 4.x.
|
||||||
|
On IDF newer than 3.2, it **can** be commented to enable file timestamp feature.
|
||||||
|
See LITTLEFS_time example.
|
||||||
|
- The other ``` #define CONFIG_LITTLEFS_xxxxx ``` are set to optimal default values.
|
||||||
|
Read [here](https://github.com/joltwallet/esp_littlefs/blob/master/Kconfig) and [here](https://github.com/ARMmbed/littlefs/blob/master/README.md) if you want to modify.
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
|
||||||
- In your existing code, replace SPIFFS like this
|
- Use LITTLEFS same way as SPIFFS
|
||||||
|
- A quick startup based on your existing code you can re-define SPIFFS
|
||||||
```
|
```
|
||||||
#define USE_LittleFS
|
#define USE_LittleFS
|
||||||
|
|
||||||
@@ -30,30 +36,59 @@
|
|||||||
#include <SPIFFS.h>
|
#include <SPIFFS.h>
|
||||||
#endif
|
#endif
|
||||||
```
|
```
|
||||||
### Differences with SPIFFS (and in this implementation)
|
- Note, this may not work if your sketch uses other libraries that use SPIFFS themselves.
|
||||||
|
|
||||||
- LittleFS has folders, you my need to tweak your code to iterate files in folders
|
### Differences with SPIFFS
|
||||||
- Root: /someting = something, so attention to /
|
|
||||||
- Lower level littlefs library cannot mount on NULL as partition_label name, while SPIFFS can
|
- LittleFS has folders, you need to iterate files in folders. See **To Do** below.
|
||||||
- Lower level littlefs library does not need maxOpenFiles parameter
|
- At root a "/folder" = "folder"
|
||||||
- Speed (LITTLEFS_Test.ino) 1048576 bytes written in 16238 ms / 1048576 bytes read in 918 ms
|
- Requires a label for mount point, NULL will not work
|
||||||
- Speed (SPIFFS_Test.ino) 1048576 bytes written in 65971 ms / 1048576 bytes read in 680 ms
|
- maxOpenFiles parameter is unused, kept for compatibility
|
||||||
|
- LITTLEFS.mkdir(path) and LITTLEFS.rmdir(path) work as expected for folders
|
||||||
|
- Speed comparison based on **LittleFS_test.ino** sketch (for a file 1048576 bytes):
|
||||||
|
|
||||||
|
|Filesystem|Read time [ms]|Write time [ms]|
|
||||||
|
|----|----|----|
|
||||||
|
|FAT|276|14493|
|
||||||
|
|LITTLEFS|446*|16387|
|
||||||
|
|SPIFFS|767|65622|
|
||||||
|
|
||||||
|
*The read speed improved by changing ```#define CONFIG_LITTLEFS_CACHE_SIZE``` from 128 to 512
|
||||||
|
|
||||||
|
|
||||||
### Arduino ESP32 LittleFS filesystem upload tool
|
### Arduino ESP32 LittleFS filesystem upload tool
|
||||||
|
|
||||||
- Download the tool archive from [here](https://github.com/lorol/arduino-esp32littlefs-plugin/raw/master/src/bin/esp32littlefs.jar)
|
- Use (replace if exists) [arduino-esp32fs-plugin](https://github.com/me-no-dev/arduino-esp32fs-plugin/pull/23 ) with [this variant](https://github.com/lorol/arduino-esp32fs-plugin), which supports SPIFFS, LittleFS and FatFS
|
||||||
- In your Arduino sketchbook directory, create tools directory if it doesn't exist yet.
|
- Requires [mklittlefs executable](https://github.com/earlephilhower/mklittlefs) which is available [in releases section here](https://github.com/lorol/arduino-esp32fs-plugin ) or download the zipped binary [here](https://github.com/earlephilhower/mklittlefs/releases) or from **esp-quick-toolchain** releases [here](https://github.com/earlephilhower/esp-quick-toolchain/releases)
|
||||||
- Unpack the tool into tools directory (the path will look like ```<home_dir>/Arduino/tools/ESP32LittleFS/tool/esp32littlefs.jar```).
|
- Copy it to **/tools** folder of esp32 platform where **espota** and **esptool** (.py or.exe) tools are located
|
||||||
- You need the [mklittlefs tool](https://github.com/earlephilhower/mklittlefs) Download the [release](https://github.com/earlephilhower/mklittlefs/releases) and copy it to
|
|
||||||
packages\esp32\tools\mkspiffs\<mklittlefs rev. x.x.x>\ or on checkout (dev) environment to: packages\esp32\hardware\esp32\<release>\tools\mklittlefs\
|
|
||||||
- Restart Arduino IDE.
|
- Restart Arduino IDE.
|
||||||
|
|
||||||
|
### PlatformIO
|
||||||
|
|
||||||
|
- See [LITTLEFS_PlatformIO example here](https://github.com/lorol/LITTLEFS/tree/master/examples/LITTLEFS_PlatformIO)
|
||||||
|
( based on notes below from [BlueAndi](https://github.com/BlueAndi) )
|
||||||
|
- Add to _platformio.ini_:
|
||||||
|
`extra_scripts = replace_fs.py`
|
||||||
|
|
||||||
|
- Add _replace_fs.py_ to project root directory (where platformio.ini is located):
|
||||||
|
|
||||||
|
```python
|
||||||
|
Import("env")
|
||||||
|
print("Replace MKSPIFFSTOOL with mklittlefs.exe")
|
||||||
|
env.Replace (MKSPIFFSTOOL = "mklittlefs.exe")
|
||||||
|
```
|
||||||
|
|
||||||
|
- Add _mklittlefs.exe_ to project root directory as well.
|
||||||
|
|
||||||
## Credits and license
|
## Credits and license
|
||||||
|
|
||||||
- This work is based on [Mbed LittleFS](https://github.com/ARMmbed/littlefs) , [ESP-IDF port of joltwallet/esp_littlefs](https://github.com/joltwallet/esp_littlefs) , [Espressif Arduino core for the ESP32, the ESP-IDF - SPIFFS Library](https://github.com/espressif/arduino-esp32/tree/master/libraries/SPIFFS)
|
- This work is based on [ARMmbed LittleFS](https://github.com/ARMmbed/littlefs) , [ESP-IDF port of joltwallet/esp_littlefs](https://github.com/joltwallet/esp_littlefs) , [Espressif Arduino core for the ESP32, the ESP-IDF - SPIFFS Library](https://github.com/espressif/arduino-esp32/tree/master/libraries/SPIFFS)
|
||||||
- Licensed under GPL v2 ([text](LICENSE))
|
- Licensed under GPL v2 ([text](LICENSE))
|
||||||
|
|
||||||
## To Do
|
## To Do
|
||||||
|
- [x] Submit to be added to Arduino Library Manager
|
||||||
- Supporting different IDF versions
|
- [ ] Decide on more compatibility (or not) with SPIFFS' lack of folders, similar to esp8266' way:
|
||||||
|
- [recursive folders auto creation](https://github.com/esp8266/Arduino/blob/master/libraries/LittleFS/src/LittleFS.cpp#L60) when a new file is created at non-existing path
|
||||||
|
- [recursive folders auto deletion](https://github.com/esp8266/Arduino/blob/master/libraries/LittleFS/src/LittleFS.h#L149) on "last file" deletion (SPIFFS cannot have "folder w/o file")
|
||||||
|
- review other differences: opendir(), rmdir(), unlink()
|
||||||
|
- [ ] Follow-up / eventually retire this library if LittleFS gets implemented through IDF / esp32 Arduino core.
|
||||||
|
|||||||
4
lib/LITTLEFS/examples/LITTLEFS_PlatformIO/.gitignore
vendored
Normal file
4
lib/LITTLEFS/examples/LITTLEFS_PlatformIO/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
.pio
|
||||||
|
.vscode
|
||||||
|
mklittlefs.exe
|
||||||
|
mklittlefs
|
||||||
68
lib/LITTLEFS/examples/LITTLEFS_PlatformIO/README.md
Normal file
68
lib/LITTLEFS/examples/LITTLEFS_PlatformIO/README.md
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
# How to run on PlatformIO IDE
|
||||||
|
|
||||||
|
- Download and extract to this project root a **mklittlefs** executable for your OS [from a zipped binary here](https://github.com/earlephilhower/mklittlefs/releases)
|
||||||
|
- Open **LITTLEFS_PlatformIO** folder
|
||||||
|
- Run PlatformIO project task: **Upload Filesystem Image**
|
||||||
|
- Run PlatformIO project task: **Upload and Monitor**
|
||||||
|
- You will see a Serial output like:
|
||||||
|
```
|
||||||
|
--- Miniterm on COM5 115200,8,N,1 ---
|
||||||
|
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
|
||||||
|
ets Jun 8 2016 00:22:57
|
||||||
|
|
||||||
|
rst:0x1 (POWERON_RESET),boot:0x13 (Snfigsip: 0, SPIWP:0xee
|
||||||
|
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
|
||||||
|
mode:DIO, clock div:2
|
||||||
|
load:0x3fff0018,len:4
|
||||||
|
load:0x3fff001c,len:1044
|
||||||
|
load:0x40078000,len:10044
|
||||||
|
load:0x40080400,len:5872
|
||||||
|
entry 0x400806ac
|
||||||
|
Listing directory: /
|
||||||
|
FILE: /file1.txt SIZE: 3 LAST WRITE: 2020-10-06 15:10:33
|
||||||
|
DIR : /testfolder LAST WRITE: 2020-10-06 15:10:33
|
||||||
|
Creating Dir: /mydir
|
||||||
|
Dir created
|
||||||
|
Writing file: /mydir/hello2.txt
|
||||||
|
- file written
|
||||||
|
Listing directory: /
|
||||||
|
FILE: /file1.txt SIZE: 3 LAST WRITE: 2020-10-06 15:10:33
|
||||||
|
DIR : /mydir LAST WRITE: 1970-01-01 00:00:00
|
||||||
|
Listing directory: /mydir
|
||||||
|
FILE: /mydir/hello2.txt SIZE: 6 LAST WRITE: 1970-01-01 00:00:00
|
||||||
|
DIR : /testfolder LAST WRITE: 2020-10-06 15:10:33
|
||||||
|
Listing directory: /testfolder
|
||||||
|
FILE: /testfolder/test2.txt SIZE: 3 LAST WRITE: 2020-10-06 15:10:33
|
||||||
|
Deleting file: /mydir/hello2.txt
|
||||||
|
- file deleted
|
||||||
|
Removing Dir: /mydir
|
||||||
|
Dir removed
|
||||||
|
Listing directory: /
|
||||||
|
FILE: /file1.txt SIZE: 3 LAST WRITE: 2020-10-06 15:10:33
|
||||||
|
DIR : /testfolder LAST WRITE: 2020-10-06 15:10:33
|
||||||
|
Listing directory: /testfolder
|
||||||
|
FILE: /testfolder/test2.txt SIZE: 3 LAST WRITE: 2020-10-06 15:10:33
|
||||||
|
Writing file: /hello.txt
|
||||||
|
- file written
|
||||||
|
Appending to file: /hello.txt
|
||||||
|
- message appended
|
||||||
|
Reading file: /hello.txt
|
||||||
|
- read from file:
|
||||||
|
Hello World!
|
||||||
|
Renaming file /hello.txt to /foo.txt
|
||||||
|
- file renamed
|
||||||
|
Reading file: /foo.txt
|
||||||
|
- read from file:
|
||||||
|
Hello World!
|
||||||
|
Deleting file: /foo.txt
|
||||||
|
- file deleted
|
||||||
|
Testing file I/O with /test.txt
|
||||||
|
- writing................................................................
|
||||||
|
- 1048576 bytes written in 12006 ms
|
||||||
|
- reading................................................................
|
||||||
|
- 1048576 bytes read in 547 ms
|
||||||
|
Deleting file: /test.txt
|
||||||
|
- file deleted
|
||||||
|
Test complete
|
||||||
|
```
|
||||||
|
- If you have a module with more than 4MB flash, you can uncomment **partitions_custom.csv** in **platformio.ini** and modify the csv file accordingly
|
||||||
1
lib/LITTLEFS/examples/LITTLEFS_PlatformIO/data/file1.txt
Normal file
1
lib/LITTLEFS/examples/LITTLEFS_PlatformIO/data/file1.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
aaa
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
bbb
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
Import("env")
|
||||||
|
env.Replace( MKSPIFFSTOOL=env.get("PROJECT_DIR") + '/mklittlefs' )
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
# Name, Type, SubType, Offset, Size, Flags
|
||||||
|
ota_0, app, ota_0, 0x10000, 0x1A0000,
|
||||||
|
ota_1, app, ota_1, , 0x1A0000,
|
||||||
|
otadata, data, ota, 0x350000, 0x2000,
|
||||||
|
nvs, data, nvs, , 0x6000,
|
||||||
|
data, data, spiffs, , 0xA8000,
|
||||||
|
35
lib/LITTLEFS/examples/LITTLEFS_PlatformIO/platformio.ini
Normal file
35
lib/LITTLEFS/examples/LITTLEFS_PlatformIO/platformio.ini
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
; PlatformIO Project Configuration File
|
||||||
|
;
|
||||||
|
; Build options: build flags, source filter
|
||||||
|
; Upload options: custom upload port, speed and extra flags
|
||||||
|
; Library options: dependencies, extra library storages
|
||||||
|
; Advanced options: extra scripting
|
||||||
|
;
|
||||||
|
; Please visit documentation for the other options and examples
|
||||||
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
|
[platformio]
|
||||||
|
default_envs = esp32
|
||||||
|
|
||||||
|
[env]
|
||||||
|
framework = arduino
|
||||||
|
|
||||||
|
[env:esp32]
|
||||||
|
platform = espressif32
|
||||||
|
;platform = https://github.com/platformio/platform-espressif32.git
|
||||||
|
;board_build.mcu = esp32
|
||||||
|
platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git
|
||||||
|
|
||||||
|
build_flags =
|
||||||
|
${env.build_flags}
|
||||||
|
-D=${PIOENV}
|
||||||
|
;-D CONFIG_LITTLEFS_FOR_IDF_3_2
|
||||||
|
|
||||||
|
lib_deps = https://github.com/lorol/LITTLEFS.git
|
||||||
|
|
||||||
|
board = esp32dev
|
||||||
|
;board_build.partitions = partitions_custom.csv
|
||||||
|
monitor_filters = esp32_exception_decoder
|
||||||
|
monitor_speed = 115200
|
||||||
|
|
||||||
|
extra_scripts = ./littlefsbuilder.py
|
||||||
293
lib/LITTLEFS/examples/LITTLEFS_PlatformIO/src/main.cpp
Normal file
293
lib/LITTLEFS/examples/LITTLEFS_PlatformIO/src/main.cpp
Normal file
@@ -0,0 +1,293 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
#include "FS.h"
|
||||||
|
#include <LITTLEFS.h>
|
||||||
|
|
||||||
|
#ifndef CONFIG_LITTLEFS_FOR_IDF_3_2
|
||||||
|
#include <time.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* You only need to format LITTLEFS the first time you run a
|
||||||
|
test or else use the LITTLEFS plugin to create a partition
|
||||||
|
https://github.com/lorol/arduino-esp32littlefs-plugin */
|
||||||
|
|
||||||
|
#define FORMAT_LITTLEFS_IF_FAILED true
|
||||||
|
|
||||||
|
void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
|
||||||
|
Serial.printf("Listing directory: %s\r\n", dirname);
|
||||||
|
|
||||||
|
File root = fs.open(dirname);
|
||||||
|
if(!root){
|
||||||
|
Serial.println("- failed to open directory");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(!root.isDirectory()){
|
||||||
|
Serial.println(" - not a directory");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
File file = root.openNextFile();
|
||||||
|
while(file){
|
||||||
|
if(file.isDirectory()){
|
||||||
|
Serial.print(" DIR : ");
|
||||||
|
|
||||||
|
#ifdef CONFIG_LITTLEFS_FOR_IDF_3_2
|
||||||
|
Serial.println(file.name());
|
||||||
|
#else
|
||||||
|
Serial.print(file.name());
|
||||||
|
time_t t= file.getLastWrite();
|
||||||
|
struct tm * tmstruct = localtime(&t);
|
||||||
|
Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n",(tmstruct->tm_year)+1900,( tmstruct->tm_mon)+1, tmstruct->tm_mday,tmstruct->tm_hour , tmstruct->tm_min, tmstruct->tm_sec);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if(levels){
|
||||||
|
listDir(fs, file.name(), levels -1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Serial.print(" FILE: ");
|
||||||
|
Serial.print(file.name());
|
||||||
|
Serial.print(" SIZE: ");
|
||||||
|
|
||||||
|
#ifdef CONFIG_LITTLEFS_FOR_IDF_3_2
|
||||||
|
Serial.println(file.size());
|
||||||
|
#else
|
||||||
|
Serial.print(file.size());
|
||||||
|
time_t t= file.getLastWrite();
|
||||||
|
struct tm * tmstruct = localtime(&t);
|
||||||
|
Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n",(tmstruct->tm_year)+1900,( tmstruct->tm_mon)+1, tmstruct->tm_mday,tmstruct->tm_hour , tmstruct->tm_min, tmstruct->tm_sec);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
file = root.openNextFile();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void createDir(fs::FS &fs, const char * path){
|
||||||
|
Serial.printf("Creating Dir: %s\n", path);
|
||||||
|
if(fs.mkdir(path)){
|
||||||
|
Serial.println("Dir created");
|
||||||
|
} else {
|
||||||
|
Serial.println("mkdir failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void removeDir(fs::FS &fs, const char * path){
|
||||||
|
Serial.printf("Removing Dir: %s\n", path);
|
||||||
|
if(fs.rmdir(path)){
|
||||||
|
Serial.println("Dir removed");
|
||||||
|
} else {
|
||||||
|
Serial.println("rmdir failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void readFile(fs::FS &fs, const char * path){
|
||||||
|
Serial.printf("Reading file: %s\r\n", path);
|
||||||
|
|
||||||
|
File file = fs.open(path);
|
||||||
|
if(!file || file.isDirectory()){
|
||||||
|
Serial.println("- failed to open file for reading");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println("- read from file:");
|
||||||
|
while(file.available()){
|
||||||
|
Serial.write(file.read());
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void writeFile(fs::FS &fs, const char * path, const char * message){
|
||||||
|
Serial.printf("Writing file: %s\r\n", path);
|
||||||
|
|
||||||
|
File file = fs.open(path, FILE_WRITE);
|
||||||
|
if(!file){
|
||||||
|
Serial.println("- failed to open file for writing");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(file.print(message)){
|
||||||
|
Serial.println("- file written");
|
||||||
|
} else {
|
||||||
|
Serial.println("- write failed");
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void appendFile(fs::FS &fs, const char * path, const char * message){
|
||||||
|
Serial.printf("Appending to file: %s\r\n", path);
|
||||||
|
|
||||||
|
File file = fs.open(path, FILE_APPEND);
|
||||||
|
if(!file){
|
||||||
|
Serial.println("- failed to open file for appending");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(file.print(message)){
|
||||||
|
Serial.println("- message appended");
|
||||||
|
} else {
|
||||||
|
Serial.println("- append failed");
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void renameFile(fs::FS &fs, const char * path1, const char * path2){
|
||||||
|
Serial.printf("Renaming file %s to %s\r\n", path1, path2);
|
||||||
|
if (fs.rename(path1, path2)) {
|
||||||
|
Serial.println("- file renamed");
|
||||||
|
} else {
|
||||||
|
Serial.println("- rename failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void deleteFile(fs::FS &fs, const char * path){
|
||||||
|
Serial.printf("Deleting file: %s\r\n", path);
|
||||||
|
if(fs.remove(path)){
|
||||||
|
Serial.println("- file deleted");
|
||||||
|
} else {
|
||||||
|
Serial.println("- delete failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SPIFFS-like write and delete file
|
||||||
|
|
||||||
|
// See: https://github.com/esp8266/Arduino/blob/master/libraries/LittleFS/src/LittleFS.cpp#L60
|
||||||
|
void writeFile2(fs::FS &fs, const char * path, const char * message){
|
||||||
|
if(!fs.exists(path)){
|
||||||
|
if (strchr(path, '/')) {
|
||||||
|
Serial.printf("Create missing folders of: %s\r\n", path);
|
||||||
|
char *pathStr = strdup(path);
|
||||||
|
if (pathStr) {
|
||||||
|
char *ptr = strchr(pathStr, '/');
|
||||||
|
while (ptr) {
|
||||||
|
*ptr = 0;
|
||||||
|
fs.mkdir(pathStr);
|
||||||
|
*ptr = '/';
|
||||||
|
ptr = strchr(ptr+1, '/');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(pathStr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.printf("Writing file to: %s\r\n", path);
|
||||||
|
File file = fs.open(path, FILE_WRITE);
|
||||||
|
if(!file){
|
||||||
|
Serial.println("- failed to open file for writing");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(file.print(message)){
|
||||||
|
Serial.println("- file written");
|
||||||
|
} else {
|
||||||
|
Serial.println("- write failed");
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// See: https://github.com/esp8266/Arduino/blob/master/libraries/LittleFS/src/LittleFS.h#L149
|
||||||
|
void deleteFile2(fs::FS &fs, const char * path){
|
||||||
|
Serial.printf("Deleting file and empty folders on path: %s\r\n", path);
|
||||||
|
|
||||||
|
if(fs.remove(path)){
|
||||||
|
Serial.println("- file deleted");
|
||||||
|
} else {
|
||||||
|
Serial.println("- delete failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
char *pathStr = strdup(path);
|
||||||
|
if (pathStr) {
|
||||||
|
char *ptr = strrchr(pathStr, '/');
|
||||||
|
if (ptr) {
|
||||||
|
Serial.printf("Removing all empty folders on path: %s\r\n", path);
|
||||||
|
}
|
||||||
|
while (ptr) {
|
||||||
|
*ptr = 0;
|
||||||
|
fs.rmdir(pathStr);
|
||||||
|
ptr = strrchr(pathStr, '/');
|
||||||
|
}
|
||||||
|
free(pathStr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void testFileIO(fs::FS &fs, const char * path){
|
||||||
|
Serial.printf("Testing file I/O with %s\r\n", path);
|
||||||
|
|
||||||
|
static uint8_t buf[512];
|
||||||
|
size_t len = 0;
|
||||||
|
File file = fs.open(path, FILE_WRITE);
|
||||||
|
if(!file){
|
||||||
|
Serial.println("- failed to open file for writing");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t i;
|
||||||
|
Serial.print("- writing" );
|
||||||
|
uint32_t start = millis();
|
||||||
|
for(i=0; i<2048; i++){
|
||||||
|
if ((i & 0x001F) == 0x001F){
|
||||||
|
Serial.print(".");
|
||||||
|
}
|
||||||
|
file.write(buf, 512);
|
||||||
|
}
|
||||||
|
Serial.println("");
|
||||||
|
uint32_t end = millis() - start;
|
||||||
|
Serial.printf(" - %u bytes written in %u ms\r\n", 2048 * 512, end);
|
||||||
|
file.close();
|
||||||
|
|
||||||
|
file = fs.open(path);
|
||||||
|
start = millis();
|
||||||
|
end = start;
|
||||||
|
i = 0;
|
||||||
|
if(file && !file.isDirectory()){
|
||||||
|
len = file.size();
|
||||||
|
size_t flen = len;
|
||||||
|
start = millis();
|
||||||
|
Serial.print("- reading" );
|
||||||
|
while(len){
|
||||||
|
size_t toRead = len;
|
||||||
|
if(toRead > 512){
|
||||||
|
toRead = 512;
|
||||||
|
}
|
||||||
|
file.read(buf, toRead);
|
||||||
|
if ((i++ & 0x001F) == 0x001F){
|
||||||
|
Serial.print(".");
|
||||||
|
}
|
||||||
|
len -= toRead;
|
||||||
|
}
|
||||||
|
Serial.println("");
|
||||||
|
end = millis() - start;
|
||||||
|
Serial.printf("- %u bytes read in %u ms\r\n", flen, end);
|
||||||
|
file.close();
|
||||||
|
} else {
|
||||||
|
Serial.println("- failed to open file for reading");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup(){
|
||||||
|
Serial.begin(115200);
|
||||||
|
if(!LITTLEFS.begin(FORMAT_LITTLEFS_IF_FAILED)){
|
||||||
|
Serial.println("LITTLEFS Mount Failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
listDir(LITTLEFS, "/", 0);
|
||||||
|
createDir(LITTLEFS, "/mydir");
|
||||||
|
writeFile(LITTLEFS, "/mydir/hello2.txt", "Hello2");
|
||||||
|
//writeFile(LITTLEFS, "/mydir/newdir2/newdir3/hello3.txt", "Hello3");
|
||||||
|
writeFile2(LITTLEFS, "/mydir/newdir2/newdir3/hello3.txt", "Hello3");
|
||||||
|
listDir(LITTLEFS, "/", 3);
|
||||||
|
deleteFile(LITTLEFS, "/mydir/hello2.txt");
|
||||||
|
//deleteFile(LITTLEFS, "/mydir/newdir2/newdir3/hello3.txt");
|
||||||
|
deleteFile2(LITTLEFS, "/mydir/newdir2/newdir3/hello3.txt");
|
||||||
|
removeDir(LITTLEFS, "/mydir");
|
||||||
|
listDir(LITTLEFS, "/", 3);
|
||||||
|
writeFile(LITTLEFS, "/hello.txt", "Hello ");
|
||||||
|
appendFile(LITTLEFS, "/hello.txt", "World!\r\n");
|
||||||
|
readFile(LITTLEFS, "/hello.txt");
|
||||||
|
renameFile(LITTLEFS, "/hello.txt", "/foo.txt");
|
||||||
|
readFile(LITTLEFS, "/foo.txt");
|
||||||
|
deleteFile(LITTLEFS, "/foo.txt");
|
||||||
|
testFileIO(LITTLEFS, "/test.txt");
|
||||||
|
deleteFile(LITTLEFS, "/test.txt");
|
||||||
|
|
||||||
|
Serial.println( "Test complete" );
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop(){
|
||||||
|
|
||||||
|
}
|
||||||
219
lib/LITTLEFS/examples/LITTLEFS_time/LITTLEFS_time.ino
Normal file
219
lib/LITTLEFS/examples/LITTLEFS_time/LITTLEFS_time.ino
Normal file
@@ -0,0 +1,219 @@
|
|||||||
|
#include "FS.h"
|
||||||
|
//#include "SPIFFS.h"
|
||||||
|
#include "LITTLEFS.h"
|
||||||
|
#include <time.h>
|
||||||
|
#include <WiFi.h>
|
||||||
|
|
||||||
|
#define SPIFFS LITTLEFS
|
||||||
|
|
||||||
|
/* This examples uses "quick re-define" of SPIFFS to run
|
||||||
|
an existing sketch with LITTLEFS instead of SPIFFS
|
||||||
|
|
||||||
|
To get time/date stamps by file.getLastWrite(), you need an
|
||||||
|
esp32 core on IDF 3.3 and comment a line in file esp_littlefs.c:
|
||||||
|
|
||||||
|
//#define CONFIG_LITTLEFS_FOR_IDF_3_2
|
||||||
|
|
||||||
|
You only need to format LITTLEFS the first time you run a
|
||||||
|
test or else use the LITTLEFS plugin to create a partition
|
||||||
|
https://github.com/lorol/arduino-esp32littlefs-plugin */
|
||||||
|
|
||||||
|
#define FORMAT_LITTLEFS_IF_FAILED true
|
||||||
|
|
||||||
|
const char* ssid = "yourssid";
|
||||||
|
const char* password = "yourpass";
|
||||||
|
|
||||||
|
long timezone = 1;
|
||||||
|
byte daysavetime = 1;
|
||||||
|
|
||||||
|
void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
|
||||||
|
Serial.printf("Listing directory: %s\n", dirname);
|
||||||
|
|
||||||
|
File root = fs.open(dirname);
|
||||||
|
if(!root){
|
||||||
|
Serial.println("Failed to open directory");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(!root.isDirectory()){
|
||||||
|
Serial.println("Not a directory");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
File file = root.openNextFile();
|
||||||
|
while(file){
|
||||||
|
if(file.isDirectory()){
|
||||||
|
Serial.print(" DIR : ");
|
||||||
|
Serial.print (file.name());
|
||||||
|
time_t t= file.getLastWrite();
|
||||||
|
struct tm * tmstruct = localtime(&t);
|
||||||
|
Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n",(tmstruct->tm_year)+1900,( tmstruct->tm_mon)+1, tmstruct->tm_mday,tmstruct->tm_hour , tmstruct->tm_min, tmstruct->tm_sec);
|
||||||
|
if(levels){
|
||||||
|
listDir(fs, file.name(), levels -1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Serial.print(" FILE: ");
|
||||||
|
Serial.print(file.name());
|
||||||
|
Serial.print(" SIZE: ");
|
||||||
|
Serial.print(file.size());
|
||||||
|
time_t t= file.getLastWrite();
|
||||||
|
struct tm * tmstruct = localtime(&t);
|
||||||
|
Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n",(tmstruct->tm_year)+1900,( tmstruct->tm_mon)+1, tmstruct->tm_mday,tmstruct->tm_hour , tmstruct->tm_min, tmstruct->tm_sec);
|
||||||
|
}
|
||||||
|
file = root.openNextFile();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void createDir(fs::FS &fs, const char * path){
|
||||||
|
Serial.printf("Creating Dir: %s\n", path);
|
||||||
|
if(fs.mkdir(path)){
|
||||||
|
Serial.println("Dir created");
|
||||||
|
} else {
|
||||||
|
Serial.println("mkdir failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void removeDir(fs::FS &fs, const char * path){
|
||||||
|
Serial.printf("Removing Dir: %s\n", path);
|
||||||
|
if(fs.rmdir(path)){
|
||||||
|
Serial.println("Dir removed");
|
||||||
|
} else {
|
||||||
|
Serial.println("rmdir failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void readFile(fs::FS &fs, const char * path){
|
||||||
|
Serial.printf("Reading file: %s\n", path);
|
||||||
|
|
||||||
|
File file = fs.open(path);
|
||||||
|
if(!file){
|
||||||
|
Serial.println("Failed to open file for reading");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.print("Read from file: ");
|
||||||
|
while(file.available()){
|
||||||
|
Serial.write(file.read());
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void writeFile(fs::FS &fs, const char * path, const char * message){
|
||||||
|
Serial.printf("Writing file: %s\n", path);
|
||||||
|
|
||||||
|
File file = fs.open(path, FILE_WRITE);
|
||||||
|
if(!file){
|
||||||
|
Serial.println("Failed to open file for writing");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(file.print(message)){
|
||||||
|
Serial.println("File written");
|
||||||
|
} else {
|
||||||
|
Serial.println("Write failed");
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void appendFile(fs::FS &fs, const char * path, const char * message){
|
||||||
|
Serial.printf("Appending to file: %s\n", path);
|
||||||
|
|
||||||
|
File file = fs.open(path, FILE_APPEND);
|
||||||
|
if(!file){
|
||||||
|
Serial.println("Failed to open file for appending");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(file.print(message)){
|
||||||
|
Serial.println("Message appended");
|
||||||
|
} else {
|
||||||
|
Serial.println("Append failed");
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void renameFile(fs::FS &fs, const char * path1, const char * path2){
|
||||||
|
Serial.printf("Renaming file %s to %s\n", path1, path2);
|
||||||
|
if (fs.rename(path1, path2)) {
|
||||||
|
Serial.println("File renamed");
|
||||||
|
} else {
|
||||||
|
Serial.println("Rename failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void deleteFile(fs::FS &fs, const char * path){
|
||||||
|
Serial.printf("Deleting file: %s\n", path);
|
||||||
|
if(fs.remove(path)){
|
||||||
|
Serial.println("File deleted");
|
||||||
|
} else {
|
||||||
|
Serial.println("Delete failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup(){
|
||||||
|
Serial.begin(115200);
|
||||||
|
// We start by connecting to a WiFi network
|
||||||
|
Serial.println();
|
||||||
|
Serial.println();
|
||||||
|
Serial.print("Connecting to ");
|
||||||
|
Serial.println(ssid);
|
||||||
|
|
||||||
|
WiFi.begin(ssid, password);
|
||||||
|
|
||||||
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
|
delay(500);
|
||||||
|
Serial.print(".");
|
||||||
|
}
|
||||||
|
Serial.println("WiFi connected");
|
||||||
|
Serial.println("IP address: ");
|
||||||
|
Serial.println(WiFi.localIP());
|
||||||
|
Serial.println("Contacting Time Server");
|
||||||
|
configTime(3600*timezone, daysavetime*3600, "time.nist.gov", "0.pool.ntp.org", "1.pool.ntp.org");
|
||||||
|
struct tm tmstruct ;
|
||||||
|
delay(2000);
|
||||||
|
tmstruct.tm_year = 0;
|
||||||
|
getLocalTime(&tmstruct, 5000);
|
||||||
|
Serial.printf("\nNow is : %d-%02d-%02d %02d:%02d:%02d\n",(tmstruct.tm_year)+1900,( tmstruct.tm_mon)+1, tmstruct.tm_mday,tmstruct.tm_hour , tmstruct.tm_min, tmstruct.tm_sec);
|
||||||
|
Serial.println("");
|
||||||
|
|
||||||
|
if(!SPIFFS.begin(FORMAT_LITTLEFS_IF_FAILED)){
|
||||||
|
Serial.println("LITTLEFS Mount Failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println("----list 1----");
|
||||||
|
listDir(SPIFFS, "/", 1);
|
||||||
|
|
||||||
|
Serial.println("----remove old dir----");
|
||||||
|
removeDir(SPIFFS, "/mydir");
|
||||||
|
|
||||||
|
Serial.println("----create a new dir----");
|
||||||
|
createDir(SPIFFS, "/mydir");
|
||||||
|
|
||||||
|
Serial.println("----remove the new dir----");
|
||||||
|
removeDir(SPIFFS, "/mydir");
|
||||||
|
|
||||||
|
Serial.println("----create the new again----");
|
||||||
|
createDir(SPIFFS, "/mydir");
|
||||||
|
|
||||||
|
Serial.println("----create and work with file----");
|
||||||
|
writeFile(SPIFFS, "/mydir/hello.txt", "Hello ");
|
||||||
|
appendFile(SPIFFS, "/mydir/hello.txt", "World!\n");
|
||||||
|
|
||||||
|
Serial.println("----list 2----");
|
||||||
|
listDir(SPIFFS, "/", 1);
|
||||||
|
|
||||||
|
Serial.println("----attempt to remove dir w/ file----");
|
||||||
|
removeDir(SPIFFS, "/mydir");
|
||||||
|
|
||||||
|
Serial.println("----remove dir after deleting file----");
|
||||||
|
deleteFile(SPIFFS, "/mydir/hello.txt");
|
||||||
|
removeDir(SPIFFS, "/mydir");
|
||||||
|
|
||||||
|
Serial.println("----list 3----");
|
||||||
|
listDir(SPIFFS, "/", 1);
|
||||||
|
|
||||||
|
Serial.println( "Test complete" );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop(){
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,9 +2,10 @@
|
|||||||
#include "FS.h"
|
#include "FS.h"
|
||||||
#include <LITTLEFS.h>
|
#include <LITTLEFS.h>
|
||||||
|
|
||||||
/* You only need to format SPIFFS the first time you run a
|
/* You only need to format LITTLEFS the first time you run a
|
||||||
test or else use the LITTLEFS plugin to create a partition
|
test or else use the LITTLEFS plugin to create a partition
|
||||||
https://github.com/me-no-dev/arduino-esp32fs-plugin */
|
https://github.com/lorol/arduino-esp32littlefs-plugin */
|
||||||
|
|
||||||
#define FORMAT_LITTLEFS_IF_FAILED true
|
#define FORMAT_LITTLEFS_IF_FAILED true
|
||||||
|
|
||||||
void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
|
void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
|
||||||
@@ -38,6 +39,24 @@ void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void createDir(fs::FS &fs, const char * path){
|
||||||
|
Serial.printf("Creating Dir: %s\n", path);
|
||||||
|
if(fs.mkdir(path)){
|
||||||
|
Serial.println("Dir created");
|
||||||
|
} else {
|
||||||
|
Serial.println("mkdir failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void removeDir(fs::FS &fs, const char * path){
|
||||||
|
Serial.printf("Removing Dir: %s\n", path);
|
||||||
|
if(fs.rmdir(path)){
|
||||||
|
Serial.println("Dir removed");
|
||||||
|
} else {
|
||||||
|
Serial.println("rmdir failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void readFile(fs::FS &fs, const char * path){
|
void readFile(fs::FS &fs, const char * path){
|
||||||
Serial.printf("Reading file: %s\r\n", path);
|
Serial.printf("Reading file: %s\r\n", path);
|
||||||
|
|
||||||
@@ -104,6 +123,66 @@ void deleteFile(fs::FS &fs, const char * path){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SPIFFS-like write and delete file
|
||||||
|
|
||||||
|
// See: https://github.com/esp8266/Arduino/blob/master/libraries/LittleFS/src/LittleFS.cpp#L60
|
||||||
|
void writeFile2(fs::FS &fs, const char * path, const char * message){
|
||||||
|
if(!fs.exists(path)){
|
||||||
|
if (strchr(path, '/')) {
|
||||||
|
Serial.printf("Create missing folders of: %s\r\n", path);
|
||||||
|
char *pathStr = strdup(path);
|
||||||
|
if (pathStr) {
|
||||||
|
char *ptr = strchr(pathStr, '/');
|
||||||
|
while (ptr) {
|
||||||
|
*ptr = 0;
|
||||||
|
fs.mkdir(pathStr);
|
||||||
|
*ptr = '/';
|
||||||
|
ptr = strchr(ptr+1, '/');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(pathStr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.printf("Writing file to: %s\r\n", path);
|
||||||
|
File file = fs.open(path, FILE_WRITE);
|
||||||
|
if(!file){
|
||||||
|
Serial.println("- failed to open file for writing");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(file.print(message)){
|
||||||
|
Serial.println("- file written");
|
||||||
|
} else {
|
||||||
|
Serial.println("- write failed");
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// See: https://github.com/esp8266/Arduino/blob/master/libraries/LittleFS/src/LittleFS.h#L149
|
||||||
|
void deleteFile2(fs::FS &fs, const char * path){
|
||||||
|
Serial.printf("Deleting file and empty folders on path: %s\r\n", path);
|
||||||
|
|
||||||
|
if(fs.remove(path)){
|
||||||
|
Serial.println("- file deleted");
|
||||||
|
} else {
|
||||||
|
Serial.println("- delete failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
char *pathStr = strdup(path);
|
||||||
|
if (pathStr) {
|
||||||
|
char *ptr = strrchr(pathStr, '/');
|
||||||
|
if (ptr) {
|
||||||
|
Serial.printf("Removing all empty folders on path: %s\r\n", path);
|
||||||
|
}
|
||||||
|
while (ptr) {
|
||||||
|
*ptr = 0;
|
||||||
|
fs.rmdir(pathStr);
|
||||||
|
ptr = strrchr(pathStr, '/');
|
||||||
|
}
|
||||||
|
free(pathStr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void testFileIO(fs::FS &fs, const char * path){
|
void testFileIO(fs::FS &fs, const char * path){
|
||||||
Serial.printf("Testing file I/O with %s\r\n", path);
|
Serial.printf("Testing file I/O with %s\r\n", path);
|
||||||
|
|
||||||
@@ -164,8 +243,18 @@ void setup(){
|
|||||||
Serial.println("LITTLEFS Mount Failed");
|
Serial.println("LITTLEFS Mount Failed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Serial.println( "SPIFFS-like write file to new path and delete it w/folders" );
|
||||||
|
writeFile2(LITTLEFS, "/new1/new2/new3/hello3.txt", "Hello3");
|
||||||
|
listDir(LITTLEFS, "/", 3);
|
||||||
|
deleteFile2(LITTLEFS, "/new1/new2/new3/hello3.txt");
|
||||||
|
|
||||||
listDir(LITTLEFS, "/", 0);
|
listDir(LITTLEFS, "/", 3);
|
||||||
|
createDir(LITTLEFS, "/mydir");
|
||||||
|
writeFile(LITTLEFS, "/mydir/hello2.txt", "Hello2");
|
||||||
|
listDir(LITTLEFS, "/", 1);
|
||||||
|
deleteFile(LITTLEFS, "/mydir/hello2.txt");
|
||||||
|
removeDir(LITTLEFS, "/mydir");
|
||||||
|
listDir(LITTLEFS, "/", 1);
|
||||||
writeFile(LITTLEFS, "/hello.txt", "Hello ");
|
writeFile(LITTLEFS, "/hello.txt", "Hello ");
|
||||||
appendFile(LITTLEFS, "/hello.txt", "World!\r\n");
|
appendFile(LITTLEFS, "/hello.txt", "World!\r\n");
|
||||||
readFile(LITTLEFS, "/hello.txt");
|
readFile(LITTLEFS, "/hello.txt");
|
||||||
@@ -174,6 +263,7 @@ void setup(){
|
|||||||
deleteFile(LITTLEFS, "/foo.txt");
|
deleteFile(LITTLEFS, "/foo.txt");
|
||||||
testFileIO(LITTLEFS, "/test.txt");
|
testFileIO(LITTLEFS, "/test.txt");
|
||||||
deleteFile(LITTLEFS, "/test.txt");
|
deleteFile(LITTLEFS, "/test.txt");
|
||||||
|
|
||||||
Serial.println( "Test complete" );
|
Serial.println( "Test complete" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"name":"LITTLEFS",
|
"name":"LittleFS_esp32",
|
||||||
"description":"LITTLEFS File System Library for ESP32",
|
"description":"LittleFS for esp32",
|
||||||
"keywords":"littlefs, spiffs",
|
"keywords":"littlefs, spiffs",
|
||||||
"authors":
|
"authors":
|
||||||
{
|
{
|
||||||
"name": "LL",
|
"name": "lorol",
|
||||||
"maintainer": true
|
"maintainer": true
|
||||||
},
|
},
|
||||||
"repository":
|
"repository":
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
name=LITTLEFS
|
name=LittleFS_esp32
|
||||||
version=1.0
|
version=1.0
|
||||||
author=LL
|
author=lorol
|
||||||
maintainer=LL
|
maintainer=lorol
|
||||||
sentence=ESP32 LITTLEFS File System
|
sentence=LittleFS for esp32
|
||||||
paragraph=
|
paragraph=LittleFS for esp32
|
||||||
category=Data Storage
|
category=Data Storage
|
||||||
url=
|
url=https://github.com/lorol/LITTLEFS
|
||||||
architectures=esp32
|
architectures=esp32
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -13,22 +13,27 @@
|
|||||||
#include <sys/reent.h>
|
#include <sys/reent.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/termios.h>
|
//#include <sys/termios.h>
|
||||||
#include <sys/poll.h>
|
#include <sys/poll.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
|
|
||||||
#include "lfs.h"
|
#include "lfs.h" //#include "littlefs/lfs.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
enum {
|
/**
|
||||||
LITTLEFS_ATTR_MTIME, /**< Last Modified - time (seconds) */
|
* @brief Last Modified Time
|
||||||
LITTLEFS_ATTR_MAX
|
*
|
||||||
};
|
* Use 't' for LITTLEFS_ATTR_MTIME to match example:
|
||||||
|
* https://github.com/ARMmbed/littlefs/issues/23#issuecomment-482293539
|
||||||
|
* And to match other external tools such as:
|
||||||
|
* https://github.com/earlephilhower/mklittlefs
|
||||||
|
*/
|
||||||
|
#define LITTLEFS_ATTR_MTIME ((uint8_t) 't')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*Configuration structure for esp_vfs_littlefs_register.
|
*Configuration structure for esp_vfs_littlefs_register.
|
||||||
|
|||||||
@@ -2,6 +2,11 @@
|
|||||||
* @file littlefs_api.c
|
* @file littlefs_api.c
|
||||||
* @brief Maps the HAL of esp_partition <-> littlefs
|
* @brief Maps the HAL of esp_partition <-> littlefs
|
||||||
* @author Brian Pugh
|
* @author Brian Pugh
|
||||||
|
*
|
||||||
|
* Copyright 2020 Brian Pugh
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define ESP_LOCAL_LOG_LEVEL ESP_LOG_INFO
|
#define ESP_LOCAL_LOG_LEVEL ESP_LOG_INFO
|
||||||
|
|||||||
Reference in New Issue
Block a user