IPWorks IoT 2020 Node.js Edition

Questions / Feedback?

Unsubscribe Method

Unsubscribes the class from the specified topic.

Syntax

mqttsn.unsubscribe(topicId, topicIdType, [callback])

Callback

The 'callback' parameter specifies a function which will be called when the operation completes (or an error is encountered). If the 'callback' parameter is not specified, then the method will block and will not return until the operation completes (or an error is encountered).

The callback for this method is defined as:

function(err){ }

'err' is the error that occurred. If there was no error, then 'err' is 'null'.

'err' has 2 properties which hold detailed information:

err.code
err.message

Remarks

This method unsubscribes the class to the TopicId.

TopicIdType indicates the category of value specified in TopicId and may have the following values:

  • 0: Topic name - a full topic name as described in RegisterTopic to be registered by the gateway.
  • 1: Pre-defined topic id - id whose mapping to a topic name is known in advance by both the client and the gateway - no registration is necessary.
  • 2: Short topic name - has a fixed length of two bytes and is short enough that no registration is necessary. To use one, simply set the correct TopicIdType and set the TopicId to a two-character string.

Unsubscribe Examples

String fullTopicName = "full/topic/name";
mqtt1.Unsubscribe(fullTopicName, 0); // unsubscribe from topic name

mqtt1.Unsubscribe(fullTopicName+"/#", 0); // must use full topic filter if includes wildcard; can't unsubscribe from individual topics included in the filter

mqtt1.Unsubscribe("aa", 2); // unsubscribe from short topic

Copyright (c) 2022 /n software inc. - All rights reserved.
IPWorks IoT 2020 Node.js Edition - Version 20.0 [Build 8265]