10 ESP_LOGI(__FILENAME__,
11 "Not loading configuration: no config_path specified: %s",
22 File f = SPIFFS.open(filename,
"r");
23 JsonDocument json_doc;
24 auto error = deserializeJson(json_doc, f);
27 ESP_LOGW(__FILENAME__,
"Could not parse configuration for %s",
31 JsonObject obj = json_doc.as<JsonObject>();
33 ESP_LOGW(__FILENAME__,
"Could not convert configuration to Json for %s",
37 ESP_LOGD(__FILENAME__,
"Configuration loaded for %s",
config_path_.c_str());
50 SPIFFS.remove(filename);
53 JsonDocument json_doc;
54 JsonObject obj = json_doc.to<JsonObject>();
56 ESP_LOGW(__FILENAME__,
"Could not get configuration from json for %s",
60 File f = SPIFFS.open(hash_path,
"w");
61 serializeJson(obj, f);
65 serializeJson(obj, str);
66 ESP_LOGV(__FILENAME__,
"Configuration saved for %s: %s",
config_path_.c_str(),
84 if (SPIFFS.exists(hash_path)) {
85 SPIFFS.remove(hash_path);
92 String hash_path = String(
"/") +
Base64Sha1(config_path);
93 String paths_to_check[] = {hash_path, hash_path +
"\n"};
96 for (
const auto& path : paths_to_check) {
97 if (SPIFFS.exists(path)) {
104 if (config_path.length() < 32 && SPIFFS.exists(config_path)) {
105 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.