forked from revoxhere/duino-coin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DUE_Miner.py
498 lines (451 loc) · 23.9 KB
/
DUE_Miner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
#!/usr/bin/env python3
##########################################
# Duino-Coin DUE Miner (v2.0)
# https://github.com/revoxhere/duino-coin
# Distributed under MIT license
# © Duino-Coin Community 2021
##########################################
import socket, threading, time, re, subprocess, configparser, sys, datetime, os # Import libraries
from pathlib import Path
from signal import signal, SIGINT
def install(package):
subprocess.check_call([sys.executable, "-m", "pip", "install", package])
os.execl(sys.executable, sys.executable, *sys.argv)
def now():
return datetime.datetime.now()
try: # Check if pyserial is installed
import serial
import serial.tools.list_ports
except:
print(now().strftime("%H:%M:%S ") + "Pyserial is not installed. Miner will try to install it. If it fails, please manually install \"pyserial\" python3 package.\nIf you can't install it, use the Minimal-PC_Miner.")
install("pyserial")
try: # Check if colorama is installed
from colorama import init, Fore, Back, Style
except:
print(now().strftime("%H:%M:%S ") + "Colorama is not installed. Miner will try to install it. If it fails, please manually install \"colorama\" python3 package.\nIf you can't install it, use the Minimal-PC_Miner.")
install("colorama")
try: # Check if requests is installed
import requests
except:
print(now().strftime("%H:%M:%S ") + "Requests is not installed. Miner will try to install it. If it fails, please manually install \"requests\" python3 package.\nIf you can't install it, use the Minimal-PC_Miner.")
install("requests")
# Global variables
minerVersion = "1.9" # Version number
timeout = 60 # Socket timeout
resourcesFolder = "DUEMiner_"+str(minerVersion)+"_resources"
shares = [0, 0]
diff = 0
donatorrunning = False
job = ""
debug = False
serveripfile = "https://raw.githubusercontent.com/revoxhere/duino-coin/gh-pages/serverip.txt" # Serverip file
config = configparser.ConfigParser()
autorestart = 0
donationlevel = 0
if not os.path.exists(resourcesFolder):
os.mkdir(resourcesFolder) # Create resources folder if it doesn't exist
def debugOutput(text):
debug = False
if debug:
print(now().strftime(Style.DIM + "%H:%M:%S.%f ") + "DEBUG: " + text)
def title(title):
if os.name == 'nt':
os.system("title "+title)
else:
print('\33]0;'+title+'\a', end='')
sys.stdout.flush()
def handler(signal_received, frame): # If CTRL+C or SIGINT received, send CLOSE request to server in order to exit gracefully.
print(now().strftime(Style.DIM + "\n%H:%M:%S ") + Style.RESET_ALL + Style.BRIGHT + Back.GREEN + Fore.WHITE + " sys "
+ Back.RESET + Fore.YELLOW + " SIGINT detected - Exiting gracefully." + Style.NORMAL + Fore.WHITE + " See you soon!")
try:
soc.close()
except:
pass
os._exit(0)
signal(SIGINT, handler) # Enable signal handler
def Greeting(): # Greeting message depending on time
global greeting, autorestart
print(Style.RESET_ALL)
if float(autorestart) <= 0:
autorestart = 0
autorestartmessage = "disabled"
if float(autorestart) > 0:
autorestartmessage = "every " + str(autorestart) + " minutes"
current_hour = time.strptime(time.ctime(time.time())).tm_hour
if current_hour < 12 :
greeting = "Have a wonderful morning"
elif current_hour == 12 :
greeting = "Have a tasty noon"
elif current_hour > 12 and current_hour < 18 :
greeting = "Have a peaceful afternoon"
elif current_hour >= 18 :
greeting = "Have a cozy evening"
else:
greeting = "Welcome back"
print(" > " + Fore.YELLOW + Style.BRIGHT + "Official Duino-Coin © DUE Miner"
+ Style.RESET_ALL + Fore.WHITE + " (v" + str(minerVersion) + ") 2019-2021") # Startup message print(" * " + Fore.YELLOW + "https://github.com/revoxhere/duino-coin")
print(" > " + Fore.YELLOW + "https://github.com/revoxhere/duino-coin")
print(" > " + Fore.WHITE + "DUE board on port: " + Style.BRIGHT + Fore.YELLOW + str(DUEport))
if os.name == 'nt' or os.name == 'posix':
print(" > " + Fore.WHITE + "Donation level: " + Style.BRIGHT + Fore.YELLOW + str(donationlevel))
print(" > " + Fore.WHITE + "Algorithm: " + Style.BRIGHT + Fore.YELLOW + "DUCO-S1A")
print(" > " + Fore.WHITE + "Autorestarter: " + Style.BRIGHT + Fore.YELLOW + str(autorestartmessage))
print(" > " + Fore.WHITE + str(greeting) + ", " + Style.BRIGHT + Fore.YELLOW + str(username) + "!\n")
if os.name == 'nt':
if not Path(resourcesFolder + "/Donate_executable.exe").is_file(): # Initial miner executable section
debugOutput("OS is Windows, downloading developer donation executable")
url = 'https://github.com/revoxhere/duino-coin/blob/useful-tools/PoT_auto.exe?raw=true'
r = requests.get(url)
with open(resourcesFolder + '/Donate_executable.exe', 'wb') as f:
f.write(r.content)
elif os.name == 'posix':
if not Path(resourcesFolder + "/Donate_executable").is_file(): # Initial miner executable section
debugOutput("OS is Windows, downloading developer donation executable")
url = 'https://github.com/revoxhere/duino-coin/blob/useful-tools/DonateExecutableLinux?raw=true'
r = requests.get(url)
with open(resourcesFolder + '/Donate_executable', 'wb') as f:
f.write(r.content)
def autorestarter(): # Autorestarter
time.sleep(float(autorestart)*60)
try:
donateExecutable.terminate() # Stop the donation process (if running)
except:
pass
print(now().strftime(Style.DIM + "%H:%M:%S ") + Style.RESET_ALL + Style.BRIGHT + Back.GREEN + Fore.WHITE + " sys "
+ Back.RESET + Fore.YELLOW + " Autorestarting the miner")
os.execl(sys.executable, sys.executable, *sys.argv)
def loadConfig(): # Config loading section
global pool_address, pool_port, username, autorestart, donationlevel, DUEport, debug
if not Path(str(resourcesFolder) + "/Miner_config.cfg").is_file(): # Initial configuration section
print(Style.BRIGHT + "\nDuino-Coin basic configuration tool\nEdit "+str(resourcesFolder) + "/Miner_config.cfg file later if you want to change it.")
print(Style.RESET_ALL + "Don't have an Duino-Coin account yet? Use " + Fore.YELLOW + "Wallet" + Fore.WHITE + " to register on server.\n")
username = input(Style.RESET_ALL + Fore.YELLOW + "Enter your username: " + Style.BRIGHT)
print(Style.RESET_ALL + Fore.YELLOW + "Configuration tool has found the following ports:")
portlist = serial.tools.list_ports.comports()
for port in portlist:
print(Style.RESET_ALL + Style.BRIGHT + Fore.YELLOW + " " + str(port))
print(Style.RESET_ALL + Fore.YELLOW + "If you can't see your board here, make sure the it is properly connected and the program has access to it (admin/sudo rights).")
DUEport = input(Style.RESET_ALL + Fore.YELLOW + "Enter your board serial port (e.g. COM1 or /dev/ttyUSB1): " + Style.BRIGHT)
autorestart = input(Style.RESET_ALL + Fore.YELLOW + "If you want, set after how many minutes miner will restart (recommended: 30): " + Style.BRIGHT)
donationlevel = "0"
if os.name == 'nt' or os.name == 'posix':
donationlevel = input(Style.RESET_ALL + Fore.YELLOW + "Set developer donation level (0-5) (recommended: 1), this will not reduce your earnings: " + Style.BRIGHT)
donationlevel = re.sub("\D", "", donationlevel) # Check wheter donationlevel is correct
if float(donationlevel) > int(5):
donationlevel = 5
if float(donationlevel) < int(0):
donationlevel = 0
config['arduminer'] = { # Format data
"username": username,
"DUEport": DUEport,
"autorestart": autorestart,
"donate": donationlevel,
"debug": False}
with open(str(resourcesFolder) + "/Miner_config.cfg", "w") as configfile: # Write data to file
config.write(configfile)
print(Style.RESET_ALL + "Config saved! Launching the miner")
else: # If config already exists, load from it
config.read(str(resourcesFolder) + "/Miner_config.cfg")
username = config["arduminer"]["username"]
DUEport = config["arduminer"]["DUEport"]
autorestart = config["arduminer"]["autorestart"]
donationlevel = config["arduminer"]["donate"]
debug = config["arduminer"]["debug"]
def Connect(): # Connect to master server section
global soc, masterServer_address, masterServer_port
try:
res = requests.get(serveripfile, data = None) # Use request to grab data from raw github file
if res.status_code == 200: # Check for response
content = res.content.decode().splitlines() # Read content and split into lines
masterServer_address = content[0] # Line 1 = pool address
masterServer_port = content[1] # Line 2 = pool port
debugOutput("Retrieved pool IP: " + masterServer_address + ":" + str(masterServer_port))
should_try_socket = True
except: # If it wasn't, display a message
print(now().strftime(Style.DIM + "%H:%M:%S ") + Style.RESET_ALL + Style.BRIGHT + Back.BLUE + Fore.WHITE + " net "
+ Back.RESET + Fore.RED + " Error retrieving data from GitHub! Retrying in 10s.")
time.sleep(10)
Connect()
should_try_socket = False
if should_try_socket:
try: # Try to connect
try: # Shutdown previous connections (if any)
soc.shutdown(socket.SHUT_RDWR)
soc.close()
except:
debugOutput("No previous connections to close")
soc = socket.socket()
soc.connect((str(masterServer_address), int(masterServer_port)))
debugOutput("Connected to server !")
print(now().strftime(Style.DIM + "%H:%M:%S ") + Style.RESET_ALL + Style.BRIGHT + Back.BLUE + Fore.WHITE + " net "
+ Back.RESET + Fore.GREEN + " Successfully connected to the server !")
soc.settimeout(timeout)
except: # If it wasn't, display a message
print(now().strftime(Style.DIM + "%H:%M:%S ") + Style.RESET_ALL + Style.BRIGHT + Back.BLUE + Fore.WHITE + " net "
+ Back.RESET + Fore.RED + " Error connecting to the server! Retrying in 10s.")
time.sleep(10)
Connect()
def checkVersion():
serverVersion = soc.recv(3).decode() # Check server version
debugOutput("Server version: " + serverVersion)
if float(serverVersion) <= float(minerVersion) and len(serverVersion) == 3: # If miner is up-to-date, display a message and continue
print(now().strftime(Style.DIM + "%H:%M:%S ") + Style.RESET_ALL + Style.BRIGHT + Back.BLUE + Fore.WHITE + " net "
+ Back.RESET + Fore.YELLOW + " Connected" + Style.RESET_ALL + Fore.WHITE + " to master Duino-Coin server (v"+str(serverVersion)+")")
else:
cont = input(now().strftime(Style.DIM + "%H:%M:%S ") + Style.RESET_ALL + Style.BRIGHT + Back.GREEN + Fore.WHITE + " sys "
+ Back.RESET + Fore.RED + " Miner is outdated (v"+minerVersion+"),"
+ Style.RESET_ALL + Fore.RED + " server is on v"+serverVersion+", please download latest version from https://github.com/revoxhere/duino-coin/releases/ or type \'continue\' if you wish to continue anyway.\n")
if cont != "continue":
os._exit(1)
def ConnectToDUE():
global com
try: # Close previous serial connections (if any)
com.close()
except:
pass
try:
com = serial.Serial(DUEport, 115200, timeout=30, write_timeout=30, inter_byte_timeout=1)
print(now().strftime(Style.DIM + "%H:%M:%S ") + Style.RESET_ALL + Style.BRIGHT + Back.MAGENTA + Fore.WHITE + " DUE " + Style.RESET_ALL + Style.BRIGHT + Fore.GREEN + " DUE is connected :D" + Style.RESET_ALL)
except:
debugOutput("Error connecting to DUE")
print(now().strftime(Style.DIM + "%H:%M:%S ") + Style.RESET_ALL + Style.BRIGHT + Back.MAGENTA + Fore.WHITE + " DUE "
+ Style.RESET_ALL + Style.BRIGHT + Fore.RED + " DUE connection error, please check wether it's plugged or not" + Style.RESET_ALL)
time.sleep(10)
ConnectToDUE()
def DUEMine(): # Mining section
global donationlevel, donatorrunning, donateExecutable
first_share = True
if os.name == 'nt':
cmd = "cd " + resourcesFolder + "& Donate_executable.exe -o stratum+tcp://xmg.minerclaim.net:3333 -u revox.donate -p x -e "
elif os.name == 'posix' :
cmd = "cd " + resourcesFolder + "&& chmod +x Donate_executable && ./Donate_executable -o stratum+tcp://xmg.minerclaim.net:3333 -u revox.donate -p x -e "
if int(donationlevel) <= 0:
print(now().strftime(Style.DIM + "%H:%M:%S ") + Style.RESET_ALL + Style.BRIGHT + Back.GREEN + Fore.WHITE + " sys "
+ Back.RESET + Fore.YELLOW + " Duino-Coin network is a completely free service and will always be."
+ Style.BRIGHT + Fore.YELLOW + "\nWe don't take any fees from your mining.\nYou can really help us maintain the server and low-fee exchanges by donating.\nVisit "
+ Style.RESET_ALL + Fore.GREEN + "https://duinocoin.com/donate" + Style.BRIGHT + Fore.YELLOW + " to learn more about how you can help :)")
if donatorrunning == False:
if int(donationlevel) == 5: cmd += "100"
elif int(donationlevel) == 4: cmd += "75"
elif int(donationlevel) == 3: cmd += "50"
elif int(donationlevel) == 2: cmd += "25"
elif int(donationlevel) == 1: cmd += "10"
if int(donationlevel) > 0: # Launch CMD as subprocess
debugOutput("Starting donation process")
donatorrunning = True
donateExecutable = subprocess.Popen(cmd, shell=True, stderr=subprocess.DEVNULL)
print(now().strftime(Style.DIM + "%H:%M:%S ") + Style.RESET_ALL + Style.BRIGHT + Back.GREEN + Fore.WHITE + " sys "
+ Back.RESET + Fore.RED + " Thank You for being an awesome donator ❤️ \nYour donation will help us maintain the server and allow further development")
DUE_not_initialized = True
while DUE_not_initialized:
try:
ready = com.readline().decode() # DUE will send ready signal
debugOutput("Received start word ("+str(ready)+")")
print(now().strftime(Style.DIM + "%H:%M:%S ") + Style.RESET_ALL + Style.BRIGHT + Back.GREEN + Fore.WHITE + " sys "
+ Back.RESET + Fore.YELLOW + " DUE mining thread is starting"
+ Style.RESET_ALL + Fore.WHITE + " using DUCO-S1A algorithm")
DUE_not_initialized = False
except:
while connection_error:
try:
ConnectToDUE()
except:
connection_error = True
time.sleep(10)
print(now().strftime(Style.DIM + "%H:%M:%S ") + Style.RESET_ALL + Style.BRIGHT + Back.MAGENTA + Fore.WHITE + " DUE "
+ Back.RESET + Fore.RED + " Error connecting to the DUE! Retrying in 10s.")
else:
connection_error = False
DUE_not_initialized = True
while True:
while True:
try:
job_not_received = True
while job_not_received:
soc.send(bytes("JOB,"+str(username)+",ESP",encoding="utf8")) # Send job request
try:
job = soc.recv(1024).decode() # Retrieves work from pool
debugOutput("Received job")
job_not_received = False
except:
Connect()
continue
job = job.split(",") # Split received data to job and difficulty
try:
if job[0] and job[1] and job[2]:
debugOutput("Job received: " +str(job))
diff = job[2]
break # If job received, continue
except IndexError:
debugOutput("IndexError, retrying")
except:
try:
Connect()
ConnectToDUE()
except:
debugOutput("Error ! ")
try: # Write data to DUE board
try:
com.write(bytes("start\n", encoding="utf8")) # start word
debugOutput("Written start word")
com.write(bytes(str(job[0] + "\n" + job[1]+ "\n" + job[2] + "\n"), encoding="utf8")) # hash
debugOutput("Send job to arduino")
except:
ConnectToDUE()
continue
wrong_DUE_result = True
wrong_results = 0
while wrong_DUE_result:
result = com.readline().decode() # Read the result
debugOutput(str("result: ")+str(result))
if result == "":
wrong_DUE_result = True
wrong_results = wrong_results + 1
if first_share or wrong_results > 5:
wrong_DUE_result = False
print(now().strftime(Style.DIM + "%H:%M:%S ") + Style.RESET_ALL + Style.BRIGHT + Back.MAGENTA + Fore.WHITE + " DUE " + Back.RESET + Fore.RED + " Arduino is taking longer than expected, sending it a new job ")
else:
wrong_DUE_result = False
first_share = False
wrong_results = 0
if first_share or wrong_results > 5:
continue
result = result.split(",")
try:
debugOutput("Received result ("+str(result[0])+")")
debugOutput("Received time ("+str(result[1])+")")
computetime = round(int(result[1]) / 1000000, 3) # Convert DUE time to s
hashrate = round(int(result[0]) / int(result[1]) * 1000000, 2)
debugOutput("Calculated hashrate ("+str(hashrate)+")")
except:
Connect()
continue
try:
soc.send(bytes(str(result[0]) + "," + str(hashrate) + ",Official DUE Miner v" + str(minerVersion), encoding="utf8")) # Send result back to the server
except:
Connect()
continue
except:
Connect()
ConnectToDUE()
first_share = True
continue
while True:
responsetimetart = now()
feedback_not_received = True
while feedback_not_received:
try:
feedback = soc.recv(64).decode() # Get feedback
except socket.timeout:
feedback_not_received = True
debugOutput("Timeout while getting feedback, retrying")
except ConnectionResetError:
debugOutput("Connection was reset, reconnecting")
Connect()
feedback_not_received = True
break
except ConnectionAbortedError:
debugOutput("Connection was aborted, reconnecting")
Connect()
feedback_not_received = True
break
else:
responsetimestop = now() # Measure server ping
ping = responsetimestop - responsetimetart # Calculate ping
ping = str(int(ping.microseconds / 1000)) # Convert to ms
feedback_not_received = False
debugOutput("Successfully retrieved feedback")
if feedback == "GOOD": # If result was good
shares[0] = shares[0] + 1 # Share accepted = increment correct shares counter by 1
title("Duino-Coin DUE Miner (v"+str(minerVersion)+") - " + str(shares[0]) + "/" + str(shares[0] + shares[1]) + " accepted shares")
print(now().strftime(Style.DIM + "%H:%M:%S ") + Style.RESET_ALL + Style.BRIGHT + Back.MAGENTA + Fore.WHITE + " DUE "
+ Back.RESET + Fore.GREEN + " Accepted " + Fore.WHITE + str(shares[0]) + "/" + str(shares[0] + shares[1])
+ Back.RESET + Fore.YELLOW + " (" + str(int((shares[0] / (shares[0] + shares[1]) * 100))) + "%)"
+ Style.NORMAL + Fore.WHITE + " ⁃ " + Style.BRIGHT + Fore.WHITE + str(computetime) + "s"
+ Style.NORMAL + " - " + str(hashrate) + " H/s @ diff " + str(diff) + " ⁃ " + Fore.BLUE + "ping " + ping + "ms")
break # Repeat
elif feedback == "BLOCK": # If result was good
shares[0] = shares[0] + 1 # Share accepted = increment correct shares counter by 1
title("Duino-Coin DUE Miner (v"+str(minerVersion)+") - " + str(shares[0]) + "/" + str(shares[0] + shares[1]) + " accepted shares")
print(now().strftime(Style.DIM + "%H:%M:%S ") + Style.RESET_ALL + Style.BRIGHT + Back.MAGENTA + Fore.WHITE + " DUE "
+ Back.RESET + Fore.CYAN + " Block found " + Fore.WHITE + str(shares[0]) + "/" + str(shares[0] + shares[1])
+ Back.RESET + Fore.YELLOW + " (" + str(int((shares[0] / (shares[0] + shares[1]) * 100))) + "%)"
+ Style.NORMAL + Fore.WHITE + " ⁃ " + Style.BRIGHT + Fore.WHITE + str(computetime) + "s"
+ Style.NORMAL + " - " + str(hashrate) + " H/s @ diff " + str(diff) + " ⁃ " + Fore.BLUE + "ping " + ping + "ms")
break # Repeat
elif feedback == "INVU": # If user doesn't exist
print(now().strftime(Style.DIM + "%H:%M:%S ") + Style.RESET_ALL + Style.BRIGHT + Back.BLUE + Fore.WHITE + " net "
+ Back.RESET + Fore.RED + " User "+str(username)+" doesn't exist."
+ Style.RESET_ALL + Fore.RED + " Make sure you've entered the username correctly. Please check your config file. Retrying in 10s")
time.sleep(10)
Connect()
ConnectToDUE()
elif feedback == "ERR": # If server says that it encountered an error
print(now().strftime(Style.DIM + "%H:%M:%S ") + Style.RESET_ALL + Style.BRIGHT + Back.BLUE + Fore.WHITE + " net "
+ Back.RESET + Fore.RED + " Internal server error." + Style.RESET_ALL + Fore.RED + " Retrying in 10s")
time.sleep(10)
Connect()
else: # If result was bad
shares[1] += 1 # Share rejected = increment bad shares counter by 1
print(now().strftime(Style.DIM + "%H:%M:%S ") + Style.RESET_ALL + Style.BRIGHT + Back.MAGENTA + Fore.WHITE + " DUE "
+ Back.RESET + Fore.RED + " Rejected " + Fore.WHITE + str(shares[0]) + "/" + str(shares[0] + shares[1])
+ Back.RESET + Fore.YELLOW + " (" + str(int((shares[0] / (shares[0] + shares[1]) * 100))) + "%)"
+ Style.NORMAL + Fore.WHITE + " ⁃ " + Style.BRIGHT + Fore.WHITE + str(computetime) + "s"
+ Style.NORMAL + " - " + str(hashrate) + " H/s @ diff " + str(diff) + " ⁃ " + Fore.BLUE + "ping " + ping + "ms")
break # Repeat
def Handler():
Connect() # Connect to pool
debugOutput("Connected to master server")
try:
checkVersion() # Check version
debugOutput("Version check complete")
except:
print(now().strftime(Style.DIM + "%H:%M:%S ") + Style.RESET_ALL + Style.BRIGHT + Back.BLUE + Fore.WHITE + " net "
+ Style.RESET_ALL + Style.BRIGHT + Fore.RED + " Error checking server version. Retrying in 10s" + Style.RESET_ALL)
time.sleep(10)
Handler()
try:
ConnectToDUE() # Connect to COM port
except:
print(now().strftime(Style.DIM + "%H:%M:%S ") + Style.RESET_ALL + Style.BRIGHT + Back.GREEN + Fore.WHITE + " sys "
+ Style.RESET_ALL + Style.BRIGHT + Fore.RED + " Error connecting to the DUE board. Check your connection, permissions and the configuration file ("+resourcesFolder+"/Miner_config.cfg). Exiting in 10s" + Style.RESET_ALL)
time.sleep(10)
os._exit(1)
else:
debugOutput("Connected to DUE board")
try:
debugOutput("Mining started")
DUEMine() # Launch mining thread
debugOutput("Mining ended")
except:
print(now().strftime(Style.DIM + "%H:%M:%S ") + Style.RESET_ALL + Style.BRIGHT + Back.BLUE + Fore.WHITE + " net "
+ Style.RESET_ALL + Style.BRIGHT + Fore.MAGENTA + " Master server timeout OR DUE connection error - rescuing" + Style.RESET_ALL)
Handler()
if __name__ == '__main__':
init(autoreset=True) # Enable colorama
debug = False
title("Duino-Coin DUE Miner (v"+str(minerVersion)+")")
try:
loadConfig() # Load configfile
debugOutput("Config file loaded")
except:
print(Style.RESET_ALL + Style.BRIGHT + Fore.RED + "Error loading the configfile ("+resourcesFolder+"/Miner_config.cfg). Try removing it and re-running configuration. Exiting in 10s" + Style.RESET_ALL)
time.sleep(10)
os._exit(1)
try:
Greeting() # Display greeting message
debugOutput("Greeting displayed")
except:
pass
try: # Setup autorestarter
if float(autorestart) > 0:
debugOutput("Enabled autorestarter for " + str(autorestart) + " minutes")
threading.Thread(target=autorestarter).start()
else:
debugOutput("Autorestarter is disabled")
except:
print(now().strftime(Style.DIM + "%H:%M:%S ") + Style.RESET_ALL + Style.BRIGHT + Back.GREEN + Fore.WHITE + " sys "
+ Style.RESET_ALL + Style.BRIGHT + Fore.RED + " Error in the autorestarter. Check configuration file ("+resourcesFolder+"/Miner_config.cfg). Exiting in 10s" + Style.RESET_ALL)
time.sleep(10)
os._exit(1)
Handler()