AWS IoT Device SDK C: MQTT
MQTT 3.1.1 client library
Return to main page ↑
IotMqttCallbackParam_t Struct Reference

Parameter to an MQTT callback function. More...

#include <iot_mqtt_types.h>

Data Fields

IotMqttConnection_t mqttConnection
 The MQTT connection associated with this completed operation, incoming PUBLISH, or disconnect. More...
 
union {
   struct {
      IotMqttOperationType_t   type
 Type of operation that completed.
 
      IotMqttOperation_t   reference
 Reference to the operation that completed.
 
      IotMqttError_t   result
 Result of operation, e.g. succeeded or failed.
 
   }   operation
 
   struct {
      const char *   pTopicFilter
 Topic filter that matched the message.
 
      uint16_t   topicFilterLength
 Length of pTopicFilter.
 
      IotMqttPublishInfo_t   info
 PUBLISH message received from the server.
 
   }   message
 
   IotMqttDisconnectReason_t   disconnectReason
 Why the MQTT connection was disconnected.
 
u
 Valid member depends on callback type.
 

Detailed Description

Parameter to an MQTT callback function.

Parameter for: MQTT callback functions

The MQTT library passes this struct to a registered callback whenever an operation completes, a message is received on a topic filter, or an MQTT connection is disconnected.

The members of this struct are different based on the callback trigger. If the callback function was triggered for completed operation, the operation member is valid. Otherwise, if the callback was triggered because of a server-to-client PUBLISH, the message member is valid. Finally, if the callback was triggered because of a disconnect, the disconnectReason member is valid.

For an incoming PUBLISH, the message.pTopicFilter parameter provides the subscription topic filter that matched the topic name in the PUBLISH. Because topic filters may use MQTT wildcards, the topic filter may be different from the topic name. This pointer must be treated as read-only; the topic filter must not be modified. Additionally, the topic filter may go out of scope as soon as the callback function returns, so it must be copied if it is needed at a later time.

Attention
Any pointers in this callback parameter may be freed as soon as the callback function returns. Therefore, data must be copied if it is needed after the callback function returns.
The MQTT library may set strings that are not NULL-terminated.
See also
IotMqttCallbackInfo_t for the signature of a callback function.

Field Documentation

◆ mqttConnection

IotMqttConnection_t IotMqttCallbackParam_t::mqttConnection

The MQTT connection associated with this completed operation, incoming PUBLISH, or disconnect.

MQTT API functions are safe to call from a callback for completed operations or incoming PUBLISH messages. However, blocking function calls (including IotMqtt_Wait) are not recommended (though still safe). Do not call any API functions from a disconnect callback.


The documentation for this struct was generated from the following file: