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)
|
print(e)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
if data.endswith(b"\x00"):
|
||||||
data = json.loads(data.decode('utf-8')[:-1])
|
data = json.loads(data.decode('utf-8')[:-1])
|
||||||
|
else:
|
||||||
|
data = json.loads(data.decode('utf-8'))
|
||||||
except json.decoder.JSONDecodeError:
|
except json.decoder.JSONDecodeError:
|
||||||
raise APIError(f"Decode Error: {data}")
|
raise APIError(f"Decode Error: {data}")
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ from operator import itemgetter
|
|||||||
import PySimpleGUI as sg
|
import PySimpleGUI as sg
|
||||||
import aiofiles
|
import aiofiles
|
||||||
import toml
|
import toml
|
||||||
import yaml
|
|
||||||
|
|
||||||
from miners.miner_factory import MinerFactory
|
from miners.miner_factory import MinerFactory
|
||||||
from network import MinerNetwork
|
from network import MinerNetwork
|
||||||
@@ -159,6 +158,14 @@ async def get_data(ip_list: list):
|
|||||||
|
|
||||||
|
|
||||||
async def get_formatted_data(ip: ipaddress.ip_address):
|
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)
|
miner = await miner_factory.get_miner(ip)
|
||||||
data = await miner.api.multicommand("summary", "pools", "tunerstatus")
|
data = await miner.api.multicommand("summary", "pools", "tunerstatus")
|
||||||
host = await miner.get_hostname()
|
host = await miner.get_hostname()
|
||||||
|
|||||||
@@ -61,12 +61,37 @@ class MinerFactory:
|
|||||||
break
|
break
|
||||||
data += d
|
data += d
|
||||||
|
|
||||||
|
if data.endswith(b"\x00"):
|
||||||
data = json.loads(data.decode('utf-8')[:-1])
|
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
|
# close the connection
|
||||||
writer.close()
|
writer.close()
|
||||||
await writer.wait_closed()
|
await writer.wait_closed()
|
||||||
|
|
||||||
# check if the data returned is correct or an error
|
# check if the data returned is correct or an error
|
||||||
# if status isn't a key, it is a multicommand
|
# if status isn't a key, it is a multicommand
|
||||||
if "STATUS" not in data.keys():
|
if "STATUS" not in data.keys():
|
||||||
@@ -78,11 +103,17 @@ class MinerFactory:
|
|||||||
# this is an error
|
# this is an error
|
||||||
raise APIError(data["STATUS"][0]["Msg"])
|
raise APIError(data["STATUS"][0]["Msg"])
|
||||||
else:
|
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
|
# 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
|
# this is an error
|
||||||
raise APIError(data["STATUS"][0]["Msg"])
|
raise APIError(data["STATUS"][0]["Msg"])
|
||||||
|
|
||||||
# return the data
|
# return the data
|
||||||
return data
|
return data
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
@@ -90,6 +121,8 @@ class MinerFactory:
|
|||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
print(ip, e)
|
print(ip, e)
|
||||||
except Exception as e:
|
# except json.decoder.JSONDecodeError:
|
||||||
print(ip, e)
|
# print("Decode Error @ " + str(ip) + str(data))
|
||||||
|
# except Exception as e:
|
||||||
|
# print(ip, e)
|
||||||
return None
|
return None
|
||||||
|
|||||||
Reference in New Issue
Block a user