diff --git a/pyasic/miners/backends/braiins_os.py b/pyasic/miners/backends/braiins_os.py index 00d86266..6be97533 100644 --- a/pyasic/miners/backends/braiins_os.py +++ b/pyasic/miners/backends/braiins_os.py @@ -37,6 +37,9 @@ from pyasic.ssh.braiins_os import BOSMinerSSH from pyasic.web.braiins_os import BOSerWebAPI, BOSMinerWebAPI from pyasic.web.braiins_os.proto.braiins.bos.v1 import SaveAction +import aiofiles +import base64 + BOSMINER_DATA_LOC = DataLocations( **{ str(DataOptions.MAC): DataFunction( @@ -570,6 +573,48 @@ class BOSMiner(BraiinsOSFirmware): except LookupError: pass + async def upgrade_firmware(self, file: Path): + """ + Upgrade the firmware of the BOSMiner device. + + Args: + file (Path): The local file path of the firmware to be uploaded. + + Returns: + str: Confirmation message after upgrading the firmware. + """ + try: + self.logger.info("Starting firmware upgrade process.") + + if not file: + raise ValueError("File location must be provided for firmware upgrade.") + + # Read the firmware file contents + async with aiofiles.open(file, "rb") as f: + upgrade_contents = await f.read() + + # Encode the firmware contents in base64 + encoded_contents = base64.b64encode(upgrade_contents).decode('utf-8') + + # Upload the firmware file to the BOSMiner device + self.logger.info(f"Uploading firmware file from {file} to the device.") + await self.ssh.send_command(f"echo {encoded_contents} | base64 -d > /tmp/firmware.tar && sysupgrade /tmp/firmware.tar") + + self.logger.info("Firmware upgrade process completed successfully.") + return "Firmware upgrade completed successfully." + except FileNotFoundError as e: + self.logger.error(f"File not found during the firmware upgrade process: {e}") + raise + except ValueError as e: + self.logger.error(f"Validation error occurred during the firmware upgrade process: {e}") + raise + except OSError as e: + self.logger.error(f"OS error occurred during the firmware upgrade process: {e}") + raise + except Exception as e: + self.logger.error(f"An unexpected error occurred during the firmware upgrade process: {e}", exc_info=True) + raise + BOSER_DATA_LOC = DataLocations( **{ diff --git a/pyasic/miners/base.py b/pyasic/miners/base.py index 879a3a79..c66dc3b3 100644 --- a/pyasic/miners/base.py +++ b/pyasic/miners/base.py @@ -561,4 +561,4 @@ class BaseMiner(MinerProtocol): self.ssh = self._ssh_cls(ip) -AnyMiner = TypeVar("AnyMiner", bound=BaseMiner) +AnyMiner = TypeVar("AnyMiner", bound=BaseMiner) \ No newline at end of file diff --git a/pyasic/ssh/braiins_os.py b/pyasic/ssh/braiins_os.py index 6dee3502..28ad000d 100644 --- a/pyasic/ssh/braiins_os.py +++ b/pyasic/ssh/braiins_os.py @@ -92,4 +92,4 @@ class BOSMinerSSH(BaseSSH): Returns: str: Status of the LED. """ - return await self.send_command("cat /sys/class/leds/'Red LED'/delay_off") + return await self.send_command("cat /sys/class/leds/'Red LED'/delay_off") \ No newline at end of file