diff --git a/pyasic/config/__init__.py b/pyasic/config/__init__.py index 2b1f50f6..cea7b626 100644 --- a/pyasic/config/__init__.py +++ b/pyasic/config/__init__.py @@ -245,7 +245,9 @@ class MinerConfig: fan_speed: Manual fan speed to run the fan at (only if temp_mode == "manual"). asicboost: Whether or not to enable asicboost. autotuning_enabled: Whether or not to enable autotuning. + autotuning_mode: Autotuning mode, either "wattage" or "hashrate". autotuning_wattage: The wattage to use when autotuning. + autotuning_hashrate: The hashrate to use when autotuning. dps_enabled: Whether or not to enable dynamic power scaling. dps_power_step: The amount of power to reduce autotuning by when the miner reaches dangerous temp. dps_min_power: The minimum power to reduce autotuning to. @@ -266,7 +268,9 @@ class MinerConfig: asicboost: bool = None autotuning_enabled: bool = True - autotuning_wattage: int = 900 + autotuning_mode: Literal["power", "hashrate"] = None + autotuning_wattage: int = None + autotuning_hashrate: int = None dps_enabled: bool = None dps_power_step: int = None @@ -349,14 +353,20 @@ class MinerConfig: self.autotuning_enabled = data[key][_key] elif _key == "psu_power_limit": self.autotuning_wattage = data[key][_key] + elif _key == "power_target": + self.autotuning_wattage = data[key][_key] + elif _key == "hashrate_target": + self.autotuning_hashrate = data[key][_key] + elif _key == "mode": + self.autotuning_mode = data[key][_key].replace("_target", "") - if key == "power_scaling": + if key in ["power_scaling", "performance_scaling"]: for _key in data[key].keys(): if _key == "enabled": self.dps_enabled = data[key][_key] elif _key == "power_step": self.dps_power_step = data[key][_key] - elif _key == "min_psu_power_limit": + elif _key in ["min_psu_power_limit", "min_power_target"]: self.dps_min_power = data[key][_key] elif _key == "shutdown_enabled": self.dps_shutdown_enabled = data[key][_key] @@ -482,7 +492,7 @@ class MinerConfig: "format": { "version": "1.2+", "model": f"Antminer {model}", - "generator": "Upstream Config Utility", + "generator": "pyasic", "timestamp": int(time.time()), }, "group": [ @@ -500,8 +510,16 @@ class MinerConfig: cfg["autotuning"] = {} if self.autotuning_enabled: cfg["autotuning"]["enabled"] = self.autotuning_enabled - if self.autotuning_wattage: - cfg["autotuning"]["psu_power_limit"] = self.autotuning_wattage + if self.autotuning_mode: + cfg["format"]["version"] = "2.0" + cfg["autotuning"]["mode"] = self.autotuning_mode + "_target" + if self.autotuning_wattage: + cfg["autotuning"]["power_target"] = self.autotuning_wattage + elif self.autotuning_hashrate: + cfg["autotuning"]["hashrate_target"] = self.autotuning_hashrate + else: + if self.autotuning_wattage: + cfg["autotuning"]["psu_power_limit"] = self.autotuning_wattage if self.asicboost: cfg["hash_chain_global"] = {} @@ -525,7 +543,10 @@ class MinerConfig: if self.dps_power_step: cfg["power_scaling"]["power_step"] = self.dps_power_step if self.dps_min_power: - cfg["power_scaling"]["min_psu_power_limit"] = self.dps_min_power + if cfg["format"]["version"] == "2.0": + cfg["power_scaling"]["min_power_target"] = self.dps_min_power + else: + cfg["power_scaling"]["min_psu_power_limit"] = self.dps_min_power if self.dps_shutdown_enabled: cfg["power_scaling"]["shutdown_enabled"] = self.dps_shutdown_enabled if self.dps_shutdown_duration: diff --git a/pyasic/miners/_backends/bosminer.py b/pyasic/miners/_backends/bosminer.py index 05c946f9..e425950f 100644 --- a/pyasic/miners/_backends/bosminer.py +++ b/pyasic/miners/_backends/bosminer.py @@ -198,11 +198,8 @@ class BOSMiner(BaseMiner): return self.config if conn: async with conn: - logging.debug(f"{self}: Opening SFTP connection.") - async with conn.start_sftp_client() as sftp: - logging.debug(f"{self}: Reading config file.") - async with sftp.open("/etc/bosminer.toml") as file: - toml_data = toml.loads(await file.read()) + # good ol' BBB compatibility :/ + toml_data = toml.loads((await conn.run("cat /etc/bosminer.toml")).stdout) logging.debug(f"{self}: Converting config file.") cfg = MinerConfig().from_raw(toml_data) self.config = cfg @@ -219,14 +216,28 @@ class BOSMiner(BaseMiner): except (asyncssh.Error, OSError): return None async with conn: - await conn.run("/etc/init.d/bosminer stop") - logging.debug(f"{self}: Opening SFTP connection.") - async with conn.start_sftp_client() as sftp: - logging.debug(f"{self}: Opening config file.") - async with sftp.open("/etc/bosminer.toml", "w+") as file: - await file.write(toml_conf) - logging.debug(f"{self}: Restarting BOSMiner") - await conn.run("/etc/init.d/bosminer start") + # BBB check because bitmain suxx + bbb_check = await conn.run("if [ ! -f /etc/init.d/bosminer ]; then echo '1'; else echo '0'; fi;") + + bbb = bbb_check.stdout.strip() == "1" + + if not bbb: + await conn.run("/etc/init.d/bosminer stop") + logging.debug(f"{self}: Opening SFTP connection.") + async with conn.start_sftp_client() as sftp: + logging.debug(f"{self}: Opening config file.") + async with sftp.open("/etc/bosminer.toml", "w+") as file: + await file.write(toml_conf) + logging.debug(f"{self}: Restarting BOSMiner") + await conn.run("/etc/init.d/bosminer start") + + # I really hate BBB, please get rid of it if you have it + else: + await conn.run("/etc/init.d/S99Bosminer stop") + logging.debug(f"{self}: BBB sending config") + await conn.run("echo '" + toml_conf + "' > /etc/bosminer.toml") + logging.debug(f"{self}: BBB restarting bosminer.") + await conn.run("/etc/init.d/S99Bosminer start") async def set_power_limit(self, wattage: int) -> bool: try: