added Hive get bad boards, and started on a bad board utility
This commit is contained in:
@@ -174,10 +174,12 @@ If you are sure you want to use this command please use API.send_command("{item}
|
|||||||
str_data = str_data.replace("\n", "")
|
str_data = str_data.replace("\n", "")
|
||||||
# fix an error with a bmminer return not having a specific comma that breaks json.loads()
|
# fix an error with a bmminer return not having a specific comma that breaks json.loads()
|
||||||
str_data = str_data.replace("}{", "},{")
|
str_data = str_data.replace("}{", "},{")
|
||||||
|
# fix an error with a bmminer return having a specific comma that breaks json.loads()
|
||||||
|
str_data = str_data.replace("[,{", "[{")
|
||||||
# parse the json
|
# parse the json
|
||||||
parsed_data = json.loads(str_data)
|
parsed_data = json.loads(str_data)
|
||||||
# handle bad json
|
# handle bad json
|
||||||
except json.decoder.JSONDecodeError as e:
|
except json.decoder.JSONDecodeError as e:
|
||||||
print(e)
|
print(e)
|
||||||
raise APIError(f"Decode Error: {data}")
|
raise APIError(f"Decode Error: {str_data}")
|
||||||
return parsed_data
|
return parsed_data
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
|
import asyncio
|
||||||
|
|
||||||
from miners.bmminer import BMMiner
|
from miners.bmminer import BMMiner
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
class HiveonT9(BMMiner):
|
class HiveonT9(BMMiner):
|
||||||
@@ -9,3 +12,18 @@ class HiveonT9(BMMiner):
|
|||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return f"HiveonT9: {str(self.ip)}"
|
return f"HiveonT9: {str(self.ip)}"
|
||||||
|
|
||||||
|
|
||||||
|
async def get_bad_boards(self) -> list:
|
||||||
|
"""Checks for and provides list of non working boards."""
|
||||||
|
board_stats = await self.api.stats()
|
||||||
|
stats = board_stats['STATS'][1]
|
||||||
|
bad_boards = []
|
||||||
|
board_chains = {6: [2, 9, 10], 7: [3, 11, 12], 8: [4, 13, 14]}
|
||||||
|
for board in board_chains:
|
||||||
|
for chain in board_chains[board]:
|
||||||
|
count = stats[f"chain_acn{chain}"]
|
||||||
|
chips = stats[f"chain_acs{chain}"].replace(" ", "")
|
||||||
|
if not count == 18 or "x" in chips:
|
||||||
|
bad_boards.append({"board": board, "chain": chain, "chip_count": count, "chip_status": chips})
|
||||||
|
return bad_boards
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
from API.bmminer import BMMinerAPI
|
from API.bmminer import BMMinerAPI
|
||||||
from miners import BaseMiner
|
from miners import BaseMiner
|
||||||
|
import asyncssh
|
||||||
|
|
||||||
class BMMiner(BaseMiner):
|
class BMMiner(BaseMiner):
|
||||||
def __init__(self, ip: str) -> None:
|
def __init__(self, ip: str) -> None:
|
||||||
api = BMMinerAPI(ip)
|
api = BMMinerAPI(ip)
|
||||||
self.model = None
|
|
||||||
super().__init__(ip, api)
|
super().__init__(ip, api)
|
||||||
|
self.model = None
|
||||||
|
self.config = None
|
||||||
|
self.uname = 'root'
|
||||||
|
self.pwd = 'admin'
|
||||||
|
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return f"BMMiner: {str(self.ip)}"
|
return f"BMMiner: {str(self.ip)}"
|
||||||
@@ -21,16 +25,58 @@ class BMMiner(BaseMiner):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
async def get_hostname(self) -> str:
|
async def get_hostname(self) -> str:
|
||||||
|
try:
|
||||||
|
async with (await self._get_ssh_connection()) as conn:
|
||||||
|
if conn is not None:
|
||||||
|
data = await conn.run('cat /proc/sys/kernel/hostname')
|
||||||
|
return data.stdout.strip()
|
||||||
|
else:
|
||||||
return "?"
|
return "?"
|
||||||
|
except Exception:
|
||||||
|
return "?"
|
||||||
|
|
||||||
|
async def _get_ssh_connection(self) -> asyncssh.connect:
|
||||||
|
try:
|
||||||
|
conn = await asyncssh.connect(str(self.ip),
|
||||||
|
known_hosts=None,
|
||||||
|
username=self.uname,
|
||||||
|
password=self.pwd,
|
||||||
|
server_host_key_algs=['ssh-rsa'])
|
||||||
|
return conn
|
||||||
|
except asyncssh.misc.PermissionDenied:
|
||||||
|
try:
|
||||||
|
conn = await asyncssh.connect(str(self.ip),
|
||||||
|
known_hosts=None,
|
||||||
|
username="admin",
|
||||||
|
password="admin",
|
||||||
|
server_host_key_algs=['ssh-rsa'])
|
||||||
|
return conn
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
except OSError:
|
||||||
|
print(str(self.ip) + " Connection refused.")
|
||||||
|
return None
|
||||||
|
|
||||||
|
async def send_ssh_command(self, cmd):
|
||||||
|
result = None
|
||||||
|
async with (await self._get_ssh_connection()) as conn:
|
||||||
|
for i in range(3):
|
||||||
|
try:
|
||||||
|
result = await conn.run(cmd)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"{cmd} error: {e}")
|
||||||
|
if i == 3:
|
||||||
|
return
|
||||||
|
continue
|
||||||
|
|
||||||
async def send_config(self, _):
|
async def send_config(self, _):
|
||||||
return None # ignore for now
|
return None # ignore for now
|
||||||
|
|
||||||
async def restart_backend(self) -> None:
|
async def restart_backend(self) -> None:
|
||||||
return None # Murray
|
return None
|
||||||
|
|
||||||
async def reboot(self) -> None:
|
async def reboot(self) -> None:
|
||||||
return None # Murray
|
await self.send_ssh_command("reboot")
|
||||||
|
|
||||||
async def get_config(self) -> None:
|
async def get_config(self) -> None:
|
||||||
return None # Murray
|
return None
|
||||||
|
|||||||
@@ -111,9 +111,7 @@ class CGMiner(BaseMiner):
|
|||||||
await self.send_ssh_command(commands)
|
await self.send_ssh_command(commands)
|
||||||
|
|
||||||
async def reboot(self) -> None:
|
async def reboot(self) -> None:
|
||||||
commands = ['reboot']
|
await self.send_ssh_command("reboot")
|
||||||
commands = ';'.join(commands)
|
|
||||||
await self.send_ssh_command(commands)
|
|
||||||
|
|
||||||
async def start_cgminer(self) -> None:
|
async def start_cgminer(self) -> None:
|
||||||
commands = ['mkdir -p /etc/tmp/',
|
commands = ['mkdir -p /etc/tmp/',
|
||||||
|
|||||||
0
tools/__init__.py
Normal file
0
tools/__init__.py
Normal file
0
tools/bad_board_util/__init__.py
Normal file
0
tools/bad_board_util/__init__.py
Normal file
0
tools/bad_board_util/func/__init__.py
Normal file
0
tools/bad_board_util/func/__init__.py
Normal file
1
tools/bad_board_util/layout.py
Normal file
1
tools/bad_board_util/layout.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
import PySimpleGUI as sg
|
||||||
7
tools/bad_board_util/miner_factory.py
Normal file
7
tools/bad_board_util/miner_factory.py
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
"""
|
||||||
|
This file stores the MinerFactory instance used by the BadBoardUtility for use in other files.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from miners.miner_factory import MinerFactory
|
||||||
|
|
||||||
|
miner_factory = MinerFactory()
|
||||||
0
tools/bad_board_util/ui.py
Normal file
0
tools/bad_board_util/ui.py
Normal file
Reference in New Issue
Block a user