I am using Paho MQTT Ayncronous version ( libmqttv3a) and I am trying to find a way to receive messages in similar way that Mosquitto does,
mosquitto has 2 functions mosquitto_message_callback_set and mosquitto_subscribe_callback_set, the first is for receiving messages from that came from
the broker and the second when the broker responds to a subscription request.
In case of Paho I am only able to find one similar to the second, MQTTAsync_setCallbacks 4th parameter (MQTTAsync_messageArrived callback)
This function only handles Subscription responses.
/*
* Function: mosquitto_message_callback_set
*
* Set the message callback. This is called when a message is received from the
* broker.
*
* Parameters:
* mosq - a valid mosquitto instance.
* on_message - a callback function in the following form:
* void callback(struct mosquitto *mosq, void *obj, const struct mosquitto_message *message)
*
* Callback Parameters:
* mosq - the mosquitto instance making the callback.
* obj - the user data provided in <mosquitto_new>
* message - the message data. This variable and associated memory will be
* freed by the library after the callback completes. The client
* should make copies of any of the data it requires.
*
* See Also:
* <mosquitto_message_copy>
*/
libmosq_EXPORT void mosquitto_message_callback_set(struct mosquitto *mosq, void (*on_message)(struct mosquitto *, void *, const struct mosquitto_message *));
/*
* Function: mosquitto_subscribe_callback_set
*
* Set the subscribe callback. This is called when the broker responds to a
* subscription request.
*
* Parameters:
* mosq - a valid mosquitto instance.
* on_subscribe - a callback function in the following form:
* void callback(struct mosquitto *mosq, void *obj, int mid, int qos_count, const int *granted_qos)
*
* Callback Parameters:
* mosq - the mosquitto instance making the callback.
* obj - the user data provided in <mosquitto_new>
* mid - the message id of the subscribe message.
* qos_count - the number of granted subscriptions (size of granted_qos).
* granted_qos - an array of integers indicating the granted QoS for each of
* the subscriptions.
*/
libmosq_EXPORT void mosquitto_subscribe_callback_set(struct mosquitto *mosq, void (*on_subscribe)(struct mosquitto *, void *, int, int, const int *));