WiFi MQTT Publish
Publish messages to message queuing telemetry transport (MQTT) broker
Simulink Support Package for Arduino Hardware / WiFi
Use the WiFi MQTT Publish block to publish messages from your publisher (hardware) to the MQTT broker on the topic you specify in the Topic parameter.
The WiFi MQTT Publish block supports MQTT over TCP/IP sockets only.
The WiFi MQTT Publish 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
message — Message to publish
Specify the message you want the publisher to publish to the MQTT broker as an
array of ASCII characters of type
status — Status code from MQTT broker
The block outputs the status code issued by the MQTT broker in response to the
publish request. If the broker accepts the message for publishing, the block outputs
1 at this port. The block outputs
0 when the
broker rejects the message. The broker can reject a message for various reasons, such
as an incorrect user name or password or if the message requires a protocol version
that the broker cannot accept.
Broker service — MQTT broker service provider
ThingSpeak (default) |
Select the MQTT broker service provider that receives, filters, and sends messages to the clients.
ThingSpeak— When you specify this option, the MQTT access to your channels is handled by a ThingSpeak™ MQTT broker. To create an MQTT device, follow the steps in Create a ThingSpeak MQTT Device (ThingSpeak).
Other— Specify this option when the MQTT access to your channels is handled by other MQTT public brokers such as HiveMQ®, Mosquitto™, and so on.
Configure the same MQTT broker properties as in the MQTT properties.
Topic — Routing information for MQTT broker
channels/<channelID>/publish (default) | any valid topic name
Specify a topic that the publisher uses to filter messages. A topic can have a maximum of 128 characters. For information on topics and their structure, see Topics in MQTT.
Retain message — Option to send message to new subscribers
off (default) |
Control how the MQTT broker handles new subscriptions.
on— When a new subscription is made to a topic, the broker identifies the message in its database with the matching topic name and sends the message immediately.
The MQTT broker retains only the last published message related to the specified topic.
off— When a new subscription is made to a topic, the subscriber must wait until the publisher sends the next message.
To enable this parameter, set Broker Service to
Update interval (seconds) — Rate of publishing message(s)
60 (default) | scalar
Enter the time interval in seconds to publish message(s) to the MQTT broker.
Print diagnostic messages — Print MQTT broker response on serial port
off (default) |
Select this option to print the response from the MQTT broker on the Arduino serial port for each publish request.
Introduced in R2022b