jedie / pysmartmeter

Collect data from Hitchi Smartmeter and expose it via MQTT
GNU General Public License v3.0
7 stars 1 forks source link

Can't read from. Try next serial. #36

Closed vlcty closed 1 year ago

vlcty commented 1 year ago

I get the following error:

[root@alarm pysmartmeter-0.4.1]# ./cli.py dump

+ /root/pysmartmeter-0.4.1/.venv/bin/pysmartmeter dump

pysmartmeter v0.4.1 (No git found for: /root/pysmartmeter-0.4.1)
Detect Serial...
____________________________________________________________________________________________________
try: /dev/ttyUSB0 CP2102 USB to UART Bridge Controller - CP2102 USB to UART Bridge Controller USB VID:PID=10C4:EA60 SER=0020 LOCATION=1-1.1.2
/dev/ttyUSB0 file mode: 0o20660
/dev/ttyUSB0 user ID: 0
/dev/ttyUSB0 user group ID: 986
/dev/ttyUSB0 user group: 'uucp'
Read from Serial<id=0xffffa1673f70, open=True>(port='/dev/ttyUSB0', baudrate=9600, bytesize=7, parity='E', stopbits=1, timeout=1, xonxoff=False, rtscts=False, dsrdtr=False)...
b'\x01\x1b\x1b\x1b\x1b\x01\x01\x01\x01v\x07\x00\t\x00\x05\x1a\x06b\x00b\x00rc\x01\x01v\x01\x01\x07\x00\t\x00\x013\x02\x0b\t\x01EMH\x00\x000\rP\x01\x01cnK\x00v\x07\x00\t\x00\x05\x1a\x07b\x00b\x00rc\x07\x01w\x01\x0b\
t\x01EMH\x00\x000\rP\x07\x01\x00b\n'
b"\x7f\x7frb\x01e\x00\x01\x1bDyw\x07\x01\x01G\x02\x03\x7f\x01\x01\x01\x01\x04EMH\x01w\x07\x01\x00\x00\x00\t\x7f\x01\x01\x01\x01\x0b\t\x01EMH\x00\x000\rP\x01w\x07\x01\x00\x01\x08\x00\x7fd\x01\x01\x02\x01b\x1eR\x03V\
x00\x00\x00\x00\x1b\x01w\x07\x01\x00\x02\x08\x00\x7fd\x01\x01\x02\x01b\x1eR\x03V\x00\x00\x00\x00\x00\x01w\x07\x01\x00\x01\x08\x01\x7f\x01\x01b\x1eR\x03V\x00\x00\x00\x00\x1b\x01w\x07\x01\x00\x02\x08\x01\x7f\x01\x01b
\x1eR\x03V\x00\x00\x00\x00\x00\x01w\x07\x01\x00\x01\x08\x02\x7f\x01\x01b\x1eR\x03V\x00\x00\x00\x00\x00\x01w\x07\x01\x00\x02\x08\x02\x7f\x01\x01b\x1eR\x03V\x00\x00\x00\x00\x00\x01w\x07\x01\x01G\x02\x05\x7f\x01\x01\x
01\x01\x03\x02;\x079U'5\x00?\x1b#Sk\x10\x15n9\\\x16U\x111\x19Ym\x15\x11M|<oN\x01tt&4\x1c9 HCln,D\x0bhx\x01\x01\x01c\x1a{\x00v\x07\x00\t\x00\x05\x1a\x08b\x00b\x00rc\x02\x01q\x01c\t'\x00\x1b\x1b\x1b\x1b\x1a\x00C\x0c"
b'\x1b\x1b\x1b\x1b\x01\x01\x01\x01v\x07\x00\t\x00\x05\x1a\x0cb\x00b\x00rc\x01\x01v\x01\x01\x07\x00\t\x00\x013\x04\x0b\t\x01EMH\x00\x000\rP\x01\x01cd\x08\x00v\x07\x00\t\x00\x05\x1a\rb\x00b\x00rc\x07\x01w\x01\x0b\t\x
01EMH\x00\x000\rP\x07\x01\x00b\n'
b"\x7f\x7frb\x01e\x00\x01\x1bFyw\x07\x01\x01G\x02\x03\x7f\x01\x01\x01\x01\x04EMH\x01w\x07\x01\x00\x00\x00\t\x7f\x01\x01\x01\x01\x0b\t\x01EMH\x00\x000\rP\x01w\x07\x01\x00\x01\x08\x00\x7fd\x01\x01\x02\x01b\x1eR\x03V\
x00\x00\x00\x00\x1b\x01w\x07\x01\x00\x02\x08\x00\x7fd\x01\x01\x02\x01b\x1eR\x03V\x00\x00\x00\x00\x00\x01w\x07\x01\x00\x01\x08\x01\x7f\x01\x01b\x1eR\x03V\x00\x00\x00\x00\x1b\x01w\x07\x01\x00\x02\x08\x01\x7f\x01\x01b
\x1eR\x03V\x00\x00\x00\x00\x00\x01w\x07\x01\x00\x01\x08\x02\x7f\x01\x01b\x1eR\x03V\x00\x00\x00\x00\x00\x01w\x07\x01\x00\x02\x08\x02\x7f\x01\x01b\x1eR\x03V\x00\x00\x00\x00\x00\x01w\x07\x01\x01G\x02\x05\x7f\x01\x01\x
01\x01\x03\x02;\x079U'5\x00?\x1b#Sk\x10\x15n9\\\x16U\x111\x19Ym\x15\x11M|<oN\x01tt&4\x1c9 HCln,D\x0bhx\x01\x01\x01c\x10)\x00v\x07\x00\t\x00\x05\x1a\x0eb\x00b\x00rc\x02\x01q\x01c~R\x00\x1b\x1b\x1b\x1b\x1a\x000\x07"
b'\x1b\x1b\x1b\x1b\x01\x01\x01\x01v\x07\x00\t\x00\x05\x1a\x12b\x00b\x00rc\x01\x01v\x01\x01\x07\x00\t\x00\x013\x06\x0b\t\x01EMH\x00\x000\rP\x01\x01c\x19#\x00v\x07\x00\t\x00\x05\x1a\x13b\x00b\x00rc\x07\x01w\x01\x0b\t
\x01EMH\x00\x000\rP\x07\x01\x00b\n'
Can't read from. Try next serial.
Serial not found

