fixed some of the issues with newer whatsminers not scanning properly because of their API, still a bug with asyncio
This commit is contained in:
@@ -72,7 +72,10 @@ class BaseMinerAPI:
|
||||
print(e)
|
||||
|
||||
try:
|
||||
data = json.loads(data.decode('utf-8')[:-1])
|
||||
if data.endswith(b"\x00"):
|
||||
data = json.loads(data.decode('utf-8')[:-1])
|
||||
else:
|
||||
data = json.loads(data.decode('utf-8'))
|
||||
except json.decoder.JSONDecodeError:
|
||||
raise APIError(f"Decode Error: {data}")
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ from operator import itemgetter
|
||||
import PySimpleGUI as sg
|
||||
import aiofiles
|
||||
import toml
|
||||
import yaml
|
||||
|
||||
from miners.miner_factory import MinerFactory
|
||||
from network import MinerNetwork
|
||||
@@ -159,6 +158,14 @@ async def get_data(ip_list: list):
|
||||
|
||||
|
||||
async def get_formatted_data(ip: ipaddress.ip_address):
|
||||
# TODO: Fix bug with some whatsminers and asyncio:
|
||||
# Traceback (most recent call last):
|
||||
# File "C:\Users\upstr\AppData\Local\Programs\Python\Python310\lib\asyncio\events.py", line 80, in _run
|
||||
# self._context.run(self._callback, *self._args)
|
||||
# File "C:\Users\upstr\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 162, in _call_connection_lost
|
||||
# self._sock.shutdown(socket.SHUT_RDWR)
|
||||
# OSError: [WinError 10038] An operation was attempted on something that is not a socket
|
||||
|
||||
miner = await miner_factory.get_miner(ip)
|
||||
data = await miner.api.multicommand("summary", "pools", "tunerstatus")
|
||||
host = await miner.get_hostname()
|
||||
|
||||
@@ -61,12 +61,37 @@ class MinerFactory:
|
||||
break
|
||||
data += d
|
||||
|
||||
data = json.loads(data.decode('utf-8')[:-1])
|
||||
if data.endswith(b"\x00"):
|
||||
data = json.loads(data.decode('utf-8')[:-1])
|
||||
else:
|
||||
# some stupid whatsminers need a different command
|
||||
fut = asyncio.open_connection(str(ip), 4028)
|
||||
# get reader and writer streams
|
||||
reader, writer = await asyncio.wait_for(fut, timeout=5)
|
||||
|
||||
# create the command
|
||||
cmd = {"command": "get_version"}
|
||||
|
||||
# send the command
|
||||
writer.write(json.dumps(cmd).encode('utf-8'))
|
||||
await writer.drain()
|
||||
|
||||
# instantiate data
|
||||
data = b""
|
||||
|
||||
# loop to receive all the data
|
||||
while True:
|
||||
d = await reader.read(4096)
|
||||
if not d:
|
||||
break
|
||||
data += d
|
||||
|
||||
data = data.decode('utf-8').replace("\n", "")
|
||||
data = json.loads(data)
|
||||
|
||||
# close the connection
|
||||
writer.close()
|
||||
await writer.wait_closed()
|
||||
|
||||
# check if the data returned is correct or an error
|
||||
# if status isn't a key, it is a multicommand
|
||||
if "STATUS" not in data.keys():
|
||||
@@ -78,11 +103,17 @@ class MinerFactory:
|
||||
# this is an error
|
||||
raise APIError(data["STATUS"][0]["Msg"])
|
||||
else:
|
||||
# check for stupid whatsminer formatting
|
||||
if not isinstance(data["STATUS"], list):
|
||||
if data["STATUS"] not in ("S", "I"):
|
||||
raise APIError(data["Msg"])
|
||||
else:
|
||||
if "whatsminer" in data["Description"]:
|
||||
return {'STATUS': [{'STATUS': 'S', 'When': 1635435132, 'Code': 22, 'Msg': 'CGMiner versions', 'Description': 'cgminer 4.9.2'}], 'VERSION': [{'CGMiner': '4.9.2', 'API': '3.7'}], 'id': 1}
|
||||
# make sure the command succeeded
|
||||
if data["STATUS"][0]["STATUS"] not in ("S", "I"):
|
||||
elif data["STATUS"][0]["STATUS"] not in ("S", "I"):
|
||||
# this is an error
|
||||
raise APIError(data["STATUS"][0]["Msg"])
|
||||
|
||||
# return the data
|
||||
return data
|
||||
except OSError as e:
|
||||
@@ -90,6 +121,8 @@ class MinerFactory:
|
||||
return None
|
||||
else:
|
||||
print(ip, e)
|
||||
except Exception as e:
|
||||
print(ip, e)
|
||||
# except json.decoder.JSONDecodeError:
|
||||
# print("Decode Error @ " + str(ip) + str(data))
|
||||
# except Exception as e:
|
||||
# print(ip, e)
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user