XKNX / xknx

XKNX - A KNX library written in Python
http://xknx.io/
MIT License
289 stars 105 forks source link

CouldNotParseKNXIP "wrong HPAI length" with HassIO #76

Closed ronniegarcia closed 5 years ago

ronniegarcia commented 6 years ago

Hey, I'm using Home Assistant 0.56.2 within HassIO on a Raspberry Pi 3 I have a Siemens 5WG1 148-1AB22 KNX/IP ethernet gateway (AKA N148/22) I can successfully connect to my KNX bus with eibd-server and linknx on a separate Linux Voyage system.

Unfortunately I can't connect to my KNX bus with Home Assistant, as it raises this exception at startup :

2017-11-04 15:00:01 INFO (MainThread) [homeassistant.setup] Setting up knx
2017-11-04 15:00:01 DEBUG (MainThread) [xknx.log] Starting tunnel to 10.100.4.96:3671 from 10.100.4.99
2017-11-04 15:00:01 DEBUG (MainThread) [xknx.knx] Sending: <KNXIPFrame <KNXIPHeader HeaderLength="6" ProtocolVersion="16" KNXIPServiceType="KNXIPServiceType.CONNECT_REQUEST" Reserve="0" TotalLength="26" />
 body="<ConnectRequest control_endpoint="<HPAI 10.100.4.99:54510 />" data_endpoint="<HPAI 10.100.4.99:54510 />" request_type="ConnectRequestType.TUNNEL_CONNECTION" />" />
2017-11-04 15:00:01 ERROR (MainThread) [xknx.log] <CouldNotParseKNXIP description="wrong HPAI length" />
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/xknx/io/udp_client.py", line 85, in data_received_callback
    knxipframe.from_knx(raw)
  File "/usr/lib/python3.6/site-packages/xknx/knxip/knxip.py", line 77, in from_knx
    pos += self.body.from_knx(data[pos:])
  File "/usr/lib/python3.6/site-packages/xknx/knxip/connect_response.py", line 54, in from_knx
    pos += self.control_endpoint.from_knx(raw[pos:])
  File "/usr/lib/python3.6/site-packages/xknx/knxip/hpai.py", line 23, in from_knx
    raise CouldNotParseKNXIP("wrong HPAI length")
xknx.exceptions.exception.CouldNotParseKNXIP: <CouldNotParseKNXIP description="wrong HPAI length" />
2017-11-04 15:00:02 ERROR (MainThread) [homeassistant.components.knx] Can't connect to KNX interface: Could not establish connection
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/homeassistant/components/knx.py", line 80, in async_setup
    yield from hass.data[DATA_KNX].start()
  File "/usr/lib/python3.6/site-packages/homeassistant/components/knx.py", line 140, in start
    connection_config=connection_config)
  File "/usr/lib/python3.6/site-packages/xknx/xknx.py", line 66, in start
    yield from self.knxip_interface.start()
  File "/usr/lib/python3.6/site-packages/xknx/io/knxip_interface.py", line 76, in start
    self.connection_config.gateway_port)
  File "/usr/lib/python3.6/site-packages/xknx/io/knxip_interface.py", line 106, in start_tunnelling
    yield from self.interface.start()
  File "/usr/lib/python3.6/site-packages/xknx/io/tunnel.py", line 74, in start
    yield from self.connect()
  File "/usr/lib/python3.6/site-packages/xknx/io/tunnel.py", line 89, in connect
    raise XKNXException("Could not establish connection")
xknx.exceptions.exception.XKNXException: Could not establish connection
2017-11-04 15:00:02 INFO (MainThread) [homeassistant.setup] Setup of domain knx took 1.2 seconds.
2017-11-04 15:00:02 ERROR (MainThread) [homeassistant.setup] Setup failed for knx: Component failed to initialize.

Here is my config :

knx:
  tunneling:
    host: '10.100.4.96'
    port: 3671
    local_ip: '10.100.4.99'

10.100.4.96 is my Siemens KNX/IP ethernet gateway 10.100.4.99 is my HassIO However, I understand that HassIO uses Docker and I have the following from the HassIO ssh shell :

core-ssh:/config# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 02:42:AC:1E:21:00  
          inet addr:172.30.33.0  Bcast:0.0.0.0  Mask:255.255.254.0

And :

core-ssh:/config# arp
hassio (172.30.32.2) at 02:42:ac:1e:20:02 [ether]  on eth0
homeassistant (172.30.32.1) at 02:42:04:f5:dc:22 [ether]  on eth0

Is it something with NAT that prevents me from connecting to the gateway ? Thanks

Julius2342 commented 6 years ago

are you able to record the full binary packet with tcpdump?

Julius2342 commented 6 years ago

alternatively you could add print(raw) to data_received_callback within /usr/lib/python3.6/site-packages/xknx/io/udp_client.py (e.g. line 85, just before knxipframe.from_knx(raw) )

ronniegarcia commented 6 years ago

Hi Julius, Thanks to your suggestion, I figured out with Wireshark that my KNX gateway replies with :

E_NO_MORE_CONNECTIONS - The KNXnet/IP server device could not accept the new data connection (busy) (0x24)

When I kill eibd-server on the other system (I thought it was), Home Assistant can connect successfully.

I think it would be helpful to trap this specific error code and log the appropriate message. Unfortunately I can't help you with the code, but I can make any test you would need. I attached the capture with the E_NO_MORE_CONNECTIONS

Thanks ! Ronnie

knxnet_e_no_more_connections.pcap.zip

dzungpv commented 6 years ago

@ronniegarcia This is old but recently i try to add Siemens 5WG1 151 to home assistant but it not work. You can share now your device work with latest hass? I post thread here https://community.home-assistant.io/t/help-with-knx-cant-connect-to-knx-interface-could-not-establish-connection/54920