From 8eb1e3cc5b30b16d7363325355a11ad9c7ba4377 Mon Sep 17 00:00:00 2001 From: dwightmulcahy Date: Thu, 14 Mar 2024 14:18:35 -0500 Subject: [PATCH] zero out stats now when a reset is done --- .gitignore | 1 + src/mining.cpp | 9 ++++++++- src/mining.h | 2 ++ src/wManager.cpp | 4 +++- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index f7eadc56..5db995f3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.idea/ .pio .vscode .vs diff --git a/src/mining.cpp b/src/mining.cpp index f292edfb..6190110d 100644 --- a/src/mining.cpp +++ b/src/mining.cpp @@ -43,7 +43,7 @@ monitor_data mMonitor; bool isMinerSuscribed = false; unsigned long mLastTXtoPool = millis(); -int saveIntervals[7] = {5 * 60, 15 * 60, 30 * 60, 1 * 360, 3 * 360, 6 * 360, 12 * 360}; +int saveIntervals[8] = {1 * 60, 5 * 60, 15 * 60, 30 * 60, 1 * 360, 3 * 360, 6 * 360, 12 * 360}; int saveIntervalsSize = sizeof(saveIntervals)/sizeof(saveIntervals[0]); int currentIntervalIndex = 0; @@ -399,6 +399,13 @@ void saveStat() { nvs_set_u64(stat_handle, "upTime", upTime + (esp_timer_get_time()/1000000)); } +void resetStat() { + Serial.printf("[MONITOR] Resetting NVS stats\n"); + templates = hashes = Mhashes = totalKHashes = elapsedKHs = upTime = shares = valids = 0; + best_diff = 0.0; + saveStat(); +} + void runMonitor(void *name) { diff --git a/src/mining.h b/src/mining.h index 2eff7073..a1adf140 100644 --- a/src/mining.h +++ b/src/mining.h @@ -17,6 +17,8 @@ void runStratumWorker(void *name); void runMiner(void *name); String printLocalTime(void); +void resetStat(); + typedef struct{ uint8_t bytearray_target[32]; uint8_t bytearray_pooltarget[32]; diff --git a/src/wManager.cpp b/src/wManager.cpp index 6b7e98f3..5b947a69 100644 --- a/src/wManager.cpp +++ b/src/wManager.cpp @@ -13,6 +13,7 @@ #include "drivers/storage/SDCard.h" #include "drivers/storage/nvMemory.h" #include "drivers/storage/storage.h" +#include "mining.h" // Flag for saving data @@ -53,6 +54,7 @@ void reset_configuration() { Serial.println("Erasing Config, restarting"); nvMem.deleteConfig(); + resetStat(); wm.resetSettings(); ESP.restart(); } @@ -149,7 +151,7 @@ void init_WifiManager() { strcat(checkboxParams, " checked"); } - WiFiManagerParameter save_stats_to_nvs("SaveStatsToNVS", "Track Uptime, Best Diff, Total Hashes in device Flash memory. (Experimental)", "T", 2, checkboxParams, WFM_LABEL_AFTER); + WiFiManagerParameter save_stats_to_nvs("SaveStatsToNVS", "Save mining statistics to flash memory.", "T", 2, checkboxParams, WFM_LABEL_AFTER); // Text box (String) - 80 characters maximum WiFiManagerParameter password_text_box("Poolpassword - Optionl", "Pool password", Settings.PoolPassword, 80);