mqtt_subscribe

Subscribes the client to a topic.

C Language

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

ExampleMQTT Vuser Functions

Arguments

NameComments
handleThe MQTT client handle returned by mqtt_create.
topic

The destination topic as a null-terminated string. The topic can contain wildcards.

Examples:
myhome/kitchen/temperature/1, region2/#
region2/WeatherStation/+/temperature

General

mqtt_subscribe subscribes the client to a topic or a set of topics that match the wildcard. The broker sends messages published on these topics automatically.

If the connection is lost during mqtt_subscribe, the client tries to subscribe again after reconnection.

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 to subscribed topics */

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

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

/* Now the client will receive messages from all subscriptions except for "sensors/temperature/surface/3" */