AWS IoT Device SDK C: MQTT
MQTT 3.1.1 client library
Return to main page ↑
IotMqtt_SerializePingreq

Generate a PINGREQ packet.

size_t bufferSize );
Parameters
[in,out]pBufferUser provide buffer where the PINGREQ packet is written.
[in]bufferSizeSize of the buffer pointed to by pBuffer.
Returns
IOT_MQTT_SUCCESS or IOT_MQTT_BAD_PARAMETER.
Note
This call is part of serializer API used for implementing light-weight MQTT client.

Example

// Example below shows how IotMqtt_SerializePingReq() should be used.
#define mqttexampleSHARED_BUFFER_SIZE 100
static ucSharedBuffer[mqttexampleSHARED_BUFFER_SIZE];
void sendPingRequest( int xMQTTSocket )
{
size_t xSentBytes = 0;
// PingReq is fixed length packet, therefore there is no need to calculate the size,
// just makes sure static buffer can accommodate Ping request.
IotMqtt_Assert( MQTT_PACKET_PINGREQ_SIZE <= mqttexampleSHARED_BUFFER_SIZE );
xResult = IotMqtt_SerializePingreq( ucSharedBuffer, MQTT_PACKET_PINGREQ_SIZE );
// xMQTTSocket here is posix socket created and connected to MQTT broker outside of this function.
xSentByte = send( xMQTTSocket, ( void * ) ucSharedBuffer, MQTT_PACKET_DISCONNECT_SIZE, 0 );
}