set up cgminer get hostname, and fixed the bug with asyncio trying to close non socket objects
This commit is contained in:
@@ -3,6 +3,11 @@ from cfg_util.layout import window
|
||||
from cfg_util.ui import ui
|
||||
|
||||
import asyncio
|
||||
import sys
|
||||
|
||||
# Fix bug with some whatsminers and asyncio because of a socket not being shut down:
|
||||
if sys.version_info[0] == 3 and sys.version_info[1] >= 8 and sys.platform.startswith('win'):
|
||||
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
@@ -127,14 +127,6 @@ 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()
|
||||
|
||||
3
main.py
3
main.py
@@ -31,6 +31,7 @@ async def braiins_update():
|
||||
results = await asyncio.gather(*tasks)
|
||||
print(results)
|
||||
|
||||
|
||||
async def test_command():
|
||||
miner_network = MinerNetwork('192.168.1.1')
|
||||
miners = await miner_network.scan_network_for_miners()
|
||||
@@ -39,7 +40,5 @@ async def test_command():
|
||||
print(data)
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
asyncio.new_event_loop().run_until_complete(test_command())
|
||||
|
||||
@@ -9,24 +9,47 @@ class CGMiner(BaseMiner):
|
||||
super().__init__(ip, api)
|
||||
self.config = None
|
||||
self.uname = 'root'
|
||||
self.pwd = 'root'
|
||||
self.pwd = 'admin'
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"CGMiner: {str(self.ip)}"
|
||||
|
||||
async def get_hostname(self) -> str:
|
||||
return "CGMiner Unknown"
|
||||
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 "CGMiner Unknown"
|
||||
except Exception as e:
|
||||
return "CGMiner Unknown"
|
||||
|
||||
async def send_config(self):
|
||||
return None # ignore for now
|
||||
|
||||
async def _get_ssh_connection(self) -> asyncssh.connect:
|
||||
conn = await asyncssh.connect(str(self.ip),
|
||||
known_hosts=None,
|
||||
username=self.uname,
|
||||
password=self.pwd,
|
||||
server_host_key_algs=['ssh-rsa'])
|
||||
return conn
|
||||
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 as e:
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user