#include "config.h" #include "log.h" #include Preferences config; void configSetup() { config.begin("config", false); const String &stored = config.getString("HOSTNAME", ""); if (!stored.equals(HOSTNAME)) { error(R"([WARNING] Stored config hostname mismatch: "%s" != "%s" [WARNING])", stored.c_str(), HOSTNAME); } } void configReset() { info("[CONFIG RESET]"); config.end(); nvs_flash_erase(); nvs_flash_init(); config.begin("config", false); config.putString("HOSTNAME", HOSTNAME); configLoad(); } String configGetString(const char *name, const char *fallback, bool allowEmpty) { if (!config.isKey(name)) { return fallback; } String value = config.getString(name); if (!allowEmpty && value.isEmpty()) { return fallback; } return value; } bool configPutString(const char *name, const char *value) { return config.putString(name, value) == strlen(value); } double configGetDouble(const char *name, double fallback) { if (!config.isKey(name)) { return fallback; } return config.getDouble(name); } bool configPutDouble(const char *name, double fallback) { return config.value(name, fallback) == 0; }