Skip to content

Refactor openwb mqtt#3467

Merged
sfeilmeier merged 14 commits intoOpenEMS:developfrom
Sn0w3y:refactor-openwb-mqtt
Dec 13, 2025
Merged

Refactor openwb mqtt#3467
sfeilmeier merged 14 commits intoOpenEMS:developfrom
Sn0w3y:refactor-openwb-mqtt

Conversation

@Sn0w3y
Copy link
Copy Markdown
Collaborator

@Sn0w3y Sn0w3y commented Dec 6, 2025

No description provided.

Sn0w3y and others added 13 commits December 1, 2025 00:13
This update significantly refactors the OpenWB EVCS integration for improved reliability and maintainability. Changes include the removal of the ReadWorker class in favor of using the BridgeHttpFactory and HttpBridgeCycleServiceDefinition for handling HTTP requests to the OpenWB API. This approach simplifies the codebase by leveraging existing infrastructure for HTTP communications, thereby reducing custom network handling code. Additionally, SSL certificate validation for OpenWB's self-signed certificates is now globally disabled within this component to prevent connection issues. The update also introduces more granular handling of OpenWB's API responses for statuses, power, energy, and other metrics, improving the accuracy and responsiveness of the EVCS component. This refactor ensures better alignment with OpenEMS architecture and prepares the ground for future enhancements.
This update transitions the OpenWB EVCS integration from using HTTP API calls to MQTT for communication. The change involves modifying the configuration to use MQTT URI, username, and password instead of IP address and port. It also includes updates to the implementation to subscribe to MQTT topics for receiving data such as power, voltage, and state changes, and to publish commands. This migration improves the reliability and efficiency of the communication with OpenWB devices by leveraging the lightweight MQTT protocol, which is better suited for real-time data exchange in IoT applications.
Introduces the 'io.openems.edge.bridge.mqtt' module, providing MQTT communication support for OpenEMS Edge with MQTT 3.1, 3.1.1, and 5.0 via HiveMQ client. Adds configuration, connection handlers, API interfaces, and subscription management. Updates build and application files to include the new bridge and its dependencies.
This commit replaces the HiveMQ client with the Eclipse Paho client for both MQTT 3.x and MQTT 5.0 connection handlers in the MQTT bridge component. The change includes adapting the connection, publishing, subscription, and disconnection logic to utilize the Eclipse Paho API. This upgrade addresses compatibility issues with the previous client and improves the stability and flexibility of MQTT communications. The implementation now supports detailed configuration options provided by Eclipse Paho, such as automatic reconnection handling, advanced authentication mechanisms, and Last Will and Testament (LWT) features. Additionally, the commit introduces a custom reconnection strategy and enhances the handling of MQTT message subscriptions and deliveries, ensuring more robust and reliable MQTT service integration.
This commit updates the MQTT dependencies for the io.openems.edge.bridge.mqtt module. Specifically, it adds bcpkix and bcprov with version 1.78.1 to the buildpath, and replaces the com.hivemq:hivemq-mqtt-client-shaded and io.reactivex.rxjava2.rxjava dependencies with io.openems.wrapper.paho-mqttv5, org.eclipse.paho.client.mqttv3, and org.eclipse.paho.mqttv5.client, all versioned at 1.2. This change aims to standardize MQTT client usage across the project and ensure compatibility with the latest MQTT protocol versions.
This commit introduces unit tests for MQTT connection handlers across different MQTT protocol versions (3.1, 3.1.1, and 5). It includes tests for constructor behavior, connection status checks, publish/subscribe/unsubscribe operations when not connected, and topic matching with various wildcard scenarios. The tests ensure that the connection handlers behave as expected across different scenarios, including handling SSL connections, and correctly interpreting MQTT quality of service (QoS) levels. This comprehensive test suite aims to improve the reliability and robustness of the MQTT bridge by validating its core functionalities.
This commit overhauls the MQTT integration for the OpenWB Electric Vehicle Charging Station (EVCS) component, transitioning from a direct MQTT client implementation to utilizing the centralized MQTT bridge. The changes include removing direct MQTT connection handling in favor of subscribing to topics through the MQTT bridge, adapting the configuration to specify the MQTT bridge ID instead of individual MQTT connection parameters, and updating the handling of MQTT messages to work with the bridge's mechanisms. Additionally, the test cases were updated to mock the MQTT bridge and simulate message reception, ensuring the component correctly processes incoming data. This refactor improves maintainability by centralizing MQTT management and enhances testability through better simulation capabilities.
Deleted the MQTT Bridge implementation, including all related classes, interfaces, and unit tests. This change could be due to a refactoring decision to either move the MQTT functionality to a different module or to redesign the MQTT communication strategy within the system. Removing these files indicates a significant change in how MQTT communication is handled within the project.
This commit removes unused dependencies from the project to streamline the build process and reduce potential conflicts. Specifically, the 'com.hivemq:hivemq-mqtt-client-shaded' dependency was removed from cnf/pom.xml, and a duplicate entry for 'org.eclipse.paho.client.mqttv3' was removed from io.openems.edge.application/EdgeApp.bndrun.
@codecov
Copy link
Copy Markdown

