Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[smaenergymeter] Fix handling of broadcast frames #11718

Merged
merged 6 commits into from
May 10, 2024

Conversation

splatch
Copy link
Contributor

@splatch splatch commented Dec 5, 2021

SMA Energy Meter improvements

There are two outstanding issues which are closely related to how UDP traffic is handled by SMA energy meter binding.
This PR addresses both by separating several concerns into their own places, separating network communication from data parsing and port management. Starting point for fix were odd values reported by meter binding in #11497. Additionally it introduces support for handling of multiple meters requested in #3429 which is impossible prior provided fixes.

This work wouldn't be possible without amazing analysis made by Thomas: https://community.openhab.org/t/sma-energy-meter-binding-yields-unplausible-values/128180/4.

@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/sma-energy-meter-binding-yields-unplausible-values/128180/6

Copy link

@monnimeter monnimeter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thank you much!

@splatch
Copy link
Contributor Author

splatch commented Dec 13, 2021

I've updated PR as there are some troubles with amount of changes I introduced. We're clearing issues out in forum topic mentioned earlier.

@splatch splatch changed the title [smaenergymeter] Fix handling of broadcast frames [WIP][smaenergymeter] Fix handling of broadcast frames Dec 13, 2021
@splatch splatch force-pushed the sma-fixes branch 2 times, most recently from 9d0c4d5 to 0ab493c Compare December 13, 2021 10:22
@splatch
Copy link
Contributor Author

splatch commented Apr 29, 2024

@lsiepel None of review checklist mention empty method bodies, sets over lists. Use of primitives over complex types is subjective matter related to nullnes, which in above case when elements are mapped by config mapper, is not wrong. I probably could find dozen of such use cases in existing codebase, yet nobody fight with them.

I'll fix the socket leak if I can. I won't touch nit picks. You decide whether you do for users, continuous improvement or continuous waiting.

@lsiepel
Copy link
Contributor

lsiepel commented Apr 29, 2024

@lsiepel None of review checklist mention empty method bodies, sets over lists. Use of primitives over complex types is subjective matter related to nullnes, which in above case when elements are mapped by config mapper, is not wrong. I probably could find dozen of such use cases in existing codebase, yet nobody fight with them.

I'll fix the socket leak if I can. I won't touch nit picks. You decide whether you do for users, continuous improvement or continuous waiting.

Tried to fix all comments by a uploading a commit to your repository but permissions are lacking. Could you allow me to perform a commit?

Signed-off-by: Leo Siepel <leosiepel@gmail.com>
@lsiepel
Copy link
Contributor

lsiepel commented Apr 29, 2024

I now have triage access, but no write access, could you check again, thanks.

@splatch
Copy link
Contributor Author

splatch commented Apr 29, 2024

@lsiepel done, you should have write access now.

Signed-off-by: Leo Siepel <leosiepel@gmail.com>

Signed-off-by: Leo Siepel <leosiepel@gmail.com>
@lsiepel
Copy link
Contributor

lsiepel commented Apr 29, 2024

If i understood it right, @splatch has some details about a leak and might fix this. I fixed most review comments and have some questions remaining @lolodomo Hopefully we can get this to the finish line. Thanks!

Copy link
Contributor

@lolodomo lolodomo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final comments

Signed-off-by: Leo Siepel <leosiepel@gmail.com>
@lolodomo
Copy link
Contributor

lolodomo commented Apr 30, 2024

Only remains the question about usage of scheduleAtFixedRate.

https://www.openhab.org/docs/developer/guidelines.html#e-runtime-behavior

@lolodomo
Copy link
Contributor

lolodomo commented May 5, 2024

No answer?

Signed-off-by: Leo Siepel <leosiepel@gmail.com>
@lsiepel
Copy link
Contributor

lsiepel commented May 10, 2024

No answer?

Seems not, i changed it to scheduleWithFixedDelay as i'm pretty sure that a little variation in the receiving of packets is not going to harm anything. Please continue with review/merging. So we can put all this behind us.

