Main Content

read

Read available messages from MQTT topic

Since R2022a

Description

mqttMsg = read(mqttClient) reads all available messages from all subscribed topic in the specified MQTT client. This action flushes the messages so they cannot be read again.

mqttMsg = read(mqttClient,Topic=mqttTopic) reads all available messages from the specified MQTT topic among the topics that mqttClient is subscribed to.

example

Examples

collapse all

Read messages from one or more subscribed MQTT topics.

Read all available messages from a specific subscribed topic.

mqttMsg = read(mqttClient,Topic="TopMW01");

Read all available messages from all subscribed topics.

mqttMsg = read(mqttClient)
mqttMsg =

  2×2 timetable

            Time              Topic           Data      
    ____________________    _________    _______________

    14-Dec-2021 16:00:37    "TopMW01"    "Hello World 1"
    14-Dec-2021 16:00:41    "TopMW01"    "Hello World 2"

Programmatically access the first message.

mqttMsg.Data(1)
ans = 

    "Hello World 1"

Input Arguments

collapse all

MQTT client specified as an icomm.mqtt.Client object, created with the mqttclient function.

Example: mqttClient = mqttclient()

Data Types: object

MQTT topic to read messages from, specified as a string or character vector.

Example: "trubits/mqTop48"

Data Types: string | char

Output Arguments

collapse all

Messages read from MQTT topics, returned as a timetable of messages.

Version History

Introduced in R2022a

See Also

Functions