codecov bot commented Dec 6, 2025

Codecov Report

❌ Patch coverage is 64.10256% with 42 lines in your changes missing coverage. Please review.

❌ Your patch status has failed because the patch coverage (64.11%) is below the target coverage (75.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@              Coverage Diff              @@
##             develop    #3467      +/-   ##
=============================================
+ Coverage      59.43%   59.46%   +0.04%     
  Complexity       112      112              
=============================================
  Files           2912     2912              
  Lines         125401   125436      +35     
  Branches        9394     9394              
=============================================
+ Hits           74516    74583      +67     
+ Misses         48054    48002      -52     
- Partials        2831     2851      +20     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@da-Kai da-Kai requested a review from sfeilmeier December 12, 2025 06:57
@sfeilmeier
Copy link
Copy Markdown
Contributor

@Sn0w3y: In principle I am very positive about this change. Have you been able to test this in production?

@sthhs FYI

@Sn0w3y
Copy link
Copy Markdown
Collaborator Author

Sn0w3y commented Dec 12, 2025

@sfeilmeier Unfortunately I only implemented it based on the Documentation of OpenWB - maybe @sjjh could help us out and test ? :)

@sthhs
Copy link
Copy Markdown
Contributor

sthhs commented Dec 12, 2025

@Sn0w3y
This implementation would break my OpenWB component. Is this intended?

It works with my OpenWB. The only thing I've found is that energyStartSession is not initialized if the component is activated while the box is charging.

@Sn0w3y
Copy link
Copy Markdown
Collaborator Author

Sn0w3y commented Dec 12, 2025

This implementation would break my OpenWB component. Is this intended?

It will not actually break your Implementation but "improve" it to use MQTT instead of HTTP Requests.
Please set up a MQTT Bridge and configure it - then test :)

Would be great to have your Feedback afterwards!

@sthhs
Copy link
Copy Markdown
Contributor

sthhs commented Dec 12, 2025

This implementation would break my OpenWB component. Is this intended?

It will not actually break your Implementation but "improve" it to use MQTT instead of HTTP Requests. Please set up a MQTT Bridge and configure it - then test :)

Would be great to have your Feedback afterwards!

Already tested:

It works with my OpenWB. The only thing I've found is that energyStartSession is not initialized if the component is activated while the box is charging.

Initialize energyStartSession when charging has already been started.
@Sn0w3y
Copy link
Copy Markdown
Collaborator Author

Sn0w3y commented Dec 12, 2025

@sjjh should be fixed now - please check :)

Szenario Vorher Nachher
Normale Aktivierung (nicht ladend)
Aktivierung während Laden, imported kommt NACH charge_state ✗ energyStartSession bleibt null ✓ wird in handleImported() initialisiert
Aktivierung während Laden, imported kommt VOR charge_state ✓ (über startNewSession())

@sthhs
Copy link
Copy Markdown
Contributor

sthhs commented Dec 12, 2025

@sjjh should be fixed now - please check :)

Do you really mean @sjjh or me?

@Sn0w3y
Copy link
Copy Markdown
Collaborator Author

Sn0w3y commented Dec 12, 2025

@sjjh should be fixed now - please check :)

Do you really mean @sjjh or me?

Sorry, i meant you for sure!

@sthhs
Copy link
Copy Markdown
Contributor

sthhs commented Dec 13, 2025

@sjjh should be fixed now - please check :)

Do you really mean @sjjh or me?

Sorry, i meant you for sure!

Now it works. The session energy is initialized and calculated correctly.

@Sn0w3y
Copy link
Copy Markdown
Collaborator Author

Sn0w3y commented Dec 13, 2025

@sfeilmeier i guess ready to merge 🎉😋

@sfeilmeier sfeilmeier merged commit 021a5b0 into OpenEMS:develop Dec 13, 2025
6 of 7 checks passed
@sjjh
Copy link
Copy Markdown
Contributor

sjjh commented Dec 14, 2025

We indeed don't own any openWB. We're still struggling with the ABL and Alven. :D In case we would switch to openWB, are all features of it supported in OpenEMS?

@Sn0w3y
Copy link
Copy Markdown
Collaborator Author

Sn0w3y commented Dec 14, 2025

are all features of it supported in OpenEMS?

Please have a look at the Code - it is hard to Answer "Functions" of Code - especially on GitHub (for Developers mainly) - please move such Conversations to community.

@Sn0w3y Sn0w3y deleted the refactor-openwb-mqtt branch December 14, 2025 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants