home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.89k stars 30.12k forks source link

Invalid message error when connecting #99648

Closed meierthomas closed 1 year ago

meierthomas commented 1 year ago

The problem

I'm implementing an external interface for my Elk M1 setup. I have a USB to serial adapter to connect to my Elk M1 panel and connected to the USB port of a Pine A64 running ser2net.

I have the following configuration.yaml

elkm1:
  - host: elk://192.168.2.102:3001
    # Elk doesn't know which areas/zones/etc are unused, so it can generate
    # many unwanted Home Assistant Entities. Be liberal in excluding them:
    area:
      exclude: [2-8]
    zone:
      exclude: [9-208]
    plc:
      enabled: false
    task:
      enabled: false
    counter:
      exclude: [1-64]
    keypad:
      exclude: [2-16]
    setting:
      enabled: true
      exclude: [1-20]
    output:
      exclude: [1-8,10-208]
    thermostat:
      enabled: false

192.168.2.102 is the Pine A64 running ser2net

ser2net seems to be running fine

root@DietPi:~# systemctl status ser2net
● ser2net.service - Serial port to network proxy
     Loaded: loaded (/lib/systemd/system/ser2net.service; enabled; preset: enabled)
     Active: active (running) since Tue 2023-09-05 10:28:03 AEST; 9min ago
       Docs: man:ser2net(8)
   Main PID: 1314 (ser2net)
      Tasks: 1 (limit: 2218)
     Memory: 732.0K
        CPU: 334ms
     CGroup: /system.slice/ser2net.service
             └─1314 /usr/sbin/ser2net -n -c /etc/ser2net.yaml -P /run/ser2net.pid

Sep 05 10:28:03 DietPi systemd[1]: Starting ser2net.service - Serial port to network proxy...
Sep 05 10:28:03 DietPi systemd[1]: Started ser2net.service - Serial port to network proxy.

using the following config

%YAML 1.1
---
# This is a ser2net configuration file, tailored to be rather
# simple.
#
# Find detailed documentation in ser2net.yaml(5)
# A fully featured configuration file is in
# /usr/share/doc/ser2net/examples/ser2net.yaml.gz
#
# If you find your configuration more useful than this very simple
# one, please submit it as a bugreport

define: &banner \r\nser2net port \p device \d [\B] (Pine A64)\r\n\r\n

admin:
  accepter: tcp,8000

connection: &elkm1
    accepter: tcp,3001
    enable: on
    options:
      banner: *banner
      kickolduser: true
      telnet-brk-on-sync: true
    connector: serialdev,
              /dev/ttyUSB0,
              115200n81,NONE,1STOPBIT,local

When starting Home Assistant I get data on port 3001 as follows

