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

Callback Functions' Parameters Usage #170

Open
woolseyj opened this issue Jul 1, 2023 · 2 comments
Open

Callback Functions' Parameters Usage #170

woolseyj opened this issue Jul 1, 2023 · 2 comments

Comments

@woolseyj
Copy link

woolseyj commented Jul 1, 2023

I have a few questions and comments concerning the library's callback functions' parameters.

  1. What are the flags, rc, and pid parameters provided in some of the MQTT client's callback functions and what are their expected usage? I can't find much information on them in the library's documentation or in the source code itself.

  2. The on_subscribe() callback provides all of the parameters, topic and qos, submitted with the subscribe() method. However, this is not the case for the on_publish() and publish() counterparts as the message, retain, and qos parameters are missing. Is it possible to include them in a future update? As an example, I am trying to print the topic and message to the screen when a message is published. This would be nice to handle within the on_publish() callback, but I am instead printing the topic and message directly after publishing since the on_publish() callback does not have access to the topic's message. Is there a way to retrieve the published topic's message within the on_publish() callback that I am missing?

  3. What is the expected use case for the userdata parameter in some of the callback functions?

Your assistance would be greatly appreciated.

@vladak
Copy link
Contributor

vladak commented Oct 25, 2023

Let's start from the end: the user_data parameter is handy when you want to avoid global state. For example, there can be a variable that is defined only in main() and you'd like to modify it based on MQTT events. To avoid declaring the variable as a global variable, it can be passed to the MQTT() initializer and then it will be used as 2nd argument for the callbacks. Unfortunately, the user_data is not used for the "on_message" callbacks (#178) where it would be arguably most useful.

@woolseyj
Copy link
Author

Thank you @vladak for explaining the usage of the user_data parameter.

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

No branches or pull requests

2 participants