Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 4.0 pull #1723

Merged
merged 41 commits into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
c3f99d4
Rename ESP32_Code/ESP32_Code.ino to Legacy codes/ESP32_Code/ESP32_Cod…
revoxhere Dec 16, 2023
0985a93
Rename ESP8266_Code/ESP8266_Code.ino to Legacy codes/ESP8266_Code/ESP…
revoxhere Dec 16, 2023
59255bc
Create .gitkeep
revoxhere Dec 17, 2023
ff41a2a
@matteocrippa's huge part of rework
revoxhere Dec 17, 2023
38220cb
Delete ESP_Code/.gitkeep
revoxhere Dec 17, 2023
e394efb
Arduino IDE compatibility
revoxhere Dec 17, 2023
3aa5192
Create Dashboard.h
revoxhere Dec 17, 2023
83d5868
Arduino IDE compatibility
revoxhere Dec 17, 2023
8106f18
Import typo
revoxhere Dec 17, 2023
1638aae
Cleanups, reorganization, dashboard and IoT, removed MQTT
revoxhere Dec 17, 2023
82bab91
IoT, dashboard and cleanups
revoxhere Dec 17, 2023
76d01b0
Arduino IDE import
revoxhere Dec 17, 2023
4366c43
Create a separate settings file
revoxhere Dec 17, 2023
a31c2bc
Keep the 8266 watchdog silent
revoxhere Dec 17, 2023
fdfc8a5
Maybe this way...
revoxhere Dec 17, 2023
7c4859d
Hacky fix for weirdly low hashrate with no sensors attached
revoxhere Dec 27, 2023
3e5a4fb
Move led settings
revoxhere Dec 27, 2023
45c3ea4
True fix for #7c4859d
revoxhere Dec 28, 2023
9368c02
Remove unnecessary serial print
revoxhere Dec 28, 2023
1f6fbf9
Correct esp8266 clock
revoxhere Dec 28, 2023
56c6f0c
Correct wallet ID gen. and internal temp sensor
revoxhere Dec 28, 2023
e8f161f
Internal temp sensor
revoxhere Dec 28, 2023
fde62d1
Internl temp sensor
revoxhere Dec 28, 2023
03d463c
Some curses experiments, postponed for now
revoxhere Dec 29, 2023
a404259
Update PC_Miner_langs.json
revoxhere Dec 29, 2023
1f2263c
Working print queue
revoxhere Dec 29, 2023
63dc5e7
Update PC_Miner_langs.json
revoxhere Dec 29, 2023
433c0aa
IoT with symbols
revoxhere Dec 29, 2023
2cff709
Update PC_Miner_langs.json
revoxhere Dec 29, 2023
85a240b
Print queue and small bugfixes
revoxhere Dec 30, 2023
516c022
Update and rename Wallet.py to Legacy codes/Wallet.py
revoxhere Dec 30, 2023
0afaa12
Rename CLI_Wallet.py to Legacy codes/CLI_Wallet.py
revoxhere Dec 30, 2023
dcbfac2
More natural log colors
revoxhere Dec 30, 2023
8df4ad0
More natural log colors
revoxhere Dec 30, 2023
2c290d7
Window title and share message
revoxhere Dec 30, 2023
ab977ab
Typo
revoxhere Dec 30, 2023
1f191e4
Share message
revoxhere Dec 30, 2023
0ac2a8c
Date update
revoxhere Dec 30, 2023
68e304e
Update AVR_Miner_langs.json
revoxhere Dec 30, 2023
de24d36
Update PC_Miner_langs.json
revoxhere Dec 30, 2023
762773e
Date update
revoxhere Dec 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 79 additions & 66 deletions AVR_Miner.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python3
"""
Duino-Coin Official AVR Miner 3.9 © MIT licensed
Duino-Coin Official AVR Miner 4.0 © MIT licensed
https://duinocoin.com
https://github.com/revoxhere/duino-coin
Duino-Coin Team & Community 2019-2023
Duino-Coin Team & Community 2019-2024
"""

