Example #1
0
int mqtt_unsubscribe(const char* topic)
{
  if(!mqtt_ready())
    return -1;

  printf("sending unsubscribe\n");
  mqtt_state.outbound_message = mqtt_msg_unsubscribe(&mqtt_state.mqtt_connection, topic, 
                                                     &mqtt_state.pending_msg_id);
  mqtt_flags &= ~MQTT_FLAG_READY;
  mqtt_state.pending_msg_type = MQTT_MSG_TYPE_UNSUBSCRIBE;
  tcpip_poll_tcp(mqtt_state.tcp_connection);

  return 0;
}
Example #2
0
/**
  * @brief  MQTT un-subscibe function.
  * @param  client:   MQTT_Client reference
  * @param  topic:   String topic will un-subscribe
  * @retval TRUE if success queue
  */
BOOL ICACHE_FLASH_ATTR MQTT_UnSubscribe(MQTT_Client * client, char *topic) {
    uint8_t dataBuffer[MQTT_BUF_SIZE];
    uint16_t dataLen;
    client->mqtt_state.outbound_message = mqtt_msg_unsubscribe(&client->mqtt_state.mqtt_connection,
							       topic, &client->mqtt_state.pending_msg_id);
    MQTT_INFO("MQTT: queue un-subscribe, topic\"%s\", id: %d\r\n", topic, client->mqtt_state.pending_msg_id);
    while (QUEUE_Puts
	   (&client->msgQueue, client->mqtt_state.outbound_message->data,
	    client->mqtt_state.outbound_message->length) == -1) {
	MQTT_INFO("MQTT: Queue full\r\n");
	if (QUEUE_Gets(&client->msgQueue, dataBuffer, &dataLen, MQTT_BUF_SIZE) == -1) {
	    MQTT_INFO("MQTT: Serious buffer error\r\n");
	    return FALSE;
	}
    }
    system_os_post(MQTT_TASK_PRIO, 0, (os_param_t) client);
    return TRUE;
}