10 ESP_LOGI(__FILENAME__,
11 "Not loading configuration: no config_path specified: %s",
21 File f = SPIFFS.open(filename,
"r");
22 JsonDocument json_doc;
23 auto error = deserializeJson(json_doc, f);
26 ESP_LOGW(__FILENAME__,
"Could not parse configuration for %s",
30 JsonObject obj = json_doc.as<JsonObject>();
32 ESP_LOGW(__FILENAME__,
"Could not parse configuration from Json for %s",
36 ESP_LOGD(__FILENAME__,
"Configuration loaded for %s",
config_path_.c_str());
49 SPIFFS.remove(filename);
52 JsonDocument json_doc;
53 JsonObject obj = json_doc.to<JsonObject>();
55 ESP_LOGW(__FILENAME__,
"Could not get configuration from json for %s",
59 File f = SPIFFS.open(hash_path,
"w");
60 serializeJson(obj, f);
64 serializeJson(obj, str);
65 ESP_LOGV(__FILENAME__,
"Configuration saved for %s: %s",
config_path_.c_str(),
83 if (SPIFFS.exists(hash_path)) {
84 SPIFFS.remove(hash_path);
91 String hash_path = String(
"/") +
Base64Sha1(config_path);
92 String paths_to_check[] = {hash_path, hash_path +
"\n"};
95 for (
const auto& path : paths_to_check) {
96 if (SPIFFS.exists(path)) {
103 if (config_path.length() < 32 && SPIFFS.exists(config_path)) {
104 filename = config_path;
virtual bool clear() override
Delete the data from a persistent storage.
virtual bool load() override
Load and populate the object from a persistent storage.
virtual bool save() override
Save the object to a persistent storage.
bool find_config_file(const String &config_path, String &filename)
const String config_path_
virtual bool from_json(const JsonObject &root)
virtual bool to_json(JsonObject &root)
String Base64Sha1(const String &payload_str)
A base64-encoded SHA-1 hash function.