coreMQTT v2.0.0
MQTT 3.1.1 Client Library
MQTT_InitStatefulQoS

Initialize an MQTT context for QoS > 0.

MQTTPubAckInfo_t * pOutgoingPublishRecords,
size_t outgoingPublishCount,
MQTTPubAckInfo_t * pIncomingPublishRecords,
size_t incomingPublishCount );
MQTTStatus_t MQTT_InitStatefulQoS(MQTTContext_t *pContext, MQTTPubAckInfo_t *pOutgoingPublishRecords, size_t outgoingPublishCount, MQTTPubAckInfo_t *pIncomingPublishRecords, size_t incomingPublishCount)
Initialize an MQTT context for QoS > 0.
Definition: core_mqtt.c:2489
MQTTStatus_t
Return codes from MQTT functions.
Definition: core_mqtt_serializer.h:97
A struct representing an MQTT connection.
Definition: core_mqtt.h:160
An element of the state engine records for QoS 1 or Qos 2 publishes.
Definition: core_mqtt.h:149

This function must be called on an MQTTContext_t after MQTT_Init and before any other function.

Parameters
[in]pContextThe context to initialize.
[in]pOutgoingPublishRecordsPointer to memory which will be used to store state of outgoing publishes.
[in]outgoingPublishCountMaximum number of records which can be kept in the memory pointed to by pOutgoingPublishRecords.
[in]pIncomingPublishRecordsPointer to memory which will be used to store state of incoming publishes.
[in]incomingPublishCountMaximum number of records which can be kept in the memory pointed to by pIncomingPublishRecords.
Returns
MQTTBadParameter if invalid parameters are passed; MQTTSuccess otherwise.

Example

// Function for obtaining a timestamp.
uint32_t getTimeStampMs();
// Callback function for receiving packets.
void eventCallback(
MQTTContext_t * pContext,
MQTTPacketInfo_t * pPacketInfo,
MQTTDeserializedInfo_t * pDeserializedInfo
);
// Network send.
int32_t networkSend( NetworkContext_t * pContext, const void * pBuffer, size_t bytes );
// Network receive.
int32_t networkRecv( NetworkContext_t * pContext, void * pBuffer, size_t bytes );
MQTTContext_t mqttContext;
MQTTFixedBuffer_t fixedBuffer;
uint8_t buffer[ 1024 ];
const size_t outgoingPublishCount = 30;
MQTTPubAckInfo_t outgoingPublishes[ outgoingPublishCount ];
// Clear context.
memset( ( void * ) &mqttContext, 0x00, sizeof( MQTTContext_t ) );
// Set transport interface members.
transport.pNetworkContext = &someTransportContext;
transport.send = networkSend;
transport.recv = networkRecv;
// Set buffer members.
fixedBuffer.pBuffer = buffer;
fixedBuffer.size = 1024;
status = MQTT_Init( &mqttContext, &transport, getTimeStampMs, eventCallback, &fixedBuffer );
if( status == MQTTSuccess )
{
// We do not expect any incoming publishes in this example, therefore the incoming
// publish pointer is NULL and the count is zero.
status = MQTT_InitStatefulQoS( &mqttContext, outgoingPublishes, outgoingPublishCount, NULL, 0 );
// Now QoS1 and/or QoS2 publishes can be sent with this context.
}
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:2430
@ MQTTSuccess
Definition: core_mqtt_serializer.h:98
struct NetworkContext NetworkContext_t
The NetworkContext is an incomplete type. An implementation of this interface must define struct Netw...
Definition: transport_interface.h:189
Struct to hold deserialized packet information for an MQTTEventCallback_t callback.
Definition: core_mqtt.h:244
Buffer passed to MQTT library.
Definition: core_mqtt_serializer.h:133
size_t size
Size of buffer.
Definition: core_mqtt_serializer.h:135
uint8_t * pBuffer
Pointer to buffer.
Definition: core_mqtt_serializer.h:134
MQTT incoming packet parameters.
Definition: core_mqtt_serializer.h:254
The transport layer interface.
Definition: transport_interface.h:300
TransportSend_t send
Definition: transport_interface.h:302
TransportRecv_t recv
Definition: transport_interface.h:301
NetworkContext_t * pNetworkContext
Definition: transport_interface.h:304