Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions main/http_server/handler_alert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ esp_err_t POST_update_alert(httpd_req_t *req)

doc.clear();

Config::flush_nvs_changes(); // Commit batched alert settings to NVS
ESP_LOGI(TAG, "Alert configuration flushed to NVS");
httpd_resp_send_chunk(req, NULL, 0);

// reload discord alerter config
Expand Down
3 changes: 2 additions & 1 deletion main/http_server/handler_influx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ esp_err_t PATCH_update_influx(httpd_req_t *req)
}

doc.clear();

Config::flush_nvs_changes(); // Commit batched Influx settings to NVS
ESP_LOGI(TAG, "Influx configuration flushed to NVS");
httpd_resp_send_chunk(req, NULL, 0);
return ESP_OK;
}
3 changes: 3 additions & 0 deletions main/http_server/handler_restart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "global_state.h"
#include "http_cors.h"
#include "http_utils.h"
#include "nvs_config.h"

static const char *TAG = "http_restart";

Expand All @@ -19,6 +20,8 @@ esp_err_t POST_restart(httpd_req_t *req)

ESP_LOGI(TAG, "Restarting System because of API Request");

Config::flush_nvs_changes(); // Ensure persistent settings are saved

// Send HTTP response before restarting
const char *resp_str = "System will restart shortly.";
httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);
Expand Down
4 changes: 3 additions & 1 deletion main/http_server/handler_swarm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ esp_err_t PATCH_update_swarm(httpd_req_t *req)
buf[total_len] = '\0';

Config::setSwarmConfig(buf);
Config::flush_nvs_changes(); // Ensure Swarm config is written to flash
ESP_LOGI(TAG, "Swarm config flushed to NVS");
httpd_resp_send_chunk(req, NULL, 0);
return ESP_OK;
}
Expand All @@ -59,4 +61,4 @@ esp_err_t GET_swarm(httpd_req_t *req)
httpd_resp_sendstr(req, swarm_config);
free(swarm_config);
return ESP_OK;
}
}
4 changes: 4 additions & 0 deletions main/http_server/handler_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@ esp_err_t PATCH_update_settings(httpd_req_t *req)

doc.clear();

// Apply all changes to NVS in one go
Config::flush_nvs_changes();
ESP_LOGI(TAG, "Configuration changes flushed to NVS");

// Signal the end of the response
httpd_resp_send_chunk(req, NULL, 0);

Expand Down
4 changes: 3 additions & 1 deletion main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ extern "C" void app_main(void)
// shows and saves last reset reason
esp_reset_reason_t reason = SYSTEM_MODULE.showLastResetReason();

// initialize cache and mutex for config
Config::init_cache();

// migrate config
Config::migrate_config();

Expand Down Expand Up @@ -177,7 +180,6 @@ extern "C" void app_main(void)
board->loadSettings();
board->initBoard();


SYSTEM_MODULE.setBoard(board);

size_t total_psram = esp_psram_get_size();
Expand Down
Loading