IoT_Error_t aws_iot_mqtt_unsubscribe(char *pTopic) { IoT_Error_t rc = NONE_ERROR; if(0 != MQTTUnsubscribe(&c, pTopic)) { rc = UNSUBSCRIBE_ERROR; } return rc; }
int Cpush_unsubscribing(unsigned int clientHandle, unsigned char* topic) { if ((0 == clientHandle)||(NULL == topic)) { return CPUSH_RET_ERROR_PARA; } Client* client = (Client*)clientHandle; int rc = MQTTUnsubscribe(client,(const char*)topic); if (FAILURE == rc) { printf("Cpush_unsubscribing fail! ret:%d", rc); return CPUSH_RET_FAIL; } printf("Cpush_unsubscribing OK!"); return CPUSH_RET_OK; }
static enum cmd_status cmd_mqtt_unsubscribe_exec(char *cmd) { uint32_t i; char *tmp; int rc; /* get param */ if ((tmp = cmd_strrchr(cmd, '\"')) == NULL) return CMD_STATUS_INVALID_ARG; *tmp = '\0'; if ((tmp = cmd_strchr(cmd, '\"')) == NULL) return CMD_STATUS_INVALID_ARG; tmp++; i = 0; while (i < MAX_SUB_TOPICS) { if ((sub_topic[i] != NULL) && (!cmd_memcmp(sub_topic[i], tmp, cmd_strlen(tmp) + 1))) break; i++; } if (OS_MutexLock(&lock, 60000) == OS_E_TIMEOUT) return CMD_STATUS_FAIL; if ((rc = MQTTUnsubscribe(&client, tmp/*sub_topic[i]*/)) != 0) { CMD_ERR("Return code from MQTT unsubscribe is %d\n", rc); return CMD_STATUS_FAIL; } if (i == MAX_SUB_TOPICS) CMD_WRN("Unsubscribe topics is inexist\n"); else { cmd_free(sub_topic[i]); sub_topic[i] = NULL; } OS_MutexUnlock(&lock); return CMD_STATUS_OK; }