mirror of
https://github.com/Genaker/LoraSA.git
synced 2026-05-05 13:02:51 +02:00
44 lines
925 B
C
44 lines
925 B
C
#include "FS.h"
|
|
#include <LittleFS.h>
|
|
|
|
String 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 String("");
|
|
}
|
|
String content;
|
|
Serial.println("- read from file:");
|
|
while (file.available())
|
|
{
|
|
content = file.readStringUntil('\n');
|
|
}
|
|
file.close();
|
|
return content;
|
|
}
|
|
|
|
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();
|
|
}
|