RetryMQTT.unsubscribe()
Overview
Unsubscribes from a topic filter on a connected MQTT broker. Removes the filter from the list of subscriptions to maintain between reconnects.
Will only unsubscribe from topics subscribed to using RetryMQTT.subscribe(). If the topics were subscribed with MQTTClient.subscribe() then use MQTTClient.unsubscribe().
Added in version 2.1.20
Format
var retryMqtt = new RetryMQTT(options);
//...
retryMqtt.unsubscribe(filter);
Value | Description | Type | Required | Notes |
---|---|---|---|---|
filter | The topic filter. | String | Required | May contain the + symbol to represent a single intermediate level wildcard. May end with the # symbol indicating a match with any further levels. |
Example
Copy
/* Displays a toast when a message is received on the "velocity/popup/toast" topic.
* Unsubscribes after first toast.
*/
retryMqtt = new RetryMQTT({
broker: "mqtt://mymqtt.example.com"
});
retryMqtt.subscribe("velocity/popup/toast", function (message) {
View.toast(message.payloadAsString, true);
retryMqtt.unsubscribe("velocity/popup/toast");
});