from os import _exit, mkdir
Expand Down Expand Up @@ -109,7 +109,7 @@ def port_num(com):


class Settings:
VER = '3.9'
VER = '4.0'
SOC_TIMEOUT = 15
REPORT_TIME = 120
AVR_TIMEOUT = 10
Expand Down Expand Up @@ -792,7 +792,7 @@ def greeting():
+ Style.BRIGHT + get_string('banner')
+ Style.RESET_ALL + Fore.MAGENTA
+ f' {Settings.VER}' + Fore.RESET
+ ' 2019-2023')
+ ' 2019-2024')

print(
Style.DIM + Fore.MAGENTA
Expand Down Expand Up @@ -828,12 +828,12 @@ def greeting():
+ Style.BRIGHT + Fore.YELLOW
+ 'DUCO-S1A ⚙ AVR diff')

if rig_identifier != "None":
if rig_identifier[0] != "None" or len(rig_identifier) > 1:
print(
Style.DIM + Fore.MAGENTA
+ Settings.BLOCK + Style.NORMAL
+ Fore.RESET + get_string('rig_identifier')
+ Style.BRIGHT + Fore.YELLOW + rig_identifier)
+ Style.BRIGHT + Fore.YELLOW + ", ".join(rig_identifier))

print(
Style.DIM + Fore.MAGENTA
Expand Down Expand Up @@ -909,23 +909,20 @@ def pretty_print(sender: str = "sys0",
else:
fg_color = Fore.YELLOW

with thread_lock():
print(Fore.WHITE + datetime.now().strftime(Style.DIM + "%H:%M:%S ")
+ bg_color + Style.BRIGHT + " " + sender + " "
+ Back.RESET + " " + fg_color + msg.strip())

print_queue.append(Fore.RESET + datetime.now().strftime(Style.DIM + "%H:%M:%S ")
+ Style.RESET_ALL + Fore.WHITE + bg_color + Style.BRIGHT + f" {sender} "
+ Style.RESET_ALL + " " + fg_color + msg.strip())


def share_print(id, type, accept, reject, total_hashrate,
computetime, diff, ping, reject_cause=None):
def share_print(id, type, accept, reject, thread_hashrate,
total_hashrate, computetime, diff, ping, reject_cause=None):
"""
Produces nicely formatted CLI output for shares:
HH:MM:S |avrN| ⛏ Accepted 0/0 (100%) ∙ 0.0s ∙ 0 kH/s ⚙ diff 0 k ∙ ping 0ms
"""

try:
total_hashrate = get_prefix("H/s", total_hashrate, 2)
except:
total_hashrate = "? H/s"
thread_hashrate = get_prefix("H/s", thread_hashrate, 2)
total_hashrate = get_prefix("H/s", total_hashrate, 1)

if type == "accept":
share_str = get_string("accepted")
Expand All @@ -939,23 +936,24 @@ def share_print(id, type, accept, reject, total_hashrate,
share_str += f"{Style.NORMAL}({reject_cause}) "
fg_color = Fore.RED

with thread_lock():
print(Fore.WHITE + datetime.now().strftime(Style.DIM + "%H:%M:%S ")
+ Fore.WHITE + Style.BRIGHT + Back.MAGENTA + Fore.RESET
+ " avr" + str(id) + " " + Back.RESET
+ fg_color + Settings.PICK + share_str + Fore.RESET
+ str(accept) + "/" + str(accept + reject) + Fore.MAGENTA
+ " (" + str(round(accept / (accept + reject) * 100)) + "%)"
+ Style.NORMAL + Fore.RESET
+ " ∙ " + str("%04.1f" % float(computetime)) + "s"
+ Style.NORMAL + " ∙ " + Fore.BLUE + Style.BRIGHT
+ str(total_hashrate) + Fore.RESET + Style.NORMAL
+ Settings.COG + f" diff {diff} ∙ " + Fore.CYAN
+ f"ping {(int(ping))}ms")
print_queue.append(
Fore.RESET + datetime.now().strftime(Style.DIM + "%H:%M:%S ")
+ Style.RESET_ALL + Fore.WHITE + Style.BRIGHT + Back.MAGENTA
+ " avr" + str(id) + " " + Style.RESET_ALL + fg_color
+ Settings.PICK + share_str + Fore.RESET
+ str(accept) + "/" + str(accept + reject) + Fore.MAGENTA
+ " (" + str(round(accept / (accept + reject) * 100)) + "%)"
+ Style.NORMAL + Fore.RESET
+ " ∙ " + str("%04.1f" % float(computetime)) + "s"
+ Style.NORMAL + " ∙ " + Fore.BLUE + Style.BRIGHT
+ f"{thread_hashrate}" + Style.DIM
+ f" ({total_hashrate} {get_string('hashrate_total')})" + Fore.RESET + Style.NORMAL
+ Settings.COG + f" {get_string('diff')} {diff} ∙ " + Fore.CYAN
+ f"ping {(int(ping))}ms")


def mine_avr(com, threadid, fastest_pool, thread_rigid):
global hashrate
global hashrate, shares
start_time = time()
report_shares = 0
last_report_share = 0
Expand Down Expand Up @@ -1088,23 +1086,17 @@ def mine_avr(com, threadid, fastest_pool, thread_rigid):
break

start_diff = "AVR"
if hashrate_test > 12000:
start_diff = "ESP32"
elif hashrate_test > 6000:
start_diff = "ESP8266H"
elif hashrate_test > 4500:
start_diff = "ESP8266"
elif hashrate_test > 1000:
if hashrate_test > 1000:
start_diff = "DUE"
elif hashrate_test > 520:
elif hashrate_test > 550:
start_diff = "ARM"
elif hashrate_test > 370:
elif hashrate_test > 380:
start_diff = "MEGA"

pretty_print('sys' + port_num(com),
get_string('hashrate_test')
+ get_prefix("H/s", hashrate_test, 2)
+ Fore.RESET
+ Fore.RESET + Style.BRIGHT
+ get_string('hashrate_test_diff')
+ start_diff)

Expand Down Expand Up @@ -1181,6 +1173,7 @@ def mine_avr(com, threadid, fastest_pool, thread_rigid):
hashrate_mean.append(hashrate_t)
hashrate = mean(hashrate_mean[-5:])
hashrate_list[threadid] = hashrate
total_hashrate = sum(hashrate_list)
except Exception as e:
pretty_print('sys' + port_num(com),
get_string('mining_avr_connection_error')
Expand Down Expand Up @@ -1222,32 +1215,32 @@ def mine_avr(com, threadid, fastest_pool, thread_rigid):

if feedback[0] == 'GOOD':
shares[0] += 1
printlock.acquire()
share_print(port_num(com), "accept",
shares[0], shares[1], hashrate,
shares[0], shares[1], hashrate, total_hashrate,
computetime, diff, ping)
printlock.release()

elif feedback[0] == 'BLOCK':
shares[0] += 1
shares[2] += 1
printlock.acquire()
share_print(port_num(com), "block",
shares[0], shares[1], hashrate,
shares[0], shares[1], hashrate, total_hashrate,
computetime, diff, ping)
printlock.release()

elif feedback[0] == 'BAD':
shares[1] += 1
printlock.acquire()
share_print(port_num(com), "reject",
shares[0], shares[1], hashrate,
shares[0], shares[1], hashrate, total_hashrate,
computetime, diff, ping, feedback[1])
printlock.release()

else:
printlock.acquire()
share_print(port_num(com), "reject",
shares[0], shares[1], hashrate,
shares[0], shares[1], hashrate, total_hashrate,
computetime, diff, ping, feedback)
printlock.release()

if shares[0] % 100 == 0 and shares[0] > 1:
pretty_print("sys0",
f"{get_string('surpassed')} {accept.value} {get_string('surpassed_shares')}",
"success")

title(get_string('duco_avr_miner') + str(Settings.VER)
+ f') - {shares[0]}/{(shares[0] + shares[1])}'
Expand All @@ -1266,22 +1259,28 @@ def mine_avr(com, threadid, fastest_pool, thread_rigid):


def periodic_report(start_time, end_time, shares,
block, hashrate, uptime):
blocks, hashrate, uptime):
"""
Displays nicely formated uptime stats
"""
seconds = round(end_time - start_time)
pretty_print("sys0",
" " + get_string('periodic_mining_report')
pretty_print("sys0", get_string("periodic_mining_report")
+ Fore.RESET + Style.NORMAL
+ get_string('report_period')
+ str(seconds) + get_string('report_time')
+ get_string('report_body1')
+ str(shares) + get_string('report_body2')
+ get_string("report_period")
+ str(seconds) + get_string("report_time")
+ get_string("report_body1")
+ str(shares) + get_string("report_body2")
+ str(round(shares/seconds, 1))
+ get_string('report_body3')
+ get_string('report_body7') + str(block)
+ get_string('report_body4')
+ str(int(hashrate)) + " H/s" + get_string('report_body5')
+ str(int(hashrate*seconds)) + get_string('report_body6')
+ get_string('total_mining_time') + str(uptime), "success")
+ get_string("report_body3")
+ get_string("report_body7")
+ str(blocks)
+ get_string("report_body4")
+ str(get_prefix("H/s", hashrate, 2))
+ get_string("report_body5")
+ str(int(hashrate*seconds))
+ get_string("report_body6")
+ get_string("total_mining_time")
+ str(uptime) + "\n", "success")


def calculate_uptime(start_time):
Expand All @@ -1298,8 +1297,22 @@ def calculate_uptime(start_time):
return str(round(uptime)) + get_string('uptime_seconds')


print_queue = []
def print_queue_handler():
"""
Prevents broken console logs with many threads
"""
while True:
if len(print_queue):
message = print_queue[0]
del print_queue[0]
print(message)
sleep(0.1)


if __name__ == '__main__':
init(autoreset=True)
Thread(target=print_queue_handler).start()
title(f"{get_string('duco_avr_miner')}{str(Settings.VER)})")

if sys.platform == "win32":
Expand Down
4 changes: 2 additions & 2 deletions Arduino_Code/Arduino_Code.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
( _ \( )( )(_ _)( \( )( _ )___ / __)( _ )(_ _)( \( )
)(_) ))(__)( _)(_ ) ( )(_)((___)( (__ )(_)( _)(_ ) (
(____/(______)(____)(_)\_)(_____) \___)(_____)(____)(_)\_)
Official code for Arduino boards (and relatives) version 3.9
Official code for Arduino boards (and relatives) version 4.0

Duino-Coin Team & Community 2019-2022 © MIT Licensed
Duino-Coin Team & Community 2019-2024 © MIT Licensed
https://duinocoin.com
https://github.com/revoxhere/duino-coin
If you don't know where to start, visit official website and navigate to
Expand Down
53 changes: 53 additions & 0 deletions ESP_Code/Counter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#ifndef _COUNTER_H_
#define _COUNTER_H_

#include <Arduino.h>
#include <string.h>

template <unsigned int max_digits>
class Counter {

public:
Counter() { reset(); }

void reset() {
memset(buffer, '0', max_digits);
buffer[max_digits] = '\0';
val = 0;
len = 1;
}

inline Counter &operator++() {
inc_string(buffer + max_digits - 1);
++val;
return *this;
}

inline operator unsigned int() const { return val; }
inline const char *c_str() const { return buffer + max_digits - len; }
inline size_t strlen() const { return len; }

protected:
inline void inc_string(char *c) {
// In theory, the line below should be uncommented to avoid writing outside the buffer. In practice however,
// with max_digits set to 10 or more, we can fit all possible unsigned 32-bit integers in the buffer.
// The check is skipped to gain a small extra speed improvement.
// if (c >= buffer) return;

if (*c < '9') {
*c += 1;
}
else {
*c = '0';
inc_string(c - 1);
len = max(max_digits - (c - buffer) + 1, len);
}
}

protected:
char buffer[max_digits + 1];
unsigned int val;
size_t len;
};

#endif
Loading