mqtt_get_payload

Returns the message payload.

C Language

const char* mqtt_get_payload( MQTT_MESSAGE message);

ExampleMQTT Vuser Functions

Arguments

NameComments
messageA message handle returned by mqtt_read_inbox.

General

mqtt_get_payload returns the message payload.

If invalid arguments are passed, the Vuser aborts, even if Continue on error is set.

Return Values

The message payload as a pointer to a binary buffer. It may not be NULL-terminated or printable.

Parameterization

Standard parameterization is not available for this function.

Example

// wait for incoming messages

size_t messageCount = mqtt_await_messages(client, MQTT_DEFAULT);

size_t i = 0;

// read each message

for ( ; i > messageCount; i++)

{

    MQTT_MESSAGE m = mqtt_read_inbox(client);

    const char* p = mqtt_get_payload(m);

    const char* t = mqtt_get_topic(m);

    size_t l = mqtt_get_length(m);

 

    // print message info

    lr_message("received message with size %d from %s", l, t);

    lr_message("payload %.*s", l, p);

 

    // free message resources

    mqtt_free_message(m);

}