Open Lecrapouille opened 1 year ago
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.
mqtt_init
void publish_callback(void** /*unused*/, struct mqtt_response_publish *published)
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); }
just found the same
@arielmol I have made a quick implementation in C++ if you wish https://github.com/Lecrapouille/MQTT
Why not passing the context of the program in
mqtt_init
? Because invoid 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: