coreMQTT v1.2.0
MQTT 3.1.1 Client Library

Sends MQTT SUBSCRIBE for the given list of topic filters to the broker.

const MQTTSubscribeInfo_t * pSubscriptionList,
size_t subscriptionCount,
uint16_t packetId );
MQTTStatus_t MQTT_Subscribe(MQTTContext_t *pContext, const MQTTSubscribeInfo_t *pSubscriptionList, size_t subscriptionCount, uint16_t packetId)
Sends MQTT SUBSCRIBE for the given list of topic filters to the broker.
Definition: core_mqtt.c:1856
Return codes from MQTT functions.
Definition: core_mqtt_serializer.h:97
A struct representing an MQTT connection.
Definition: core_mqtt.h:169
MQTT SUBSCRIBE packet parameters.
Definition: core_mqtt_serializer.h:187
[in]pContextInitialized MQTT context.
[in]pSubscriptionListList of MQTT subscription info.
[in]subscriptionCountThe number of elements in pSubscriptionList.
[in]packetIdPacket ID generated by MQTT_GetPacketId.
MQTTNoMemory if the MQTTContext_t.networkBuffer is too small to hold the MQTT packet; MQTTBadParameter if invalid parameters are passed; MQTTSendFailed if transport write failed; MQTTSuccess otherwise.


// Variables used in this example.
MQTTStatus_t status;
MQTTSubscribeInfo_t subscriptionList[ NUMBER_OF_SUBSCRIPTIONS ] = { 0 };
uint16_t packetId;
// This context is assumed to be initialized and connected.
MQTTContext_t * pContext;
// This is assumed to be a list of filters we want to subscribe to.
const char * filters[ NUMBER_OF_SUBSCRIPTIONS ];
// Set each subscription.
for( int i = 0; i < NUMBER_OF_SUBSCRIPTIONS; i++ )
subscriptionList[ i ].qos = MQTTQoS0;
// Each subscription needs a topic filter.
subscriptionList[ i ].pTopicFilter = filters[ i ];
subscriptionList[ i ].topicFilterLength = strlen( filters[ i ] );
// Obtain a new packet id for the subscription.
packetId = MQTT_GetPacketId( pContext );
status = MQTT_Subscribe( pContext, &subscriptionList[ 0 ], NUMBER_OF_SUBSCRIPTIONS, packetId );
if( status == MQTTSuccess )
// We must now call MQTT_ReceiveLoop() or MQTT_ProcessLoop() to receive the SUBACK.
// If the broker accepts the subscription we can now receive publishes
// on the requested topics.
uint16_t MQTT_GetPacketId(MQTTContext_t *pContext)
Get a packet ID that is valid according to the MQTT 3.1.1 spec.
Definition: core_mqtt.c:2279
@ MQTTSuccess
Definition: core_mqtt_serializer.h:98
Definition: core_mqtt_serializer.h:117
MQTTQoS_t qos
Quality of Service for subscription.
Definition: core_mqtt_serializer.h:191
uint16_t topicFilterLength
Length of subscription topic filter.
Definition: core_mqtt_serializer.h:201
const char * pTopicFilter
Topic filter to subscribe to.
Definition: core_mqtt_serializer.h:196