denpamusic / PyPlumIO

PyPlumIO is a native ecoNET library for Plum ecoMAX controllers.
MIT License
15 stars 2 forks source link

Can't connect to #135

Open danielkovarik2 opened 3 weeks ago

danielkovarik2 commented 3 weeks ago

Is there an existing issue for this?

I'm having the following issue:

Hello,

I am having issues with connecting to the boiler. Noticed initially in home assistant integration (timeouts) and after some digging I've found an error message in pyplumio. Unknown sender type (80)

I have tried the script to get data from the ecomax (https://gist.github.com/denpamusic/5df805524738ea1bb9c00d25ed351c46) without any issues. Attaching file ecomax_data.json

But when I tried to test another script I found in other issue here I got the unknown sender error again.

image

Would you please try to help me where should I look?

Tried:

Only change I made at home before this happened was that I changed the router (from old mikrotik to newer mikrotik) but it shouldn't be the issue I believe.

Thank you

My environment is:

env independent

I have following devices connected:

I'm connecting to my devices using:

Ethernet/WiFi to RS-485 converter

I'm seeing following log messages:

No response

Code of Conduct

danielkovarik2 commented 3 weeks ago

Update.

Tried to run the failed script couple times and I've got different results:

  1. Already mentioned pyplumio.exceptions.UnknownDeviceError: Unknown sender type (80)
  2. Different unknown sender pyplumio.exceptions.UnknownDeviceError: Unknown sender type (87)
  3. unknown frame type pyplumio.exceptions.UnknownFrameError: Unknown frame type (137)
  4. And actual response Got response (44 bytes): UIDResponse(recipient=<DeviceType.ALL: 0>, sender=<DeviceType.ECOMAX: 69>, econet_type=252, econet_version=50, message=b'\x000\x00\x0b\x00\x03\x00\x18\x111270B20\x00\x02\x00\x0eecoMAX860D3-HB', data={'product': ProductInfo(type=<ProductType.ECOMAX_P: 0>, id=48, uid='8921I88Z3ECHH24C000Z0', logo=48, image=2, model='ecoMAX 860D3-HB')})

These 4 randomly change

denpamusic commented 3 weeks ago

Hi,

Thank you for the feedback and sorry for delayed response.

Despite it's name UnknownDeviceError isn't really an error per se, it's serves more as a warning, that PyPlumIO encountered a frame from the unknown device, that it can't process. It is normally ignored by the AsyncProtocol and logged only on the DEBUG log level here. It doesn't affect operation of frame producer at all, as it simply continues onto next frame, that it hopefully can process.

The script from other issue that you've mentioned is simply too low level and doesn't have a mechanism to cope with it. It's why you only get issues with that script and not diagnostics.py which internally uses AsyncProtocol.

Here I updated it for you:

"""Collect a single frame and dump it on screen."""

import asyncio
import sys

import pyplumio
from pyplumio.const import DeviceType
from pyplumio.frames import requests, responses

# Set host and port here.
HOST = "localhost"
PORT = 8899

async def main() -> int:
    """Collect a single UID frame and dump it on screen.

    We'll use DummyProtocol here, since we'll need direct control over
    connection and access to a raw ecoMAX frame.
    """
    async with pyplumio.open_tcp_connection(
        host=HOST, port=PORT, protocol=pyplumio.DummyProtocol()
    ) as connection:
        print("Requesting UID from the ecoMAX...")
        await connection.writer.write(requests.UIDRequest(recipient=DeviceType.ECOMAX))

        print("Waiting for response...")
        while connection.connected:
            try:
                if isinstance(
                    (response := await connection.reader.read()),
                    responses.UIDResponse,
                ):
                    print(f"Got response ({response.length} bytes): {response}")
                    break
            except pyplumio.ProtocolError:
                # Continue reading next frame in case of protocol errors.
                pass

sys.exit(asyncio.run(main()))

Notice that now we catch pyplumio.ProtocolError and simply continue reading next frame instead of completely failing. Protocol errors to a certain extend can be safely ignored, since sometimes broken or unknown frames do happen in RS485 and should NOT be treated as unrecoverable.

denpamusic commented 3 weeks ago

Hi again,

A couple of more things to note, that I've apparently missed in your issue description, due to being sick. While UnknownDeviceError is probably not an error that is causing you a problem with timeouts, the presence of it can in fact indicate that you're getting malformed frames.

You see, PyPlumIO (PIO) frame reader uses fail-fast approach to error handling. In this approach we check a frames in order from least to most expensive checks. While this allows to fail frame early with least amount of wasted resources, this also makes it a bit harder to debug, since errors such as UnknownDeviceError can mean that PIO encountered frame from the unknown device, but it can also mean that whole frame was malformed. We just didn't bother to check checksum, since checksums are expensive and even if it's correct PIO wouldn't know what to do with frame from the unknown device anyways.

Since you've indicated in your issue description that you've only got ecoMAX connected to the network and nothing else, PIO shouldn't have encountered any unknown devices. So it this case the real issue is probably stems from PIO getting malformed frames from your device, which means there's possibly issue with your HW (converter settings or even RS485 wires not being properly attached). I'd start debugging this issue from hardware standpoint first.