Skip to content

Commit 75d0c08

Browse files
Copilotdorkmo
andcommitted
Replace SD library with LittleFS for internal flash storage
Co-authored-by: dorkmo <[email protected]>
1 parent cd2fc6a commit 75d0c08

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

TankAlarm-112025-Server-BluesOpta/TankAlarm-112025-Server-BluesOpta.ino

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#else
3030
#include <Ethernet.h>
3131
#endif
32-
#include <SD.h>
3332
#include <math.h>
3433
#include <string.h>
3534
#include <ctype.h>
@@ -1920,14 +1919,22 @@ static bool ftpRestoreClientConfigs(FtpSession &session, char *error, size_t err
19201919
}
19211920

19221921
// Open cache file for writing (truncate)
1923-
if (SD.exists(CLIENT_CONFIG_CACHE_PATH)) {
1924-
SD.remove(CLIENT_CONFIG_CACHE_PATH);
1922+
#if defined(ARDUINO_OPTA) || defined(ARDUINO_ARCH_MBED)
1923+
FILE *cacheFile = fopen("/fs/client_config_cache.txt", "w");
1924+
if (!cacheFile) {
1925+
snprintf(error, errorSize, "Failed to open cache file");
1926+
return false;
19251927
}
1926-
SDLib::File cacheFile = SD.open(CLIENT_CONFIG_CACHE_PATH, FILE_WRITE);
1928+
#else
1929+
if (LittleFS.exists(CLIENT_CONFIG_CACHE_PATH)) {
1930+
LittleFS.remove(CLIENT_CONFIG_CACHE_PATH);
1931+
}
1932+
File cacheFile = LittleFS.open(CLIENT_CONFIG_CACHE_PATH, "w");
19271933
if (!cacheFile) {
19281934
snprintf(error, errorSize, "Failed to open cache file");
19291935
return false;
19301936
}
1937+
#endif
19311938

19321939
// Parse manifest lines: uid \t site
19331940
char *lineStart = manifest;
@@ -1975,10 +1982,14 @@ static bool ftpRestoreClientConfigs(FtpSession &session, char *error, size_t err
19751982
while(cEnd >= cStart && isspace(*cEnd)) *cEnd-- = 0;
19761983

19771984
if (strlen(cStart) > 0) {
1985+
#if defined(ARDUINO_OPTA) || defined(ARDUINO_ARCH_MBED)
1986+
fprintf(cacheFile, "%s\t%s\n", uid, cStart);
1987+
#else
19781988
cacheFile.print(uid);
19791989
cacheFile.print('\t');
19801990
cacheFile.print(cStart);
19811991
cacheFile.print('\n');
1992+
#endif
19821993
restoredFiles++;
19831994
Serial.print(F("FTP restore client config: "));
19841995
Serial.println(remotePath);
@@ -1991,7 +2002,11 @@ static bool ftpRestoreClientConfigs(FtpSession &session, char *error, size_t err
19912002
lineStart = lineEnd + 1;
19922003
}
19932004

2005+
#if defined(ARDUINO_OPTA) || defined(ARDUINO_ARCH_MBED)
2006+
fclose(cacheFile);
2007+
#else
19942008
cacheFile.close();
2009+
#endif
19952010
return true;
19962011
}
19972012

0 commit comments

Comments
 (0)