MQTT Vuser Functions > mqtt_unsubscribe

mqtt_unsubscribe

Unsubscribes the client from a topic.

C Language

int mqtt_unsubscribe( MQTT handle, const char* topic);

Example MQTT Vuser Functions

Arguments

Name Comments
handle The MQTT client handle returned by mqtt_create.
topic The topic or wildcard topic to stop receiving messages on. See mqtt_subscribe.

General

mqtt_unsubscribe unsubscribes the client from a topic or a set of topics on the broker.

You can call this function at any time during the run to stop the client from receiving messages on subscribed topics. We recommend that you call this function before mqtt_disconnect (not required).

If the connection is lost during an mqtt_unsubscribe operation, the client will not try to unsubscribe again after reconnecting, and a warning will be displayed in the script's output.

If invalid arguments are passed, the Vuser aborts, even if Continue on error is set.

Return Values

MQTT_SUCCESS or MQTT_FAIL

Parameterization

Standard parameterization is available for this function.

Example

/* Subscribe to the topics matching the wildcard "sensors/temperature/#"*/

mqtt_subscribe(client, "sensors/temperature/#");

/* Now the client will receive messages it was subscribed to */

/* Unsubscribe from the topic "sensors/temperature/surface/3" */

mqtt_unsubscribe(client, "sensors/temperature/surface/3");

/* Now it will receive messages from all subscriptions but "sensors/temperature/surface/3" */