Skip to content

Conversation

@ThatsLucas
Copy link
Contributor

Describe your changes

This PR fixes the issue reported in #1712 where the MQTT message handler was not working with topics containing wildcards.
I used the already existing function 'check_topic_matches'

Issue ticket number and link

Checklist before requesting a review

  • I have performed a self-review of my code
  • I have made corresponding changes to the documentation
  • I read the contribution documentation and made sure that my changes meet its requirements

@james-ctc
Copy link
Member

From memory it is deliberate design decision to not support wildcards on the internal EVerest api topics.
Wildcards should be supported for non EVerest api topics.

@ThatsLucas
Copy link
Contributor Author

Oh ok, i'll avoid using them then.
Do you want me to close this PR ?

@Pietfried Pietfried self-assigned this Feb 3, 2026
Copy link
Contributor

@Pietfried Pietfried left a comment

Choose a reason for hiding this comment

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

Hi @ThatsLucas , thanks for the contribution. It is ok to add wildcard support for external mqtt.

The current approach modifies execute_handlers_from_vector which affects both var_handlers and external mqtt messages but we would like to keep var_handlers separate.

handle_error_message is already considering wildcard topics, so we can make use of the same approach.

My suggestion is to define execute_handlers_from_vector_with_wildcards as a member function and use it within handle_error_message and handle_external_mqtt_message like:

void MessageHandler::handle_external_mqtt_message(const std::string& topic, const json& data) {
    execute_handlers_from_vector_with_wildcards(external_var_handlers, topic,
                                            [&](const auto& handler) { (*handler->handler)(topic, data); });
}

void MessageHandler::handle_error_message(const std::string& topic, const json& data) {
    execute_handlers_from_vector_with_wildcards(error_handlers, topic,
                                            [&](const auto& handler) { (*handler->handler)(topic, data); });
}

@Pietfried Pietfried linked an issue Feb 4, 2026 that may be closed by this pull request
@ThatsLucas ThatsLucas force-pushed the fix-wildcard-mqtt-ext branch from d906300 to 5024893 Compare February 4, 2026 10:38
…n and now use vector for errror_handler

Signed-off-by: ThatsLucas <[email protected]>
@ThatsLucas ThatsLucas force-pushed the fix-wildcard-mqtt-ext branch from 5024893 to cd61b19 Compare February 4, 2026 10:43
@ThatsLucas
Copy link
Contributor Author

Hey @Pietfried thanks for the suggestion !

I made the requested change, looks good for me.
Just to double check, i had to change from

    std::map<MqttTopic, std::shared_ptr<TypedHandler>> error_handlers;  
to
    std::map<MqttTopic, std::vector<std::shared_ptr<TypedHandler>>>
        error_handlers; 

Is this the intended behavior, or was it meant to replace the handler each time?

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.

Mqtt subscribe not working as expected with wildcards

3 participants