From ac6cd6a3f0ee6906c534740f2dac65bc9d8dd248 Mon Sep 17 00:00:00 2001 From: cosmicpsyop Date: Sat, 13 Apr 2024 14:02:47 -0700 Subject: [PATCH] add pool data api discovery --- src/monitor.cpp | 43 ++++++++++++++++++++++++++++++++++++++++++- src/monitor.h | 2 +- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/monitor.cpp b/src/monitor.cpp index df6c889..0d129a0 100644 --- a/src/monitor.cpp +++ b/src/monitor.cpp @@ -32,6 +32,8 @@ unsigned int bitcoin_price=0; String current_block = "793261"; global_data gData; pool_data pData; +String poolAPIUrl; + void setup_monitor(void){ /******** TIME ZONE SETTING *****/ @@ -42,7 +44,11 @@ void setup_monitor(void){ // GMT +2 in seconds (zona horaria de Europa Central) timeClient.setTimeOffset(3600 * Settings.Timezone); - Serial.println("TimeClient setup done"); + Serial.println("TimeClient setup done"); +#ifdef NERDMINER_T_HMI + poolAPIUrl = getPoolAPIUrl(); + Serial.println("poolAPIUrl: " + poolAPIUrl); +#endif } unsigned long mGlobalUpdate =0; @@ -317,6 +323,36 @@ coin_data getCoinData(unsigned long mElapsed) return data; } +String getPoolAPIUrl(void) { + poolAPIUrl = String(getPublicPool); + if (Settings.PoolAddress == "public-pool.io") { + poolAPIUrl = "https://public-pool.io:40557/api/client/"; + } + else { + if (Settings.PoolAddress == "nerdminers.org") { + poolAPIUrl = "https://pool.nerdminers.org/users/"; + } + else { + switch (Settings.PoolPort) { + case 3333: + if (Settings.PoolAddress == "pool.vkbit.com") + poolAPIUrl = "https://vkbit.com/miner/"; + else if (Settings.PoolAddress == "pool.sethforprivacy.com") + poolAPIUrl = "https://pool.sethforprivacy.com/api/client/"; + // Add more cases for other addresses with port 3333 if needed + break; + case 2018: + poolAPIUrl = "http://" + Settings.PoolAddress + ":2019/api/client/"; + break; + default: + poolAPIUrl = String(getPublicPool); + break; + } + } + } + return poolAPIUrl; +} + pool_data getPoolData(void){ //pool_data pData; if((mPoolUpdate == 0) || (millis() - mPoolUpdate > UPDATE_POOL_min * 60 * 1000)){ @@ -329,7 +365,12 @@ pool_data getPoolData(void){ String btcWallet = Settings.BtcWallet; Serial.println(btcWallet); if (btcWallet.indexOf(".")>0) btcWallet = btcWallet.substring(0,btcWallet.indexOf(".")); +#ifdef NERDMINER_T_HMI + Serial.println("Pool API : " + poolAPIUrl+btcWallet); + http.begin(poolAPIUrl+btcWallet); +#else http.begin(String(getPublicPool)+btcWallet); +#endif int httpCode = http.GET(); if (httpCode == HTTP_CODE_OK) { String payload = http.getString(); diff --git a/src/monitor.h b/src/monitor.h index ff89c19..8c458d2 100644 --- a/src/monitor.h +++ b/src/monitor.h @@ -127,6 +127,6 @@ coin_data getCoinData(unsigned long mElapsed); pool_data getPoolData(void); clock_data_t getClockData_t(unsigned long mElapsed); - +String getPoolAPIUrl(void); #endif //MONITOR_API_H