From 6d245aa1ac43fb9c3a0e50c25dde4d756b2cd4cb Mon Sep 17 00:00:00 2001 From: Roman Mashta Date: Sun, 3 Sep 2023 23:52:24 +0300 Subject: [PATCH] Stack overflow issue for Monitor task fix --- src/NerdMinerV2.ino.cpp | 2 +- src/mining.cpp | 5 +++++ src/monitor.cpp | 31 +++++-------------------------- 3 files changed, 11 insertions(+), 27 deletions(-) diff --git a/src/NerdMinerV2.ino.cpp b/src/NerdMinerV2.ino.cpp index 0c7999b..94e802f 100644 --- a/src/NerdMinerV2.ino.cpp +++ b/src/NerdMinerV2.ino.cpp @@ -91,7 +91,7 @@ void setup() Serial.println("Initiating tasks..."); char *name = (char*) malloc(32); sprintf(name, "(%s)", "Monitor"); - BaseType_t res1 = xTaskCreatePinnedToCore(runMonitor, "Monitor", 5000, (void*)name, 4, NULL,1); + BaseType_t res1 = xTaskCreatePinnedToCore(runMonitor, "Monitor", 10000, (void*)name, 4, NULL,1); /******** CREATE STRATUM TASK *****/ sprintf(name, "(%s)", "Stratum"); diff --git a/src/mining.cpp b/src/mining.cpp index 2225d68..3d9d74b 100644 --- a/src/mining.cpp +++ b/src/mining.cpp @@ -405,6 +405,11 @@ void runMonitor(void *name) mMiner.newJob ? "true" : "false", mMiner.inRun ? "true" : "false", client.connected() ? "true" : "false", isMinerSuscribed ? "true" : "false", WiFi.status() == WL_CONNECTED ? "true" : "false"); } + + #ifdef DEBUG_MEMORY + Serial.printf("### [Total Heap / Free heap]: %d / %d \n", ESP.getHeapSize(), ESP.getFreeHeap()); + Serial.printf("### Max stack usage: %d\n", uxTaskGetStackHighWaterMark(NULL)); + #endif } animateCurrentScreen(frame); doLedStuff(frame); diff --git a/src/monitor.cpp b/src/monitor.cpp index 79f2571..a5c652e 100644 --- a/src/monitor.cpp +++ b/src/monitor.cpp @@ -55,7 +55,7 @@ void updateGlobalData(void){ http.begin(getGlobalHash); int httpCode = http.GET(); - if (httpCode > 0) { + if (httpCode == HTTP_CODE_OK) { String payload = http.getString(); DynamicJsonDocument doc(1024); @@ -75,33 +75,12 @@ void updateGlobalData(void){ } http.end(); - - //OLD code gets remaining blocks to next difficulty ajustment - /*//Make second API call to get remaining Blocks - http.begin(getDifficulty); - httpCode = http.GET(); - - if (httpCode > 0) { - String payload = http.getString(); - - DynamicJsonDocument doc(1024); - deserializeJson(doc, payload); - String temp = ""; - if (doc.containsKey("progressPercent")) gData.progressPercent = doc["progressPercent"].as(); - if (doc.containsKey("remainingBlocks")) gData.remainingBlocks = doc["remainingBlocks"].as(); - - doc.clear(); - - mGlobalUpdate = millis(); - } - - http.end();*/ - + //Make third API call to get fees http.begin(getFees); httpCode = http.GET(); - if (httpCode > 0) { + if (httpCode == HTTP_CODE_OK) { String payload = http.getString(); DynamicJsonDocument doc(1024); @@ -131,7 +110,7 @@ String getBlockHeight(void){ http.begin(getHeightAPI); int httpCode = http.GET(); - if (httpCode > 0) { + if (httpCode == HTTP_CODE_OK) { String payload = http.getString(); payload.trim(); @@ -159,7 +138,7 @@ String getBTCprice(void){ http.begin(getBTCAPI); int httpCode = http.GET(); - if (httpCode > 0) { + if (httpCode == HTTP_CODE_OK) { String payload = http.getString(); DynamicJsonDocument doc(1024);