-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBPL-Logging.sh
More file actions
executable file
·91 lines (71 loc) · 2.67 KB
/
BPL-Logging.sh
File metadata and controls
executable file
·91 lines (71 loc) · 2.67 KB
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
#!/bin/bash
bitaxeLocalIP=$(cat ./config.json | jq .bitaxeLocalIP | tr -d '"')
bitaxeName=$(cat ./config.json | jq .bitaxeName | tr -d '"')
# Graceful exit
handle_sigterm() {
echo "Caught SIGTERM!"
exit 0
}
# Trap SIGTERM
trap handle_sigterm SIGTERM
# Function to check dependencies
checkdeps() {
command -v jq >/dev/null 2>&1 || { echo "Error: jq not installed"; exit 1; }
}
# Function to convert abbreviated number to full integer
convert_abbrev_number() {
local input="$1"
local number suffix multiplier
# Check if input is empty
if [ -z "$input" ]; then
echo "Error: Empty input" >&2
return 1
fi
# Extract numeric part and suffix using regex
if [[ "$input" =~ ^([0-9]+(\.[0-9]+)?)([KMGTkmgt]?)$ ]]; then
number="${BASH_REMATCH[1]}"
suffix="${BASH_REMATCH[3]}"
else
echo "Error: Invalid format '$input'" >&2
return 1
fi
# Set multiplier based on suffix
case "${suffix^^}" in
"") multiplier=1 ;;
"K") multiplier=1000 ;;
"M") multiplier=1000000 ;;
"G") multiplier=1000000000 ;;
"T") multiplier=1000000000000 ;;
*)
echo "Error: Unsupported suffix '$suffix'" >&2
return 1
;;
esac
# Calculate result using bc, keeping decimal precision, then convert to integer
result=$(echo "scale=0; $number * $multiplier / 1" | bc)
echo "$result"
}
checkdeps
mkdir -p /tmp/BPL
echo "Uptime (s),Power (W),Core Voltage (mV),Input Voltage (mV),Current (mA),ASIC Temp (C),VR Temp (C),Hashrate (GH/s),Accepted Shares,Rejected Shares,Best Difficulty,Best Session Difficulty,Stratum Difficulty" > /tmp/BPL/BPL-$bitaxeName-Logging.csv
curl -X POST "$bitaxeLocalIP/api/system/restart";
sleep 5;
while true
do
resp=$(curl -s -X GET "$bitaxeLocalIP/api/system/info")
uptime=$(echo $resp | jq .uptimeSeconds)
power=$(echo $resp | jq .power)
inputVolt=$(echo $resp | jq .voltage)
coreVolt=$(echo $resp | jq .coreVoltageActual)
current=$(echo $resp | jq .current)
temp=$(echo $resp | jq .temp)
vrTemp=$(echo $resp | jq .vrTemp)
hashrate=$(echo $resp | jq .hashRate)
sharesAccepted=$(echo $resp | jq .sharesAccepted)
sharesRejected=$(echo $resp | jq .sharesRejected)
bestDiff=$(convert_abbrev_number $(echo $resp | jq .bestDiff | tr -d '"'))
bestSessionDiff=$(convert_abbrev_number $(echo $resp | jq .bestSessionDiff | tr -d '"'))
stratumDiff=$(convert_abbrev_number $(echo $resp | jq .stratumDiff | tr -d '"'))
echo "$uptime,$power,$coreVolt,$inputVolt,$current,$temp,$vrTemp,$hashrate,$sharesAccepted,$sharesRejected,$bestDiff,$bestSessionDiff,$stratumDiff" >> /tmp/BPL/BPL-$bitaxeName-Logging.csv
sleep 5
done