coreMQTT v2.0.0
MQTT 3.1.1 Client Library
MQTT_GetSubAckStatusCodes

Parses the payload of an MQTT SUBACK packet that contains status codes corresponding to topic filter subscription requests from the original subscribe packet.

uint8_t ** pPayloadStart,
size_t * pPayloadSize );
MQTTStatus_t MQTT_GetSubAckStatusCodes(const MQTTPacketInfo_t *pSubackPacket, uint8_t **pPayloadStart, size_t *pPayloadSize)
Parses the payload of an MQTT SUBACK packet that contains status codes corresponding to topic filter ...
Definition: core_mqtt.c:3159
MQTTStatus_t
Return codes from MQTT functions.
Definition: core_mqtt_serializer.h:97
MQTT incoming packet parameters.
Definition: core_mqtt_serializer.h:254

Each return code in the SUBACK packet corresponds to a topic filter in the SUBSCRIBE Packet being acknowledged. The status codes can be one of the following:

  • 0x00 - Success - Maximum QoS 0
  • 0x01 - Success - Maximum QoS 1
  • 0x02 - Success - Maximum QoS 2
  • 0x80 - Failure Refer to MQTTSubAckStatus_t for the status codes.
Parameters
[in]pSubackPacketThe SUBACK packet whose payload is to be parsed.
[out]pPayloadStartThis is populated with the starting address of the payload (or return codes for topic filters) in the SUBACK packet.
[out]pPayloadSizeThis is populated with the size of the payload in the SUBACK packet. It represents the number of topic filters whose SUBACK status is present in the packet.
Returns
Returns one of the following:

Example

// Global variable used in this example.
// This is assumed to be the subscription list in the original SUBSCRIBE packet.
MQTTSubscribeInfo_t pSubscribes[ NUMBER_OF_SUBSCRIPTIONS ];
// MQTT_GetSubAckStatusCodes is intended to be used from the application
// callback that is called by the library in MQTT_ProcessLoop or MQTT_ReceiveLoop.
void eventCallback(
MQTTContext_t * pContext,
MQTTPacketInfo_t * pPacketInfo,
MQTTDeserializedInfo_t * pDeserializedInfo
)
{
uint8_t * pCodes;
size_t numCodes;
if( pPacketInfo->type == MQTT_PACKET_TYPE_SUBACK )
{
status = MQTT_GetSubAckStatusCodes( pPacketInfo, &pCodes, &numCodes );
// Since the pointers to the payload and payload size are not NULL, and
// we use the packet info struct passed to the app callback (verified
// to be valid by the library), this function must return success.
assert( status == MQTTSuccess );
// The server must send a response code for each topic filter in the
// original SUBSCRIBE packet.
assert( numCodes == NUMBER_OF_SUBSCRIPTIONS );
for( int i = 0; i < numCodes; i++ )
{
// The only failure code is 0x80 = MQTTSubAckFailure.
if( pCodes[ i ] == MQTTSubAckFailure )
{
// The subscription failed, we may want to retry the
// subscription in pSubscribes[ i ] outside of this callback.
}
else
{
// The subscription was granted, but the maximum QoS may be
// lower than what was requested. We can verify the granted QoS.
if( pSubscribes[ i ].qos != pCodes[ i ] )
{
"Requested QoS %u, but granted QoS %u for %s",
pSubscribes[ i ].qos, pCodes[ i ], pSubscribes[ i ].pTopicFilter
) );
}
}
}
}
// Handle other packet types.
}
#define LogWarn(message)
Macro that is called in the MQTT library for logging "Warning" level messages.
Definition: core_mqtt_default_logging.h:81
#define MQTT_PACKET_TYPE_SUBACK
SUBACK (server-to-client).
Definition: core_mqtt_serializer.h:71
@ MQTTSubAckFailure
Failure.
Definition: core_mqtt.h:141
@ MQTTSuccess
Definition: core_mqtt_serializer.h:98
A struct representing an MQTT connection.
Definition: core_mqtt.h:160
Struct to hold deserialized packet information for an MQTTEventCallback_t callback.
Definition: core_mqtt.h:244
uint8_t type
Type of incoming MQTT packet.
Definition: core_mqtt_serializer.h:258
MQTT SUBSCRIBE packet parameters.
Definition: core_mqtt_serializer.h:190