39#ifndef MQTT_DO_NOT_USE_CUSTOM_CONFIG
41 #include "core_mqtt_config.h"
58#define MQTT_LIBRARY_VERSION "v1.1.2"
67#define MQTT_PACKET_ID_INVALID ( ( uint16_t ) 0U )
72struct MQTTDeserializedInfo;
97 struct MQTTPacketInfo * pPacketInfo,
98 struct MQTTDeserializedInfo * pDeserializedInfo );
104typedef enum MQTTConnectionStatus
114typedef enum MQTTPublishState
133typedef enum MQTTPubAckType
145typedef enum MQTTSubAckStatus
157typedef struct MQTTPubAckInfo
168typedef struct MQTTContext
232typedef struct MQTTDeserializedInfo
419 bool * pSessionPresent );
474 size_t subscriptionCount,
590 size_t subscriptionCount,
668 uint32_t timeoutMs );
735 uint32_t timeoutMs );
792 const uint16_t topicNameLength,
793 const char * pTopicFilter,
794 const uint16_t topicFilterLength,
881 uint8_t ** pPayloadStart,
882 size_t * pPayloadSize );
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:2272
const char * MQTT_Status_strerror(MQTTStatus_t status)
Error code to string conversion for MQTT statuses.
Definition: core_mqtt.c:2425
MQTTStatus_t MQTT_Publish(MQTTContext_t *pContext, const MQTTPublishInfo_t *pPublishInfo, uint16_t packetId)
Publishes a message to the given topic name.
Definition: core_mqtt.c:1909
MQTTStatus_t MQTT_ReceiveLoop(MQTTContext_t *pContext, uint32_t timeoutMs)
Loop to receive packets from the transport interface. Does not handle keep alive.
Definition: core_mqtt.c:2217
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:1849
MQTTStatus_t MQTT_MatchTopic(const char *pTopicName, const uint16_t topicNameLength, const char *pTopicFilter, const uint16_t topicFilterLength, bool *pIsMatch)
A utility function that determines whether the passed topic filter and topic name match according to ...
Definition: core_mqtt.c:2297
MQTTStatus_t MQTT_Ping(MQTTContext_t *pContext)
Sends an MQTT PINGREQ to broker.
Definition: core_mqtt.c:1983
MQTTStatus_t MQTT_Unsubscribe(MQTTContext_t *pContext, const MQTTSubscribeInfo_t *pSubscriptionList, size_t subscriptionCount, uint16_t packetId)
Sends MQTT UNSUBSCRIBE for the given list of topic filters to the broker.
Definition: core_mqtt.c:2044
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:2366
MQTTStatus_t MQTT_Disconnect(MQTTContext_t *pContext)
Disconnect an MQTT session.
Definition: core_mqtt.c:2104
MQTTStatus_t MQTT_ProcessLoop(MQTTContext_t *pContext, uint32_t timeoutMs)
Loop to receive packets from the transport interface. Handles keep alive.
Definition: core_mqtt.c:2160
MQTTStatus_t MQTT_Init(MQTTContext_t *pContext, const TransportInterface_t *pTransportInterface, MQTTGetCurrentTimeFunc_t getTimeFunction, MQTTEventCallback_t userCallback, const MQTTFixedBuffer_t *pNetworkBuffer)
Initialize an MQTT context.
Definition: core_mqtt.c:1693
MQTTStatus_t MQTT_Connect(MQTTContext_t *pContext, const MQTTConnectInfo_t *pConnectInfo, const MQTTPublishInfo_t *pWillInfo, uint32_t timeoutMs, bool *pSessionPresent)
Establish an MQTT session.
Definition: core_mqtt.c:1752
This represents the default values for the configuration macros for the MQTT library.
#define MQTT_STATE_ARRAY_MAX_COUNT
Determines the maximum number of MQTT PUBLISH messages, pending acknowledgment at a time,...
Definition: core_mqtt_config_defaults.h:82
User-facing functions for serializing and deserializing MQTT 3.1.1 packets. This header should be inc...
void(* MQTTEventCallback_t)(struct MQTTContext *pContext, struct MQTTPacketInfo *pPacketInfo, struct MQTTDeserializedInfo *pDeserializedInfo)
Application callback for receiving incoming publishes and incoming acks.
Definition: core_mqtt.h:96
uint32_t(* MQTTGetCurrentTimeFunc_t)(void)
Application provided function to query the current time in milliseconds.
Definition: core_mqtt.h:81
MQTTPublishState_t
The state of QoS 1 or QoS 2 MQTT publishes, used in the state engine.
Definition: core_mqtt.h:115
MQTTSubAckStatus_t
The status codes in the SUBACK response to a subscription request.
Definition: core_mqtt.h:146
MQTTPubAckType_t
Packet types used in acknowledging QoS 1 or QoS 2 publishes.
Definition: core_mqtt.h:134
MQTTConnectionStatus_t
Values indicating if an MQTT connection exists.
Definition: core_mqtt.h:105
MQTTStatus_t
Return codes from MQTT functions.
Definition: core_mqtt_serializer.h:97
MQTTQoS_t
MQTT Quality of Service values.
Definition: core_mqtt_serializer.h:116
@ MQTTPubRecSend
The library will send a PUBREC for a received PUBLISH.
Definition: core_mqtt.h:119
@ MQTTPubRecPending
The library is awaiting a PUBREC for an outgoing PUBLISH.
Definition: core_mqtt.h:123
@ MQTTPubCompPending
The library is awaiting a PUBCOMP for an outgoing PUBLISH.
Definition: core_mqtt.h:125
@ MQTTPubRelSend
The library will send a PUBREL for a received PUBREC.
Definition: core_mqtt.h:120
@ MQTTPubAckSend
The library will send a PUBACK for a received PUBLISH.
Definition: core_mqtt.h:118
@ MQTTPubRelPending
The library is awaiting a PUBREL for an incoming PUBLISH.
Definition: core_mqtt.h:124
@ MQTTPubCompSend
The library will send a PUBCOMP for a received PUBREL.
Definition: core_mqtt.h:121
@ MQTTStateNull
An empty state with no corresponding PUBLISH.
Definition: core_mqtt.h:116
@ MQTTPublishSend
The library will send an outgoing PUBLISH packet.
Definition: core_mqtt.h:117
@ MQTTPubAckPending
The library is awaiting a PUBACK for an outgoing PUBLISH.
Definition: core_mqtt.h:122
@ MQTTPublishDone
The PUBLISH has been completed.
Definition: core_mqtt.h:126
@ MQTTSubAckSuccessQos2
Success with a maximum delivery at QoS 2.
Definition: core_mqtt.h:149
@ MQTTSubAckSuccessQos1
Success with a maximum delivery at QoS 1.
Definition: core_mqtt.h:148
@ MQTTSubAckSuccessQos0
Success with a maximum delivery at QoS 0.
Definition: core_mqtt.h:147
@ MQTTSubAckFailure
Failure.
Definition: core_mqtt.h:150
@ MQTTPuback
PUBACKs are sent in response to a QoS 1 PUBLISH.
Definition: core_mqtt.h:135
@ MQTTPubrec
PUBRECs are sent in response to a QoS 2 PUBLISH.
Definition: core_mqtt.h:136
@ MQTTPubcomp
PUBCOMPs are sent in response to a PUBREL.
Definition: core_mqtt.h:138
@ MQTTPubrel
PUBRELs are sent in response to a PUBREC.
Definition: core_mqtt.h:137
@ MQTTNotConnected
MQTT Connection is inactive.
Definition: core_mqtt.h:106
@ MQTTConnected
MQTT Connection is active.
Definition: core_mqtt.h:107
MQTT CONNECT packet parameters.
Definition: core_mqtt_serializer.h:140
A struct representing an MQTT connection.
Definition: core_mqtt.h:169
MQTTFixedBuffer_t networkBuffer
The buffer used in sending and receiving packets from the network.
Definition: core_mqtt.h:188
MQTTConnectionStatus_t connectStatus
Whether the context currently has a connection to the broker.
Definition: core_mqtt.h:198
MQTTEventCallback_t appCallback
Callback function used to give deserialized MQTT packets to the application.
Definition: core_mqtt.h:208
TransportInterface_t transportInterface
The transport interface used by the MQTT connection.
Definition: core_mqtt.h:183
MQTTGetCurrentTimeFunc_t getTime
Function used to get millisecond timestamps.
Definition: core_mqtt.h:203
uint32_t lastPacketTime
Timestamp of the last packet sent by the library.
Definition: core_mqtt.h:213
bool waitingForPingResp
If the library is currently awaiting a PINGRESP.
Definition: core_mqtt.h:224
uint32_t pingReqSendTimeMs
Timestamp of the last sent PINGREQ.
Definition: core_mqtt.h:223
uint16_t nextPacketId
The next available ID for outgoing MQTT packets.
Definition: core_mqtt.h:193
bool controlPacketSent
Whether the library sent a packet during a call of MQTT_ProcessLoop or MQTT_ReceiveLoop.
Definition: core_mqtt.h:219
uint16_t keepAliveIntervalSec
Keep Alive interval.
Definition: core_mqtt.h:222
Struct to hold deserialized packet information for an MQTTEventCallback_t callback.
Definition: core_mqtt.h:233
MQTTStatus_t deserializationResult
Return code of deserialization.
Definition: core_mqtt.h:236
MQTTPublishInfo_t * pPublishInfo
Pointer to deserialized publish info.
Definition: core_mqtt.h:235
uint16_t packetIdentifier
Packet ID of deserialized packet.
Definition: core_mqtt.h:234
Buffer passed to MQTT library.
Definition: core_mqtt_serializer.h:130
MQTT incoming packet parameters.
Definition: core_mqtt_serializer.h:251
An element of the state engine records for QoS 1 or Qos 2 publishes.
Definition: core_mqtt.h:158
MQTTQoS_t qos
The QoS of the original PUBLISH.
Definition: core_mqtt.h:160
MQTTPublishState_t publishState
The current state of the publish process.
Definition: core_mqtt.h:161
uint16_t packetId
The packet ID of the original PUBLISH.
Definition: core_mqtt.h:159
MQTT PUBLISH packet parameters.
Definition: core_mqtt_serializer.h:209
MQTT SUBSCRIBE packet parameters.
Definition: core_mqtt_serializer.h:187
The transport layer interface.
Definition: transport_interface.h:252
Transport interface definitions to send and receive data over the network.