added Hive get bad boards, and started on a bad board utility

This commit is contained in:
UpstreamData
2022-01-21 16:15:46 -07:00
parent a1839aae46
commit a93027369e
10 changed files with 82 additions and 10 deletions

View File

@@ -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", "")
# fix an error with a bmminer return not having a specific comma that breaks json.loads()
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
parsed_data = json.loads(str_data)
# handle bad json
except json.decoder.JSONDecodeError as e:
print(e)
raise APIError(f"Decode Error: {data}")
raise APIError(f"Decode Error: {str_data}")
return parsed_data

View File

@@ -1,4 +1,7 @@
import asyncio
from miners.bmminer import BMMiner
import json
class HiveonT9(BMMiner):
@@ -9,3 +12,18 @@ class HiveonT9(BMMiner):
def __repr__(self) -> str:
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

View File

@@ -1,12 +1,16 @@
from API.bmminer import BMMinerAPI
from miners import BaseMiner
import asyncssh
class BMMiner(BaseMiner):
def __init__(self, ip: str) -> None:
api = BMMinerAPI(ip)
self.model = None
super().__init__(ip, api)
self.model = None
self.config = None
self.uname = 'root'
self.pwd = 'admin'
def __repr__(self) -> str:
return f"BMMiner: {str(self.ip)}"
@@ -21,16 +25,58 @@ class BMMiner(BaseMiner):
return None
async def get_hostname(self) -> str:
return "?"
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 "?"
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, _):
return None # ignore for now
async def restart_backend(self) -> None:
return None # Murray
return None
async def reboot(self) -> None:
return None # Murray
await self.send_ssh_command("reboot")
async def get_config(self) -> None:
return None # Murray
return None

View File

@@ -111,9 +111,7 @@ class CGMiner(BaseMiner):
await self.send_ssh_command(commands)
async def reboot(self) -> None:
commands = ['reboot']
commands = ';'.join(commands)
await self.send_ssh_command(commands)
await self.send_ssh_command("reboot")
async def start_cgminer(self) -> None:
commands = ['mkdir -p /etc/tmp/',

0
tools/__init__.py Normal file
View File

View File

View File

View File

@@ -0,0 +1 @@
import PySimpleGUI as sg

View 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()

View File