Unsubscribe Method

Unsubscribes the class from the specified topic.

Syntax

ANSI (Cross Platform)
int Unsubscribe(const char* lpszTopicId, int iTopicIdType);

Unicode (Windows)
INT Unsubscribe(LPCWSTR lpszTopicId, INT iTopicIdType);
- (void)unsubscribe:(NSString*)topicId :(int)topicIdType;
#define MID_MQTTSN_UNSUBSCRIBE 17

IPWORKSIOT_EXTERNAL int IPWORKSIOT_CALL IPWorksIoT_MQTTSN_Do(void *lpObj, int methid, int cparam, void *param[], int cbparam[], int64 *lpllVal);

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

Error Handling (C++)

This method returns a result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message. (Note: This method's result code can also be obtained by calling the GetLastErrorCode() method after it returns.)

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