Add message filtering ability#157
Open
thebigpotatoe wants to merge 1 commit intomarvinroger:masterfrom
thebigpotatoe:master
Open
Add message filtering ability#157thebigpotatoe wants to merge 1 commit intomarvinroger:masterfrom thebigpotatoe:master
thebigpotatoe wants to merge 1 commit intomarvinroger:masterfrom
thebigpotatoe:master
Conversation
New methods include; - overloaded onMessage() to accept callback for given subscription - onFilteredMessage() to accept callback for given subscription - overloaded subscribe() to add a callback to a specific subscription when subscribing
|
This would be great instead of having to compare 5000 strings. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Been using this library for a while and absolutely love it. The async nature is second to none above similar libraries. However I find myself writing boiler plate every time I set up a new project to filter incoming messages to achieve the correct action in the onMessage() callback.
To help improve on the library, I added the ability to filter the topic of an incoming message in the _onMessage() function when looping through each of the added callbacks from the user. This is achieved by supplying a chosen topic when adding a callback with onMessage() and a new method onFilteredMessage(). These achieve the same outcome, but one is easier to follow when reading code.
AsyncMqttClient& AsyncMqttClient::onMessage(AsyncMqttClientInternals::OnMessageUserCallback callback, const char* _userTopic = "#")' 'AsyncMqttClient& AsyncMqttClient::onFilteredMessage(AsyncMqttClientInternals::OnMessageUserCallback callback, const char* _userTopic)I also added a shortcut for this by overloading subscribe(). By supplying a callback when adding a subscription, the callback will be added to the vector called by _onMessage() actually removing the need to supply a callback using onMessage().
uint16_t AsyncMqttClient::subscribe(const char* topic, uint8_t qos, AsyncMqttClientInternals::OnMessageUserCallback callback)I think with these two methods and a little documentation on how to use them would make using the library a little more straightforward and far more efficient for new users when subscribing to more than one topic needing more than one callback. It will also reduce a bunch of boilerplate in a fair few of my projects and I hope a few from others.
I have tried to keep to the same formatting and style for easy integration, and have also updated all supporting files such as the examples and keywords.