From b41568636ac3657c8d2921424515e869e215c8d1 Mon Sep 17 00:00:00 2001 From: sib Date: Tue, 14 Jul 2026 16:01:05 +0200 Subject: [PATCH] fix: don't cache failed pool DNS resolution as 0.0.0.0 --- src/mining.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/mining.cpp b/src/mining.cpp index 8fd73163..29c77030 100644 --- a/src/mining.cpp +++ b/src/mining.cpp @@ -84,17 +84,22 @@ bool checkPoolConnection(void) { Serial.println("Client not connected, trying to connect..."); - //Resolve first time pool DNS and save IP + //Resolve pool DNS. WiFi.hostByName() returns 0 and writes 0.0.0.0 into serverIP on + //failure, so check the return value: otherwise a failed first resolve caches 0.0.0.0 + //and the client can never connect until the device is rebooted. if(serverIP == IPAddress(1,1,1,1)) { - WiFi.hostByName(Settings.PoolAddress.c_str(), serverIP); - Serial.printf("Resolved DNS and save ip (first time) got: %s\n", serverIP.toString()); + if (WiFi.hostByName(Settings.PoolAddress.c_str(), serverIP) != 1 || serverIP == IPAddress(0,0,0,0)) { + Serial.println("DNS resolve failed, will retry next attempt"); + serverIP = IPAddress(1,1,1,1); //keep unresolved so we retry + return false; + } + Serial.printf("Resolved DNS got: %s\n", serverIP.toString()); } //Try connecting pool IP if (!client.connect(serverIP, Settings.PoolPort)) { Serial.println("Imposible to connect to : " + Settings.PoolAddress); - WiFi.hostByName(Settings.PoolAddress.c_str(), serverIP); - Serial.printf("Resolved DNS got: %s\n", serverIP.toString()); + serverIP = IPAddress(1,1,1,1); //force a fresh DNS resolve on next attempt return false; }