From 027423242d4f5ee15eee25075db93a117a5cb80a Mon Sep 17 00:00:00 2001 From: UpstreamData Date: Wed, 3 Nov 2021 11:41:12 -0600 Subject: [PATCH] fixed a bug with multicommand on S19 where it doesnt work with the '+'.join(*commands) --- API/__init__.py | 26 +++++++++++++++++++++----- main.py | 16 +++++++++++++--- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/API/__init__.py b/API/__init__.py index 37d1e519..8bf3391a 100644 --- a/API/__init__.py +++ b/API/__init__.py @@ -36,6 +36,7 @@ class BaseMinerAPI: commands = [*commands] for item in commands: if item not in self.get_commands(): + print(f"Removing command: {item}") commands.remove(item) command = "+".join(commands) return await self.send_command(command) @@ -83,6 +84,22 @@ class BaseMinerAPI: writer.close() await writer.wait_closed() + if not self.validate_command_output(data): + try: + data = {} + for cmd in command.split("+"): + data[cmd] = [] + data[cmd].append(await self.send_command(cmd)) + except Exception as e: + print(e) + + # check again after second try + if not self.validate_command_output(data): + raise APIError(data["STATUS"][0]["Msg"]) + + return data + + def validate_command_output(self, data): # 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(): @@ -93,12 +110,11 @@ class BaseMinerAPI: if "STATUS" in data.keys(): if data[key][0]["STATUS"][0]["STATUS"] not in ["S", "I"]: # this is an error - raise APIError(data["STATUS"][0]["Msg"]) + return False else: # make sure the command succeeded if data["STATUS"][0]["STATUS"] not in ("S", "I"): # this is an error - raise APIError(data["STATUS"][0]["Msg"]) - - # return the data - return data + if data["STATUS"][0]["STATUS"] not in ("S", "I"): + return False + return True diff --git a/main.py b/main.py index 1a122e59..eba1a170 100644 --- a/main.py +++ b/main.py @@ -3,7 +3,7 @@ from miners.bosminer import BOSminer import asyncio -async def main(): +async def good_boards(): miner_network = MinerNetwork('192.168.1.1') miners = await miner_network.scan_network_for_miners() # print("\n".join([str(miner.ip) for miner in miners])) @@ -13,7 +13,7 @@ async def main(): # print('\n'.join([f"{str(miner.ip)}" for miner in miners])) -async def main_bad(): +async def bad_boards(): miner_network = MinerNetwork('192.168.1.1') miners = await miner_network.scan_network_for_miners() bad_list = list(filter(None, await asyncio.gather(*[miner.get_bad_boards() for miner in miners if isinstance(miner, BOSminer)]))) @@ -31,5 +31,15 @@ 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() + tasks = miners[0].api.multicommand("summary", "pools", "tunerstatus") + data = await asyncio.gather(tasks) + print(data) + + + + if __name__ == '__main__': - asyncio.new_event_loop().run_until_complete(braiins_update()) + asyncio.new_event_loop().run_until_complete(test_command())