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:

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)

Most upvoted comments

Yes that’s true. Once that is confirmed I will add a retry strategy too.

@sergiou87 I have pushed a potential fix to dev branch. 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 with V1.1.31, this just worked for me.

Oh! That’s great, thank you! I’ve been using these changes (1 second delay between requests + exponential backoff for up to 5 retries) and so far so good, but I will try your change tomorrow!

Oh and if you want some extra eyes on how that app works feel free to share the source with me (or not!),

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:

  1. Get APKLab: https://github.com/APKLab/APKLab
  2. Get the APK from e.g. APKPure: https://apkpure.com/s-miles-installer/com.hm.hemaiInstall1
  3. Decompile 😃

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.