Main Content

WiFi MQTT Subscribe

Receive messages from message queuing telemetry transport (MQTT) broker

  • Library:
  • Simulink Support Package for Arduino Hardware / WiFi

  • Block icon for Arduino WiFi MQTT Subscribe

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

  • ESP32-WROOM (Arduino Compatible)

  • ESP32-WROVER (Arduino Compatible)

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 (Simulink Support Package for Raspberry Pi Hardware).

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 (Simulink Support Package for Raspberry Pi Hardware).

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 (Simulink Support Package for Raspberry Pi Hardware).

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