Main Content

WiFi MQTT Subscribe

Receive messages from message queuing telemetry transport (MQTT) broker

Since R2022b

Add-On Required: This feature requires the Simulink Support Package for Arduino Hardware add-on.

  • Block icon for Arduino WiFi MQTT Subscribe

Libraries:
Simulink Support Package for Arduino Hardware / WiFi

Description

Use the WiFi MQTT Subscribe block to receive messages from the message queuing telemetry transport (MQTT) broker on the specified topic.

Note

The WiFi MQTT Subscribe block supports MQTT over TCP/IP sockets only.

The WiFi MQTT Subscribe block supports these hardware boards.

  • Arduino MKR WiFi 1010

  • Arduino MKR 1000

  • Arduino Nano 33 IoT

  • Arduino® compatible ESP32 – WROOM board

  • Arduino compatible ESP32 – WROVER board

Ports

Output

expand all

The block outputs 1 if the client receives a new message since the last sample time. Otherwise, the block outputs 0.

Data Types: Boolean

The block outputs the message received from the MQTT broker as an array of ASCII characters.

Data Types: uint8

The block outputs ASCII values corresponding to the topic name of the received message. For example, if the topic of the received message is model/data, the port outputs the topic as 109 111 100 101 108 47 100 97 116 97.

To convert the ASCII values into their alphanumeric equivalent, attach an ASCII to String block to the output of the topic port. A topic can have a maximum of 128 characters. For information on topics and their structure, see Topics in MQTT.

Dependencies

To enable this port, include a wildcard entry in the Topic parameter. For more information on wildcards in MQTT, see Wildcards in MQTT Topics.

Data Types: uint8

Parameters

expand all

Specify a topic to which the client subscribes. A topic can have a maximum of 128 characters. For information on topics and their structure, see Topics in MQTT.

Specify the length of the data you want to receive at each sample time.

Select this option to print the response from the MQTT broker on the Arduino serial port for each publish request.

Specify how often the client checks for a new message from the broker. When you specify the sample time as -1, the block inherits its sample time based on the context of the block within the model.

Version History

Introduced in R2022b