bug: fix reboot and restart on btminer not returning data.

This commit is contained in:
UpstreamData
2023-02-15 14:17:57 -07:00
parent 1a8a5ccb0e
commit 04974d5287
2 changed files with 14 additions and 18 deletions

View File

@@ -173,9 +173,14 @@ If you are sure you want to use this command please use API.send_command("{comma
writer.write(data)
logging.debug(f"{self} - ([Hidden] Send Bytes) - Draining")
await writer.drain()
# instantiate data
ret_data = b""
ret_data = await asyncio.wait_for(reader.read(4096), timeout=timeout)
try:
# Fix for stupid whatsminer bug, reboot/restart seem to not load properly in the loop
# have to receive, save the data, check if there is more data by reading with a short timeout
# append that data if there is more, and then onto the main loop.
ret_data += await asyncio.wait_for(reader.read(1), timeout=1)
except asyncio.TimeoutError:
return ret_data
# loop to receive all the data
logging.debug(f"{self} - ([Hidden] Send Bytes) - Receiving")
@@ -185,6 +190,7 @@ If you are sure you want to use this command please use API.send_command("{comma
d = await asyncio.wait_for(reader.read(4096), timeout=timeout)
if not d:
break
print("hello", d)
ret_data += d
except (asyncio.CancelledError, asyncio.TimeoutError) as e:
raise e
@@ -244,6 +250,8 @@ If you are sure you want to use this command please use API.send_command("{comma
str_data = str_data.replace("}{", "},{")
# fix an error with a bmminer return having a specific comma that breaks json.loads()
str_data = str_data.replace("[,{", "[{")
# fix an error with a btminer return having a missing comma. (2023-01-06 version)
str_data = str_data.replace('""temp0', '","temp0')
# fix an error with Avalonminers returning inf and nan
str_data = str_data.replace("info", "1nfo")
str_data = str_data.replace("inf", "0")

View File

@@ -247,21 +247,9 @@ class BTMinerAPI(BaseMinerAPI):
try:
data = await self._send_bytes(enc_command, timeout)
except (asyncio.CancelledError, asyncio.TimeoutError) as e:
if command["cmd"] in ["reboot", "restart_btminer", "power_on", "power_off"]:
logging.info(
f"{self} - (reboot/restart_btminer/power_on/power_off) - Whatsminers currently break this. "
f"Ignoring exception. Command probably worked."
)
# FAKING IT HERE
data = (
b'{"STATUS": "S", "When": 1670966423, "Code": 131, "Msg": "API command OK", "Description": "'
+ command["cmd"].encode("utf-8")
+ b'"}'
)
else:
if ignore_errors:
return {}
raise APIError("No data was returned from the API.")
if ignore_errors:
return {}
raise APIError("No data was returned from the API.")
if not data:
if ignore_errors: