hoymiles-wifi: Requests fail randomly
I have 3 microinverters and I noticed that one of them was intermittently unavailable, always the same one. After some debugging, I realized that microinverter was randomly missing from the async_get_real_data_new response. After more digging, I saw that for me async_get_real_data_new requires 4 requests and it sometimes failed with the request with that microinverter.
I’ve seen it fail because of:
- Buffer is too short for unpacking
- OSError / asyncio.TimeoutError (I don’t know which one exactly, though)
I’ve tried adding a simple retry strategy based on exponential backoff and so far so good, but sometimes it took up to 4 retries to get the response 😐
Is this a known issue? Does the S-Miles app do anything like this to handle failed requests?
@@ -377,23 +389,46 @@ class DTU:
command, request, CommandPB_pb2.CommandReqDTO
)
async def async_send_request(
self,
command: bytes,
request: Any,
response_type: Any,
dtu_port: int = DTU_PORT,
):
- """Send request to DTU."""
+ """Send request to DTU (with exponential backoff retries)."""
+
+ retries = 0
+ while retries < 5:
+ response = await self.async_send_single_request(
+ command, request, response_type, dtu_port
+ )
+ if response is not None:
+ return response
+ retries += 1
+ await asyncio.sleep(2 ** retries)
+
+ return None
+
+ async def async_send_single_request(
+ self,
+ command: bytes,
+ request: Any,
+ response_type: Any,
+ dtu_port: int = DTU_PORT,
+ ):
+ """Send single request to DTU (no retries, use async_send_request instead)."""
self.sequence = (self.sequence + 1) & 0xFFFF
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 18 (10 by maintainers)
Yes that’s true. Once that is confirmed I will add a retry strategy too.
@sergiou87 I have pushed a potential fix to
devbranch. Can you maybe check that out?It seems like there is an issue with the
V1.1.32. Maybe the package uploaded to APKPure is corrupted. Try withV1.1.31, this just worked for me.Sure thing. However, the decompiled Android app is rather large (around 0.5-1Gb). The easiest way to get access is to decompile it yourself. It’s not complicated:
The structure of the App is rather opaque. Best is to search for some known function calls, e.g.
setCp(to figure out what is going on. If you need any more help just let me know.