|
6 | 6 | #define PATH_TO_CONF "/config.json" |
7 | 7 |
|
8 | 8 | void loadConfiguration(Config& config) { |
9 | | - File file = SPIFFS.open(PATH_TO_CONF, "r"); |
| 9 | + File file = SPIFFS.open(PATH_TO_CONF, FILE_READ); |
10 | 10 | JsonDocument conf; |
11 | 11 |
|
12 | 12 | DeserializationError error = deserializeJson(conf, file); |
@@ -67,6 +67,57 @@ void loadConfiguration(Config& config) { |
67 | 67 | file.close(); |
68 | 68 | } |
69 | 69 |
|
| 70 | +void storeConfiguration(Config config) { |
| 71 | + SPIFFS.remove(PATH_TO_CONF); |
| 72 | + |
| 73 | + File file = SPIFFS.open(PATH_TO_CONF, FILE_WRITE); |
| 74 | + if (!file) { |
| 75 | + Serial.println(F("Failed to create file")); |
| 76 | + return; |
| 77 | + } |
| 78 | + |
| 79 | + JsonDocument conf; |
| 80 | + |
| 81 | + conf["STD_TIME"]["abbrev"] = config.std.abbrev; |
| 82 | + conf["STD_TIME"]["week"] = config.std.week; |
| 83 | + conf["STD_TIME"]["dow"] = config.std.dow; |
| 84 | + conf["STD_TIME"]["month"] = config.std.month; |
| 85 | + conf["STD_TIME"]["hour"] = config.std.hour; |
| 86 | + conf["STD_TIME"]["offset"] = config.std.offset; |
| 87 | + |
| 88 | + conf["DL_TIME"]["abbrev"] = config.dlt.abbrev; |
| 89 | + conf["DL_TIME"]["week"] = config.dlt.week; |
| 90 | + conf["DL_TIME"]["dow"] = config.dlt.dow; |
| 91 | + conf["DL_TIME"]["month"] = config.dlt.month; |
| 92 | + conf["DL_TIME"]["hour"] = config.dlt.hour; |
| 93 | + conf["DL_TIME"]["offset"] = config.dlt.offset; |
| 94 | + |
| 95 | + conf["I2C_ADDR"]["BME_280"] = config.i2c.BME_280; |
| 96 | + conf["I2C_ADDR"]["BH1750"] = config.i2c.BH1750; |
| 97 | + conf["I2C_ADDR"]["DS3231"] = config.i2c.DS3231; |
| 98 | + |
| 99 | + conf["MAX7219_PINS"]["CLK_PIN"] = config.max7219.CLK_PIN; |
| 100 | + conf["MAX7219_PINS"]["DATA_PIN"] = config.max7219.DATA_PIN; |
| 101 | + conf["MAX7219_PINS"]["CS_PIN"] = config.max7219.CS_PIN; |
| 102 | + |
| 103 | + conf["PINS"]["BUTTON_PIN"] = config.pins.BUTTON_PIN; |
| 104 | + conf["PINS"]["BUZZER_PIN"] = config.pins.BUZZER_PIN; |
| 105 | + |
| 106 | + conf["NTP_SERVER"] = config.ntpServer; |
| 107 | + conf["LANGUAGE"] = config.language; |
| 108 | + conf["BUZZ_SOUND"] = config.buzzSound; |
| 109 | + conf["FAHRENHEIT"] = config.fahrenheit; |
| 110 | + |
| 111 | + conf["WIFI"]["SSID"] = config.wifi.SSID; |
| 112 | + conf["WIFI"]["PASSWORD"] = config.wifi.PASSWORD; |
| 113 | + |
| 114 | + if (serializeJson(conf, file) == 0) { |
| 115 | + Serial.println(F("Failed to write to file")); |
| 116 | + } |
| 117 | + |
| 118 | + file.close(); |
| 119 | +} |
| 120 | + |
70 | 121 | void printConfiguration(Config config) { |
71 | 122 | Serial.printf("Standard TimeChangeRule:\n"); |
72 | 123 | Serial.printf(" Abbreviation: %s\n", config.std.abbrev); |
|
0 commit comments