From 6027b4a6b2812662f534efa80b56424d02416a74 Mon Sep 17 00:00:00 2001 From: Yanis Boucherk Date: Wed, 17 Mar 2021 22:07:05 +0100 Subject: [PATCH 1/3] Added a try except I added a try: except that reconnects if network breaks --- src/main.py | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/src/main.py b/src/main.py index 050ed47..2808977 100644 --- a/src/main.py +++ b/src/main.py @@ -1,11 +1,11 @@ import socket, hashlib # Global variables soc = socket.socket() -username = "user" # Edit this to your username, mind the quotes +username = "Yanis" # Edit this to your username, mind the quotes pool_address = "51.15.127.80" pool_port = 2811 -print("Starting 3DS Miner, you probably won't get any output") +print("Starting 3DS Miner, you probably won't get any output") while True: soc.connect((str(pool_address), int(pool_port))) # Connect to the server @@ -13,23 +13,27 @@ while True: print("Server is on version", server_version) # Mining section while True: - soc.send(bytes("JOB," + str(username) + ",ESP32", encoding="utf8")) # Send job request - - # Don't mind the "ESP32" for now since it is in an early state - - job = soc.recv(87).decode() # Get work from pool - job = job.split(",") # Split received data to job (job and difficulty) - difficulty = job[2] - for result in range( - 100 * int(difficulty) + 1 - ): # Calculate hash with difficulty - ducos1 = hashlib.sha1( - str(job[0] + str(result)).encode("utf-8") - ).hexdigest() # Generate hash - if job[1] == ducos1: # If result is even with job - soc.send( - bytes(str(result) + "," + ",3DS Miner unstable)", encoding="utf8") - ) # Send result of hashing algorithm to pool - feedback = soc.recv(1024).decode() # Get feedback about the result - print(feedback) - + try: + soc.send(bytes("JOB," + str(username) + ",ESP32", encoding="utf8")) # Send job request + + # Don't mind the "ESP32" for now since it is in an early state + + job = soc.recv(87).decode() # Get work from pool + job = job.split(",") # Split received data to job (job and difficulty) + difficulty = job[2] + for result in range( + 100 * int(difficulty) + 1 + ): # Calculate hash with difficulty + ducos1 = hashlib.sha1( + str(job[0] + str(result)).encode("utf-8") + ).hexdigest() # Generate hash + if job[1] == ducos1: # If result is even with job + soc.send( + bytes(str(result) + "," + ",3DS Miner unstable)", encoding="utf8") + ) # Send result of hashing algorithm to pool + feedback = soc.recv(1024).decode() # Get feedback about the result + print(feedback) + except: + soc.close() + soc = socket.socket() + soc.connect((str(pool_address), int(pool_port))) # Connect to the server From dc1457bd7857b33d963ada8e0f66599a408bb2a6 Mon Sep 17 00:00:00 2001 From: Yanis Boucherk Date: Wed, 17 Mar 2021 22:15:25 +0100 Subject: [PATCH 2/3] Fixed a bug with sleep mode 1st patch was for trying to reconnect. This one is for keeping to retry until it works ! --- src/main.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main.py b/src/main.py index 2808977..6ad9ab3 100644 --- a/src/main.py +++ b/src/main.py @@ -34,6 +34,12 @@ while True: feedback = soc.recv(1024).decode() # Get feedback about the result print(feedback) except: - soc.close() - soc = socket.socket() - soc.connect((str(pool_address), int(pool_port))) # Connect to the server + while True: + try: + soc.close() + soc = socket.socket() + soc.connect((str(pool_address), int(pool_port))) # Connect to the server + except: + pass + else: + break From 5e7e701a199ac15d5e6ccb0d267fe9a8e5dad055 Mon Sep 17 00:00:00 2001 From: Pherelo_HD <44616889+PhereloHD@users.noreply.github.com> Date: Wed, 17 Mar 2021 21:47:05 +0000 Subject: [PATCH 3/3] Update main.py --- src/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.py b/src/main.py index 6ad9ab3..223179a 100644 --- a/src/main.py +++ b/src/main.py @@ -1,11 +1,11 @@ import socket, hashlib # Global variables soc = socket.socket() -username = "Yanis" # Edit this to your username, mind the quotes +username = "user" # Edit this to your username, mind the quotes pool_address = "51.15.127.80" pool_port = 2811 -print("Starting 3DS Miner, you probably won't get any output") +print("Starting 3DS Miner, you probably will get Output on an error.") while True: soc.connect((str(pool_address), int(pool_port))) # Connect to the server