coreMQTT  v1.0.0
MQTT 3.1.1 Client Library
MQTT_ReceiveLoop

Loop to receive packets from the transport interface. Does not handle keep alive.

uint32_t timeoutMs );
Note
Passing a timeout value of 0 will run the loop for a single iteration.
Parameters
[in]pContextInitialized and connected MQTT context.
[in]timeoutMsMinimum time in milliseconds that the receive loop will run, unless an error occurs.
Returns
MQTTBadParameter if context is NULL; MQTTRecvFailed if a network error occurs during reception; MQTTSendFailed if a network error occurs while sending an ACK or PINGREQ; MQTTBadResponse if an invalid packet is received; MQTTIllegalState if an incoming QoS 1/2 publish or ack causes an invalid transition for the internal state machine; MQTTSuccess on success.

Example

// Variables used in this example.
MQTTStatus_t status;
uint32_t timeoutMs = 100;
uint32_t keepAliveMs = 60 * 1000;
// This context is assumed to be initialized and connected.
MQTTContext_t * pContext;
while( true )
{
status = MQTT_ReceiveLoop( pContext, timeoutMs );
if( status != MQTTSuccess )
{
// Determine the error. It's possible we might need to disconnect
// the underlying transport connection.
}
else
{
// Since this function does not send pings, the application may need
// to in order to comply with keep alive.
if( ( pContext->getTime() - pContext->lastPacketTime ) > keepAliveMs )
{
status = MQTT_Ping( pContext );
}
// Other application functions.
}
}
MQTT_Ping
MQTTStatus_t MQTT_Ping(MQTTContext_t *pContext)
Sends an MQTT PINGREQ to broker.
Definition: core_mqtt.c:1944
MQTTContext_t::lastPacketTime
uint32_t lastPacketTime
Timestamp of the last packet sent by the library.
Definition: core_mqtt.h:200
MQTTStatus_t
MQTTStatus_t
Return codes from MQTT functions.
Definition: core_mqtt_serializer.h:105
MQTT_ReceiveLoop
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:2178
MQTTContext_t::getTime
MQTTGetCurrentTimeFunc_t getTime
Function used to get millisecond timestamps.
Definition: core_mqtt.h:190
MQTTContext_t
A struct representing an MQTT connection.
Definition: core_mqtt.h:156
MQTTSuccess
@ MQTTSuccess
Definition: core_mqtt_serializer.h:106