#include "FS.h"
#include <LittleFS.h>
#include <ArduinoJson.h>
/* 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 filename to store config file
const String config_filename = "/config.json";
// Определяем переменные wifi
String _ssid = "RUL"; // Для хранения SSID подключение к сети с интернетом
String _password = "3F56cg23"; // Для хранения пароля сети подключение к сети с интернетом
String _ssidAP = "CY_OT"; // SSID AP точки доступа
String _passwordAP = ""; // пароль точки доступа
int timezone = 3; // часовой пояс GTM
// define filename to store config file
const char* filename = "/config.json";
// Write file to LittleFS
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();
}
bool saveConfig() {
//Выделите документ JSON
JsonDocument doc;
// Добавить значения в документ
doc["ssidAPName"] = _ssidAP;
doc["ssidAPPassword"] = _passwordAP;
doc["ssidName"] = _ssid;
doc["ssidPassword"] = _password;
doc["timezone"] = timezone;
//Сгенерируйте Minied JSON и отправьте его в последовательный порт.
String jsonConfig = "";
serializeJson(doc, jsonConfig);
// Convert the String to a const char*
//const char* Chartmp = tmp.c_str();
// write config file
writeFile(filename, jsonConfig.c_str());
return true;
}
void setup() {
// Start serial interface
Serial.begin(115200);
Serial.println("-----------------------------Start demo SPIFFS-----------------------------");
// Mount LITTLEFS and read in config file
if (!LittleFS.begin(false)) {
Serial.println("LITTLEFS Mount failed");
Serial.println("Did not find filesystem; starting format");
}
void loop() {
}
Добрый день уважаемые форумчане. У меня проблема с записью в файловую систему. При компиляции скетча выдаёт ошибку: exit status 1
Compilation error: invalid initialization of reference of type ‘fs::FS&’ from expression of type ‘const char*’
Я понимаю что void writeFile(fs::FS &fs, const char *path, const char *message) данные должны иметь формат const char * и я пробывал перевести переменную string в const char *.
Подобные проблемы и её решения были описаны на других форумах, все к сводится к присвоению объекту корректного формата. что я и сделал в первый раз
const char* Chartmp = jsonConfig.c_str();
//write config file
writeFile(filename, Chartmp);
и во второй раз
//write config file
writeFile(filename,jsonConfig.c_str();
и в первый и во второй раз получил ошибку
exit status 1
Compilation error: invalid initialization of reference of type ‘fs::FS&’ from expression of type ‘const char*’
Вопрос может кто-либо помочь разобратся, либо дать направление куда покопать?