From 40a6f5f6fbc39019269f3ba4b143e37b7ce64e67 Mon Sep 17 00:00:00 2001 From: "Alfonso C. Alvarez" Date: Sun, 4 Jun 2023 20:02:23 +0200 Subject: [PATCH] changed: fixed the closing of pool connection --- src/mining.cpp | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/src/mining.cpp b/src/mining.cpp index 1c75a5f..8b8cdf0 100644 --- a/src/mining.cpp +++ b/src/mining.cpp @@ -36,6 +36,24 @@ static miner_data mMiner; //Global miner data (Create a miner class TODO) mining_subscribe mWorker; mining_job mJob; +void checkPoolConnection(bool* isMinerSuscribed) { + + if (client.connected()) { + return; + } + + *isMinerSuscribed = false; + Serial.println("Client not connected, trying to connect..."); + IPAddress serverIP(1, 1, 1, 1); //Temporally save poolIPaddres + WiFi.hostByName(poolString, serverIP); + Serial.printf("Resolved DNS got: %s\n", serverIP.toString()); + if (!client.connect(poolString, portNumber)) { + Serial.println("Imposible to connect to : " + String(poolString)); + WiFi.hostByName(poolString, serverIP); + vTaskDelay(1000 / portTICK_PERIOD_MS); + } +} + void runStratumWorker(void *name) { // TEST: https://bitcoin.stackexchange.com/questions/22929/full-example-data-for-scrypt-stratum-client @@ -49,7 +67,6 @@ void runStratumWorker(void *name) { // connect to pool - IPAddress serverIP(1, 1, 1, 1); //Temporally save poolIPaddres float currentPoolDifficulty = atof(DEFAULT_DIFFICULTY); bool isMinerSuscribed = false; @@ -64,9 +81,9 @@ void runStratumWorker(void *name) { //Test vars: //************ //Nerdminerpool - strcpy(poolString, "nerdminerPool"); - portNumber = 3002; - strcpy(btcString,"test"); + // strcpy(poolString, "nerdminerPool"); + // portNumber = 3002; + // strcpy(btcString,"test"); //Braiins //strcpy(poolString, "eu.stratum.braiins.com"); //portNumber = 3333; @@ -76,17 +93,7 @@ void runStratumWorker(void *name) { //portNumber = 3333; //strcpy(btcString,"test"); - if (!client.connected()) { - isMinerSuscribed = false; - Serial.println("Client not connected, trying to connect..."); - if (!client.connect(serverIP, portNumber)) { - Serial.println("Imposible to connect to : " + String(poolString)); - WiFi.hostByName(poolString, serverIP); - Serial.print("Resolved DNS got : "); Serial.println(serverIP); - vTaskDelay(1000 / portTICK_PERIOD_MS); - continue; - } - } + checkPoolConnection(&isMinerSuscribed); if(!isMinerSuscribed){ @@ -109,11 +116,9 @@ void runStratumWorker(void *name) { isMinerSuscribed=true; } - - //Read pending messages from pool - while(client.available()){ + while(client.connected() && client.available()){ Serial.println(" Received message from pool"); String line = client.readStringUntil('\n');