openhab / openhab-addons

Add-ons for openHAB
https://www.openhab.org/
Eclipse Public License 2.0
1.86k stars 3.56k forks source link

[smaenergymeter] Multicast packet delayed readings #16789

Open cambronf opened 1 month ago

cambronf commented 1 month ago

Expected Behavior

immediate reading of multicast packets

Current Behavior

Delay of up to 30 minutes between received multicast packet and openhab item update. Big queue at input buffer, introduced by the fix done for broadcast frames #11718 in openhab 4.2.0M3

openhabian@openhabian:~ $ netstat -nau
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
udp6  165888      0 :::9522                 :::*
udp6  165888      0 :::9522                 :::*
udp6  156672      0 :::9522                 :::*
udp6  172032      0 :::9522                 :::*
udp6  165888      0 :::9522                 :::*
udp6  159744      0 :::9522                 :::*
udp6  153600      0 :::9522                 :::*
udp6  181248      0 :::9522                 :::*

Possible Solution

As all SMA meters send data to the same multicast group, and the multicast group is open all the time, the input buffer fills up with a lot of data. SMA meters send packets every second. The binding itself only read 1 packet every 30 second (default value). The buffer is FIFO. Delays go up to 20-30 mins. Proposed fix: move socket.JoinGroup(address) and socket.LeaveGroup() to ReceivingTask run.

Your Environment

see [https://community.openhab.org/t/sma-energy-meter-binding-yields-unplausible-values/128180/132]https://community.openhab.org/t/sma-energy-meter-binding-yields-unplausible-values/128180/132 and further for more details

splatch commented 1 month ago

I’ll have a look on it, we can solve it by just consuming queue contents but publishing at user specified interval, or as you suggested rejoin multicast group for each poll to avoid queue build up. Both solutions have some overhead.

splatch commented 4 weeks ago

@cambronf I had a look on the code, but before doing any changes - can you confirm if changing pollingPeriod to 1 helps? This setting should trigger multicast receiver every second and reduce delay.

As far I remember energy meter publish packet every 100 ms, so you still going to experience issue, but with smaller delay at the beginning.

cambronf commented 3 weeks ago

Hi I tried with 1 seconds, but the big delay and queue remains.

According to me, every SMA energymeter/homemanager send a multicast dataframe every 1s, as set in the Meter Configuration. As I have 3 meters in the network, all sending packets to the same multicast address/port, there is still a queue with pollingPerod = 1s (overload of factor 3). See also my earlier evaluation in pdf available at https://github.com/cambronf/openhab

image

splatch commented 3 weeks ago

@cambronf Please give a shoot to PR linked above - it did change internal polling interval to 1s and deferred the throttling to caller who registers packet handler. Still, if you have 3 devices, each publishing each second, we should fire receive three times/sec to avoid issue or join/leave group at each poll.

splatch commented 1 hour ago

This issue can be closed - PR with fixes been merged few days ago, it will be included in 4.2.0 release.