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

We cannot pass the context of the program to mqtt publish_callback #180

Open
Lecrapouille opened this issue Apr 3, 2023 · 2 comments
Open

Comments

@Lecrapouille
Copy link

Why not passing the context of the program in mqtt_init ? Because in void publish_callback(void** /*unused*/, struct mqtt_response_publish *published) you have to store data in a global variable since there is no way to access it.

Idea:

struct mqtt_client client;
struct context { int foo; int bar; } my_context;

client->context = &my_context;
...

static void publish_callback(void** /*unused*/, struct mqtt_response_publish *published)
{
   struct context* my_context = (struct  context*) published->context;
   my_context->foo = process(published->application_message, published->application_message_size);
}
@arielmol
Copy link

just found the same

@Lecrapouille
Copy link
Author

@arielmol I have made a quick implementation in C++ if you wish https://github.com/Lecrapouille/MQTT

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