As the configuration is extended with the poperty serialNumber and when this is not set, the SMAEnergyMeterHandler.java will set the Thing to offline during init. A breaking change.

if (serialNumber == null) {
                updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_PENDING,
                        "Meter serial number missing");
                return;
            }

I'll add a notice to the distro file.

Copy link
Contributor

@lolodomo lolodomo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lolodomo
Copy link
Contributor

i changed it to scheduleWithFixedDelay as i'm pretty sure that a little variation in the receiving of packets is not going to harm anything. Please continue with review/merging. So we can put all this behind us.

Thank you @lsiepel for having considered all comments

@lolodomo lolodomo merged commit 3c0eb94 into openhab:main May 10, 2024
5 checks passed
@lolodomo lolodomo added this to the 4.2 milestone May 10, 2024
@lsiepel lsiepel deleted the sma-fixes branch May 10, 2024 15:26
PRosenb pushed a commit to PRosenb/openhab-addons that referenced this pull request May 22, 2024
* Fix handling of broadcast frames for SMA meter openhab#11497.

Added support for multiple meters in single multicast group openhab#3429.

Signed-off-by: Łukasz Dywicki <luke@code-house.org>
Co-authored-by: Leo Siepel <leosiepel@gmail.com>
PRosenb pushed a commit to PRosenb/openhab-addons that referenced this pull request May 22, 2024
* Fix handling of broadcast frames for SMA meter openhab#11497.

Added support for multiple meters in single multicast group openhab#3429.

Signed-off-by: Łukasz Dywicki <luke@code-house.org>
Co-authored-by: Leo Siepel <leosiepel@gmail.com>
@cambronf
Copy link

The smaenergymeter binding released in 4.2.0M3 shows a huge build up of UDP multicast frames, causing delays of up to half an hour between the real measurment and the reported value in openhab.
This issue has been reported earlier this year:
[https://community.openhab.org/t/sma-energy-meter-binding-yields-unplausible-values/128180/132?u=fcambron]

The broadcast frames fix introduces clearly a new issue, keeping the bindung un-usable.

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                 :::*

@lolodomo
Copy link
Contributor

This will be clearly better to create a new issue. If not, your message could be simply not seen or forgotten in a short time.

psmedley pushed a commit to psmedley/openhab-addons that referenced this pull request Jun 15, 2024
* Fix handling of broadcast frames for SMA meter openhab#11497.

Added support for multiple meters in single multicast group openhab#3429.

Signed-off-by: Łukasz Dywicki <luke@code-house.org>
Co-authored-by: Leo Siepel <leosiepel@gmail.com>
Signed-off-by: Paul Smedley <paul@smedley.id.au>
pgfeller pushed a commit to pgfeller/openhab-addons that referenced this pull request Sep 29, 2024
* Fix handling of broadcast frames for SMA meter openhab#11497.

Added support for multiple meters in single multicast group openhab#3429.

Signed-off-by: Łukasz Dywicki <luke@code-house.org>
Co-authored-by: Leo Siepel <leosiepel@gmail.com>
Signed-off-by: Patrik Gfeller <patrik.gfeller@proton.me>
joni1993 pushed a commit to joni1993/openhab-addons that referenced this pull request Oct 15, 2024
* Fix handling of broadcast frames for SMA meter openhab#11497.

Added support for multiple meters in single multicast group openhab#3429.

Signed-off-by: Łukasz Dywicki <luke@code-house.org>
Co-authored-by: Leo Siepel <leosiepel@gmail.com>
matchews pushed a commit to matchews/openhab-addons that referenced this pull request Oct 18, 2024
* Fix handling of broadcast frames for SMA meter openhab#11497.

Added support for multiple meters in single multicast group openhab#3429.

Signed-off-by: Łukasz Dywicki <luke@code-house.org>
Co-authored-by: Leo Siepel <leosiepel@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior of an add-on (potentially) not backward compatible
Projects
None yet
10 participants