envy / esp-knx-ip

A KNX/IP library for the ESP8266 with Arduino
MIT License
139 stars 50 forks source link

KNX Communication - uncalled UDP response #68

Open HomeAsASystem opened 5 years ago

HomeAsASystem commented 5 years ago

Have you ever experienced this issue ?

https://github.com/arendst/Sonoff-Tasmota/issues/5053

I've got the same behaviour not only with Tasmota but also with the esp-knx-ip/sonoff example

envy commented 5 years ago

Hi,

no I haven't. What I gather from your bug report is this:

  1. You boot the ESP device.
  2. Some communication happens on the KNX Multicast IP
  3. The ESP responds with packets of length 0. This only happens if the ESP has not sent own KNX packets before.

Is this correct? I have to investigate this, but unfortunately I don't have access to my lab this week, so maybe next week at the earliest.

HomeAsASystem commented 5 years ago

Hi, My description was not very clear. After booting up the device it responds to every KNX multicast telegram which is send from any device to the KNX multicast address 224.0.23.12:3671. As long as the device has not sent any KNX/IP message the response is targeted to 0.0.0.0:0, but once the device has sent a KNX/IP message, the UDP response is send to the KNX multicast address 224.0.23.12:3671. So in summary, the device always responds to the multicast telegram, but the destination address of the response changes, once the device has sent an own KNX/IP telegram. I believe the root cause is somewhere in the TCP/IP or IGMP implementation of the ESP8266 stack or in a wrong configuration of the IGMP function. I removed the igmp_joingroup statement in the WifiUdp Class, then the device does not respond anymore to the multicast telegrams, but it also does not react anymore on the KNX/IP telegrams send to the device.

d-a-v commented 5 years ago

As long as the device has not sent any KNX/IP message the response is targeted to 0.0.0.0:0, but once the device has sent a KNX/IP message, the UDP response is send to the KNX multicast address 224.0.23.12:3671.

This is still a bit unclear,

(I am maintainer in the esp8266 arduino core, especially the lwIP adaptation layer)

HomeAsASystem commented 5 years ago

Sorry for being not precise enough. Please see below a wireshark trace of the issue.

image

I restartet the ESP Device before line 4041. Line4041: The KNX-IP Gateway sends a KNXnetIP message to the KNX multicast address. Line4045: The ESP device@192.168.1.40 responds with an UDP message to the destination IP 0.0.0.0. Line4054,4055,4060,4061,4072,4073: same behaviour Line 4083-4086: The ESP device@192.168.1.40 sends its KNXnetIP telegrams to the KNX multicast address. Line 4093: The KNX-IP Gateway sends a KNXnetIP telegram to the KNx multicast address Line 4094: The ESS Device@192.168.1.40 is the responding not anymore to 0.0.0.0 but to the KNX multicast address 224.0.23.12.

This leads to warnings in my OpenHAB server, as it detects invalid messages send to the KNX mutlicast address. image

hope this helps to understand the issue br

envy commented 5 years ago

Are the messages sent by your gateway destined for the ESP (e.g., reads or writes to the ESP)? Or are they destined for some other KNX device?

If it's the first, that means, the ESP is answering to the wrong address. If it's the second, then the ESP is answering to messages, it's not supposed to answer to.

HomeAsASystem commented 5 years ago

the messages of the IP gateway have no specific target, as it is the nature of the KNXnetIP protocol that all communication is send to the KNX multicast group address. Also the ESP device sends all its KNX messages to the KNX multicast address. I've also testet it in a setup where i had only two ESP devices with KNX protocol in a private WIFI. Even there on ESP device responded to the KNX messages of the other ESP device with an UDP response. It seems like there is an acknowledge implemented if an ESP device joins a multicast group. But as far as i understand this is not the purpose of UDP multicast

envy commented 5 years ago

the messages of the IP gateway have no specific target, as it is the nature of the KNXnetIP protocol that all communication is send to the KNX multicast group address. Also the ESP device sends all its KNX messages to the KNX multicast address.

I meant, if your gateway is sending a KNX group read/write to a group address that the ESP is configured to react upon, i.e. you send group write to 1/2/3 and the ESP toggles a lamp and then send back a status to 4/5/6. I want to know if this answer message is instead send to 0.0.0.0.

Or if your KNX message is sent to a group address that is not configured on the ESP and the ESP is answering anyway even though it should not do that.

HomeAsASystem commented 5 years ago

the Gateway is sending all sort of GA's as my openHAB server reads all the KNX GA's on the KNX TP installation. The ESP device responds to all messages of the IP Gateway. No matter if the GA's are addressed to the ESP device or not. The 192.168.1.40 device even has no receiving GA's configured as there is only a BME680 sensor connected to.

envy commented 5 years ago

Ok, so it is sending packets, even though it should not. I have to investigate if this is a bug on my side or one inside the ESP framework (or lwip). But if the responding stops when the ESP sent a message on its own, then it sounds more like a bug inside the ESP framework (or lwip).

Did you try the different lwip versions available?

HomeAsASystem commented 5 years ago

Another missunderstanding. When the ESP sent a message on its own, it still continues to respond to any incoming KNXnetIP multicast telegram. It only changes the destination IP of its reponse from 0.0.0.0 to 224.0.23.12. The message is even an invalid UDP message and does not contain any usefull information. The ESP device is not supposed at all to respond to the KNXnetIP telegrams from the IP-KNX gateway. I haven't used any different lwip version. I tried it with ESP platform 2.4.2 as well as 2.5.0

HomeAsASystem commented 5 years ago

I also think it is related to the esp framework. I've disabled any sending and receiving within your knx code. As soon as the esp device joins an igmp group this behaviour turns up

roelbroersma commented 5 years ago

I am seeing the same behavior.

The ESP just always answers with an UDP 0 (zero) to the 0.0.0.0 IP address. Very strange...

I never seen this before and I have seen a lot of KNX routers like Gira (all variants), MDT,..and more.

Even when this esp-knx-ip Library is only loaded and Nothing is configured.. the ESP just starts to 'answer' all Multicast calls with the UDP 0 message.

ascillato commented 5 years ago

Please, try latest arduino core from arduino. The STAGE version that will became soon the 2.6.0 has solved several bugs. I use it and I couldn't reproduce your issue.