Skip to content

Updated the MQTT component to optionally filter its messages by topic paths#3321

Merged
sfeilmeier merged 5 commits intoOpenEMS:developfrom
da-Kai:feature/mqtt-filter
Sep 22, 2025
Merged

Updated the MQTT component to optionally filter its messages by topic paths#3321
sfeilmeier merged 5 commits intoOpenEMS:developfrom
da-Kai:feature/mqtt-filter

Conversation

@da-Kai
Copy link
Copy Markdown
Contributor

@da-Kai da-Kai commented Sep 20, 2025

The current implementation of MQTT can turn in to a bit of a fire hose of data for situations where you only want some of the fields possible. This patch adds a filter function which inhibits certain topics from actually sending to the broker, instead they silently complete, doing nothing.

A single new configuration string has been added, into which a semicolon-delimited set of topic filters can be written allowing only topics which match these specifications to pass.

The topic filters use the same syntax as normal MQTT client subscriptions, so can use the + and # specifiers to indicate single, or multi-level paths.

An example path might be edge/fems33/channel/meter+/+ which would pull all metrics in meter0, meter1, etc. paths, but exclude any other topics.

THIS NEEDS TESTING - Please can someone with an otherwise working setup please check that this works, as I'm currently unable to, as I don't have access to our test hardware.

Fork of #1503 by @JohnVidler

@da-Kai da-Kai requested a review from Copilot September 20, 2025 19:59
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds topic filtering functionality to the MQTT component, allowing users to selectively publish only certain topics that match specified patterns. It introduces a new configuration option for filtering and changes the publish method to support filtered publishing status.

  • Added a filterSpec configuration parameter that accepts semicolon-delimited MQTT topic patterns using wildcards (+ and #)
  • Modified the publish mechanism to return an enum status instead of boolean, supporting OK, ERROR, and FILTERED states
  • Implemented pattern matching logic to filter topics before publishing to the broker

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
Config.java Added new filterSpec configuration attribute for topic filtering
MqttPublishStatus.java New enum to represent publish operation status (OK, ERROR, FILTERED)
ControllerApiMqttImpl.java Implemented filtering logic and updated publish methods to return status enum
SendChannelValuesWorker.java Updated to handle new publish status enum and improved logging
ControllerApiMqtt.java Removed trailing slashes from topic constants
MyConfig.java Added test implementation for new filterSpec method

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@codecov
Copy link
Copy Markdown

codecov bot commented Sep 20, 2025

Codecov Report

❌ Patch coverage is 33.33333% with 52 lines in your changes missing coverage. Please review.

❌ Your patch status has failed because the patch coverage (33.34%) 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    #3321      +/-   ##
=============================================
- Coverage      59.53%   59.51%   -0.02%     
  Complexity       113      113              
=============================================
  Files           2765     2767       +2     
  Lines         119513   119579      +66     
  Branches        8892     8906      +14     
=============================================
+ Hits           71142    71156      +14     
- Misses         45697    45745      +48     
- Partials        2674     2678       +4     
🚀 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.

* Apply requested changes from review
* Add MqttTopicFilter and unit tests
@da-Kai da-Kai requested a review from sfeilmeier September 22, 2025 13:59
Copy link
Copy Markdown
Contributor

@sfeilmeier sfeilmeier left a comment

Choose a reason for hiding this comment

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

Nice solution 👍

@sfeilmeier sfeilmeier merged commit fa081fe into OpenEMS:develop Sep 22, 2025
5 of 7 checks passed
@da-Kai da-Kai deleted the feature/mqtt-filter branch September 23, 2025 09:54
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.

3 participants