Added a try except
I added a try: except that reconnects if network breaks
This commit is contained in:
parent
74559a15a8
commit
6027b4a6b2
48
src/main.py
48
src/main.py
|
@ -1,11 +1,11 @@
|
||||||
import socket, hashlib
|
import socket, hashlib
|
||||||
# Global variables
|
# Global variables
|
||||||
soc = socket.socket()
|
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_address = "51.15.127.80"
|
||||||
pool_port = 2811
|
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:
|
while True:
|
||||||
soc.connect((str(pool_address), int(pool_port))) # Connect to the server
|
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)
|
print("Server is on version", server_version)
|
||||||
# Mining section
|
# Mining section
|
||||||
while True:
|
while True:
|
||||||
soc.send(bytes("JOB," + str(username) + ",ESP32", encoding="utf8")) # Send job request
|
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
|
|
||||||
|
# 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)
|
job = soc.recv(87).decode() # Get work from pool
|
||||||
difficulty = job[2]
|
job = job.split(",") # Split received data to job (job and difficulty)
|
||||||
for result in range(
|
difficulty = job[2]
|
||||||
100 * int(difficulty) + 1
|
for result in range(
|
||||||
): # Calculate hash with difficulty
|
100 * int(difficulty) + 1
|
||||||
ducos1 = hashlib.sha1(
|
): # Calculate hash with difficulty
|
||||||
str(job[0] + str(result)).encode("utf-8")
|
ducos1 = hashlib.sha1(
|
||||||
).hexdigest() # Generate hash
|
str(job[0] + str(result)).encode("utf-8")
|
||||||
if job[1] == ducos1: # If result is even with job
|
).hexdigest() # Generate hash
|
||||||
soc.send(
|
if job[1] == ducos1: # If result is even with job
|
||||||
bytes(str(result) + "," + ",3DS Miner unstable)", encoding="utf8")
|
soc.send(
|
||||||
) # Send result of hashing algorithm to pool
|
bytes(str(result) + "," + ",3DS Miner unstable)", encoding="utf8")
|
||||||
feedback = soc.recv(1024).decode() # Get feedback about the result
|
) # Send result of hashing algorithm to pool
|
||||||
print(feedback)
|
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
|
||||||
|
|
Loading…
Reference in New Issue