Apparently it can read something from the Hichi but can't process it? Running on a Raspi 3 with Archlinux ARM. Power meter is from EMH and it apparently sends a "reduced dataset". Maybe this causes the problem?

jedie commented 1 year ago

Hm. Strange output...

The "detect" code looks simplified:

for try_count in range(5):
    data = ser.readline()
    if data.endswith(b'\r\n'):
        # found!

It's here: https://github.com/jedie/pysmartmeter/blob/a896dff446de7889e9294252321215efd2f393af/pysmartmeter/detect_serial.py#L58-L76

Think your Hichi is not configured correctly?!? Seems that this is a kind of binary data? Normally it should look like this:

image

You can try to ask here: https://www.photovoltaikforum.com/thread/145886-habe-lesk%C3%B6pfe-mit-usb-%C3%BCber/

vlcty commented 1 year ago

I did not know that you can configure the hichi. I'm going to check that. But thanks for the sample how it should look like. It seems that my meter sends binary data.

vlcty commented 1 year ago

If anybody comes across the same issue: I've an EMH eHZ-KW8E2A5L0EQ2P meter and a Hichi USB Version.

When I check the raw serial output with minicom -D /dev/ttyUSB0 -b 9600 -H it can see the raw SML Message beginning with 1b 1b 1b 1b which is the start sequence. So it's in fact binary representation. I'll try to come up with a patch for this software to detect it. Maybe it just needs a binary to ASCII converson before futher processing.

jedie commented 1 year ago

@dmaj started to implement raw SML Message parsing here: https://github.com/jedie/pysmartmeter/pull/31 But this implementation needed much work before i can merge this.

The Question is: How to switch the Hichi from binary to ASCII mode? Maybe it's possible to do this via Serial?

r-hof commented 1 year ago

I don't think the USB or TTL versions of the Hichi adapter contain any logic that can be "switched" in any way. Meters send either OBIS protocol (readable text) or SML protocol (binary data), and pysmartmeter can only handle OBIS protocol.

The WIFI version of the Hichi has an ESP01s with Tasmota built in, which does the decoding for you.

jedie commented 1 year ago

Ah! Thanks for the explanation.

I add a info in readme in https://github.com/jedie/pysmartmeter/commit/8d3941997ded57bab1b4cc8556e1fa6cc2269838 and create a TODO ticket here: https://github.com/jedie/pysmartmeter/issues/37

Looking at https://wiki.volkszaehler.org/software/sml it doesn't look too difficult ;) Maybe a nice topic for a weekend sprint ;) And a implementation exists with https://pypi.org/project/pysml