root@DietPi:~# tcpdump -i any port 3001
tcpdump: data link type LINUX_SLL2
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on any, link-type LINUX_SLL2 (Linux cooked v2), snapshot length 262144 bytes
10:28:50.073967 eth0  In  IP 192.168.2.99.34376 > 192.168.2.102.3001: Flags [F.], seq 4184340940, ack 1625144536, win 501, options [nop,nop,TS val 1742170578 ecr 973909946], length 0
10:28:50.074053 eth0  Out IP 192.168.2.102.3001 > 192.168.2.99.34376: Flags [.], ack 1, win 509, options [nop,nop,TS val 973960739 ecr 1742170578], length 0
10:30:07.710848 eth0  In  IP 192.168.2.99.38036 > 192.168.2.102.3001: Flags [S], seq 2651684834, win 64240, options [mss 1460,sackOK,TS val 1742248218 ecr 0,nop,wscale 7], length 0
10:30:07.710935 eth0  Out IP 192.168.2.102.3001 > 192.168.2.99.38036: Flags [S.], seq 2773053630, ack 2651684835, win 65160, options [mss 1460,sackOK,TS val 974038376 ecr 1742248218,nop,wscale 7], length 0
10:30:07.711304 eth0  In  IP 192.168.2.99.38036 > 192.168.2.102.3001: Flags [.], ack 1, win 502, options [nop,nop,TS val 1742248218 ecr 974038376], length 0
10:30:07.712338 eth0  In  IP 192.168.2.99.38036 > 192.168.2.102.3001: Flags [P.], seq 1:11, ack 1, win 502, options [nop,nop,TS val 1742248219 ecr 974038376], length 10
10:30:07.712410 eth0  Out IP 192.168.2.102.3001 > 192.168.2.99.38036: Flags [.], ack 11, win 509, options [nop,nop,TS val 974038378 ecr 1742248219], length 0
10:30:07.741877 eth0  Out IP 192.168.2.102.3001 > 192.168.2.99.38036: Flags [P.], seq 1:121, ack 11, win 509, options [nop,nop,TS val 974038407 ecr 1742248219], length 120
10:30:07.742273 eth0  In  IP 192.168.2.99.38036 > 192.168.2.102.3001: Flags [.], ack 121, win 502, options [nop,nop,TS val 1742248249 ecr 974038407], length 0
10:30:07.753532 eth0  Out IP 192.168.2.102.3001 > 192.168.2.99.38036: Flags [P.], seq 121:179, ack 11, win 509, options [nop,nop,TS val 974038419 ecr 1742248249], length 58
10:30:07.754377 eth0  In  IP 192.168.2.99.38036 > 192.168.2.102.3001: Flags [.], ack 179, win 502, options [nop,nop,TS val 1742248261 ecr 974038419], length 0
10:30:07.754625 eth0  In  IP 192.168.2.99.38036 > 192.168.2.102.3001: Flags [P.], seq 11:21, ack 179, win 502, options [nop,nop,TS val 1742248262 ecr 974038419], length 10
10:30:07.763470 eth0  Out IP 192.168.2.102.3001 > 192.168.2.99.38036: Flags [P.], seq 179:243, ack 21, win 509, options [nop,nop,TS val 974038429 ecr 1742248262], length 64
10:30:07.804469 eth0  In  IP 192.168.2.99.38036 > 192.168.2.102.3001: Flags [.], ack 243, win 502, options [nop,nop,TS val 1742248312 ecr 974038429], length 0
10:30:07.804501 eth0  Out IP 192.168.2.102.3001 > 192.168.2.99.38036: Flags [P.], seq 243:285, ack 21, win 509, options [nop,nop,TS val 974038470 ecr 1742248312], length 42
10:30:07.804698 eth0  In  IP 192.168.2.99.38036 > 192.168.2.102.3001: Flags [.], ack 285, win 502, options [nop,nop,TS val 1742248312 ecr 974038470], length 0
10:30:07.805469 eth0  In  IP 192.168.2.99.38036 > 192.168.2.102.3001: Flags [P.], seq 21:31, ack 285, win 502, options [nop,nop,TS val 1742248313 ecr 974038470], length 10
10:30:07.816521 eth0  Out IP 192.168.2.102.3001 > 192.168.2.99.38036: Flags [P.], seq 285:329, ack 31, win 509, options [nop,nop,TS val 974038482 ecr 1742248313], length 44
10:30:07.817283 eth0  In  IP 192.168.2.99.38036 > 192.168.2.102.3001: Flags [P.], seq 31:41, ack 329, win 502, options [nop,nop,TS val 1742248324 ecr 974038482], length 10

but when I check the Home Assistant log I get the following error. It complains at the banner defined in ser2net

2023-09-05 10:30:07.834 ERROR (MainThread) [elkm1_lib.connection] Invalid message 'b'\r\nser2net port tcp,3001 device serialdev, /dev/ttyUSB0, 115200n81,NONE,1STOPBIT,local [,115200N81,CLOCAL] (Pine A64)\r\n\r\n''
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/elkm1_lib/connection.py", line 103, in _read_stream
    decoded = decode(line)
              ^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/elkm1_lib/message.py", line 71, in decode
    raise ValueError(error_msg)
ValueError: Message invalid

I have checked various forums re the ser2net configuration but the banner definition is always the same so I wonder why Home Assistant rejects this...

What version of Home Assistant Core has the issue?

core-2023.8.2

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Elk M1

Link to integration documentation on our website

https://www.home-assistant.io/integrations/elkm1

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 1 year ago

Hey there @gwww, @bdraco, mind taking a look at this issue as it has been labeled with an integration (elkm1) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `elkm1` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign elkm1` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


elkm1 documentation elkm1 source (message by IssueLinks)

gwww commented 1 year ago

This integration does not explicitly support ser2net. The banner message is not an expected message by the integration. If I could suggest trying turning off the banner, it would get rid of the error you are seeing. I'm not sure that there won't be other problems though.

gwww commented 1 year ago

@home-assistant close