|
1 | | -#include "FS.h" |
2 | | -#include "SPIFFS.h" |
| 1 | +#include <BytebeamArduino.h> |
3 | 2 |
|
4 | 3 | /* This macro is used to specify the base path of the spiffs partiiton */ |
5 | 4 | #define SPIFFS_BASE_PATH "/spiffs" |
|
8 | 7 | #define FORMAT_SPIFFS_IF_FAILED true |
9 | 8 |
|
10 | 9 | /* This macro is used to format the spiffs in the beginnig i.e reset if not required */ |
11 | | -#define FORMAT_SPIFSS_IN_BEGINNING true |
| 10 | +#define FORMAT_SPIFSS_IN_BEGINNING true |
12 | 11 |
|
13 | 12 | /* This macro is used to specify the name of the device config file */ |
14 | 13 | #define DEVICE_CONFIG_FILE_NAME "/device_config.json" |
@@ -36,36 +35,53 @@ char deviceConfigWriteStr[DEVICE_CONFIG_STR_LENGTH] = R"( |
36 | 35 | } |
37 | 36 | )"; |
38 | 37 |
|
39 | | -void listDir(fs::FS &fs, const char *dirname, uint8_t levels) { |
40 | | - Serial.printf("Listing directory : %s\r\n", dirname); |
| 38 | +#if defined(BYTEBEAM_ARDUINO_ARCH_ESP32) |
| 39 | + void listDir(fs::FS &fs, const char *dirname, uint8_t levels) { |
| 40 | + Serial.printf("Listing directory : %s\r\n", dirname); |
41 | 41 |
|
42 | | - File root = fs.open(dirname); |
43 | | - if (!root) { |
44 | | - Serial.println("- failed to open directory"); |
45 | | - return; |
46 | | - } |
47 | | - if (!root.isDirectory()) { |
48 | | - Serial.println(" - not a directory"); |
49 | | - return; |
50 | | - } |
| 42 | + File root = fs.open(dirname); |
| 43 | + if (!root) { |
| 44 | + Serial.println("- failed to open directory"); |
| 45 | + return; |
| 46 | + } |
| 47 | + if (!root.isDirectory()) { |
| 48 | + Serial.println(" - not a directory"); |
| 49 | + return; |
| 50 | + } |
51 | 51 |
|
52 | | - File file = root.openNextFile(); |
53 | | - while (file) { |
54 | | - if (file.isDirectory()) { |
55 | | - Serial.print(" - DIR : "); |
56 | | - Serial.println(file.name()); |
57 | | - if (levels) { |
58 | | - listDir(fs, file.name(), levels - 1); |
| 52 | + File file = root.openNextFile(); |
| 53 | + while (file) { |
| 54 | + if (file.isDirectory()) { |
| 55 | + Serial.print(" - DIR : "); |
| 56 | + Serial.println(file.name()); |
| 57 | + if (levels) { |
| 58 | + listDir(fs, file.name(), levels - 1); |
| 59 | + } |
| 60 | + } else { |
| 61 | + Serial.print(" - FILE: "); |
| 62 | + Serial.print(file.name()); |
| 63 | + Serial.print("\tSIZE: "); |
| 64 | + Serial.println(file.size()); |
59 | 65 | } |
60 | | - } else { |
61 | | - Serial.print(" - FILE: "); |
62 | | - Serial.print(file.name()); |
63 | | - Serial.print("\tSIZE: "); |
64 | | - Serial.println(file.size()); |
| 66 | + file = root.openNextFile(); |
65 | 67 | } |
66 | | - file = root.openNextFile(); |
| 68 | + } |
| 69 | +#elif defined(BYTEBEAM_ARDUINO_ARCH_ESP8266) |
| 70 | + void listDir(fs::FS &fs, const char *dirname, uint8_t levels) { |
| 71 | + Serial.printf("Listing directory: %s\n", dirname); |
| 72 | + |
| 73 | + Dir root = fs.openDir(dirname); |
| 74 | + |
| 75 | + while (root.next()) { |
| 76 | + File file = root.openFile("r"); |
| 77 | + Serial.print(" - FILE: "); |
| 78 | + Serial.print(root.fileName()); |
| 79 | + Serial.print("\tSIZE: "); |
| 80 | + Serial.println(file.size()); |
| 81 | + file.close(); |
67 | 82 | } |
68 | 83 | } |
| 84 | +#endif |
69 | 85 |
|
70 | 86 | void readFile(fs::FS &fs, const char *path, char *message) { |
71 | 87 | Serial.printf("Reading file : %s\r\n", path); |
@@ -117,8 +133,16 @@ void setup() { |
117 | 133 | } |
118 | 134 | #endif |
119 | 135 |
|
| 136 | + bool beginStatus = false; |
| 137 | + |
120 | 138 | // initalize the spiffs file system |
121 | | - if (!SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED, SPIFFS_BASE_PATH)) { |
| 139 | + #if defined(BYTEBEAM_ARDUINO_ARCH_ESP32) |
| 140 | + beginStatus = SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED, SPIFFS_BASE_PATH); |
| 141 | + #elif defined(BYTEBEAM_ARDUINO_ARCH_ESP8266) |
| 142 | + beginStatus = SPIFFS.begin(); |
| 143 | + #endif |
| 144 | + |
| 145 | + if (!beginStatus) { |
122 | 146 | Serial.println("spiffs mount failed"); |
123 | 147 | return; |
124 | 148 | } else { |
|
0 commit comments