From c6ca1df112cf88c068b61c695282389d91e104ad Mon Sep 17 00:00:00 2001 From: Upstream Data Date: Sat, 5 Nov 2022 10:15:18 -0600 Subject: [PATCH] bug: fix some issues with get data on X19 from CGMiner on Vnish to BMMiner on stock. --- pyasic/API/cgminer.py | 35 +++++++++++++++++++++++++++++- pyasic/miners/_backends/bmminer.py | 7 +++--- pyasic/miners/_backends/cgminer.py | 9 ++++---- 3 files changed, 43 insertions(+), 8 deletions(-) diff --git a/pyasic/API/cgminer.py b/pyasic/API/cgminer.py index 0ec70bb4..cac318d6 100644 --- a/pyasic/API/cgminer.py +++ b/pyasic/API/cgminer.py @@ -12,7 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -from pyasic.API import BaseMinerAPI +from pyasic.API import BaseMinerAPI, APIError + +import logging class CGMinerAPI(BaseMinerAPI): @@ -36,6 +38,37 @@ class CGMinerAPI(BaseMinerAPI): def __init__(self, ip: str, port: int = 4028): super().__init__(ip, port) + async def multicommand( + self, *commands: str, ignore_x19_error: bool = False + ) -> dict: + logging.debug(f"{self.ip}: Sending multicommand: {[*commands]}") + # make sure we can actually run each command, otherwise they will fail + commands = self._check_commands(*commands) + # standard multicommand format is "command1+command2" + # doesnt work for S19 which uses the backup _x19_multicommand + command = "+".join(commands) + try: + data = await self.send_command(command, allow_warning=ignore_x19_error) + except APIError: + logging.debug(f"{self.ip}: Handling X19 multicommand.") + data = await self._x19_multicommand(*command.split("+")) + logging.debug(f"{self.ip}: Received multicommand data.") + return data + + async def _x19_multicommand(self, *commands): + data = None + try: + data = {} + # send all commands individually + for cmd in commands: + data[cmd] = [] + data[cmd].append(await self.send_command(cmd, allow_warning=True)) + except APIError as e: + raise APIError(e) + except Exception as e: + logging.warning(f"{self.ip}: API Multicommand Error: {e}") + return data + async def version(self) -> dict: """Get miner version info.
diff --git a/pyasic/miners/_backends/bmminer.py b/pyasic/miners/_backends/bmminer.py index 469dd671..7da49dec 100644 --- a/pyasic/miners/_backends/bmminer.py +++ b/pyasic/miners/_backends/bmminer.py @@ -281,12 +281,13 @@ class BMMiner(BaseMiner): if (not chips) or (not chips > 0): hashboard.missing = True data.hashboards.append(hashboard) - if f"temp_pcb{i}" in temp[1].keys(): - env_temp = temp[1][f"temp_pcb{i}"].split("-")[0] + + if f"temp_pcb{i}" in boards[1].keys(): + env_temp = boards[1][f"temp_pcb{i}"].split("-")[0] if not env_temp == 0: env_temp_list.append(int(env_temp)) if not env_temp_list == []: - data.env_temp = sum(env_temp_list) / len(env_temp_list) + data.env_temp = round(sum(env_temp_list) / len(env_temp_list)) if stats: temp = stats.get("STATS") diff --git a/pyasic/miners/_backends/cgminer.py b/pyasic/miners/_backends/cgminer.py index a86ac15c..22df1b4f 100644 --- a/pyasic/miners/_backends/cgminer.py +++ b/pyasic/miners/_backends/cgminer.py @@ -206,7 +206,7 @@ class CGMiner(BaseMiner): miner_data = None for i in range(PyasicSettings().miner_get_data_retries): miner_data = await self.api.multicommand( - "summary", "pools", "stats", ignore_x19_error=True + "summary", "pools", "stats", ) if miner_data: break @@ -264,12 +264,13 @@ class CGMiner(BaseMiner): if (not chips) or (not chips > 0): hashboard.missing = True data.hashboards.append(hashboard) - if f"temp_pcb{i}" in temp[1].keys(): - env_temp = temp[1][f"temp_pcb{i}"].split("-")[0] + + if f"temp_pcb{i}" in boards[1].keys(): + env_temp = boards[1][f"temp_pcb{i}"].split("-")[0] if not env_temp == 0: env_temp_list.append(int(env_temp)) if not env_temp_list == []: - data.env_temp = sum(env_temp_list) / len(env_temp_list) + data.env_temp = round(sum(env_temp_list) / len(env_temp_list)) if stats: temp = stats.get("STATS")