Documentation search search close
CONTENTS
https://www.speedgoat.com/help/slrt/page/icon_documentation.jpg
v10.0.1.x for R2026a
View other versions

MQTT - Client Subscribe

MQTT - Client Subscribe — Subscribes to an MQTT topic and outputs its value

Library

Simulink Real-Time - Speedgoat

Description

The Subscribe block subscribes to a topic the remote broker provides and outputs the topic's data received. The block sends the subscription request for the topic once a connection to the broker is established. The broker passes data to the Subscriber each time the Publisher has updated the topic in the broker.

Ports

Outputs
Data

Outputs the current value of the topic subscribed. The port inherits the data type and the dimensions from the Init Value parameter. The data type and dimensions do not both need to match the data type and dimensions of the topic in the broker, but the overall number of bytes must be equal to or greater than the size of the topic. The block outputs the number of bytes received (padded by zeros), or truncates the data if it exceeds the port size. The Length output port outputs the actual number of bytes received.

Data type: Fundamental data types from Boolean to double are supported as well as dimensions from scalar values to vectors.

Status

A rising or falling edge indicates an updated Data output port

Data type: uint32

Length

Outputs the number of data bytes received. The value will always at the most be the size of the Data output port.

Data type: uint32

Inputs

This block does not have any input ports.

Parameters

Station ID

Apply the Station ID of the corresponding Setup block. Must range between 0 and 65535.

Connection ID

Apply the Connection ID of the corresponding Connection block. Must range between 0 and 65535.

Topic

The topic whose data you want to receive. Topic is a character array.

Use the / character to build paths and address specific topic levels. Examples:

Subscribe to topic 'attribute7' of parent topic 'group0/port3':

'group0/port3/attribute7'

Subscribe to topic level 'port3' of parent topic 'group0':

'group0/port3'
[Note]Note

Wildcard characters, such as + and # are not supported.

Quality of Service

The Quality of Service is a flag in the subscription message and tells the broker on how to quarantee the delivery of messages.

  • 0 - at most once: The Subscriber does not confirm the receipt of a data message and the message is not retransmitted by the broker. This level allows the Subscriber to immediately procees the message received and allows the broker not to have to preserve messages for retransmission.

  • 1 - at least once: The Subscriber confirms the receipt of a data message by sending an acknowledge to the broker. If the broker does not receive a confirmation in a specific amount of time, the same data message is transmitted again.

  • 2 - exactly once: The Subscriber confirms the receipt of a data message twice using a 4-way handshake. If the broker does not receive the confirmation in a specific amount of time, the same data message is transmitted again. This level increases the overall time for processing data messages but ensures that the same data is not processed multiple times.

Init Value

The value that the Data port outputs before a data frame is received. The parameter's data type and dimensions define the data type and dimensions of the Data output port and specify the length of the requested data. Fundamental data types from Boolean to double are supported as well as 1D-arrays.

Extended Interface

If selected, the block shows the Status and the Length output ports. Otherwise, the ports are hidden.

Sample Time

Defines the base sample time at which this driver block gets its sample hit. This parameter can also be set to -1 for inherited sample time. The units are in seconds.