Publish messages to MQTT broker on specified topic
Simulink Support Package for Raspberry Pi Hardware / Internet Of Things
The MQTT Publish block publishes messages from your hardware (publisher) to the Message Queuing Telemetry Transport (MQTT) broker on the specified topic.
The block has a Message input port and a Status output port. The Message port accepts the message to be published to the broker. The Status port outputs the status of the publish request. The string topic/level on the block icon is specified by the Topic parameter.
For more information on MQTT, see Publish and Subscribe to MQTT Messages.
The MQTT Publish block supports MQTT only over TCP/IP sockets.
Message — Message to be published
The message to be published to the MQTT broker, specified as a vector.
Status — Status code from MQTT broker
The status code issued by the MQTT broker in response to the publish request. If
the broker accepts the message for publishing, the port outputs
Any nonzero output indicates that the broker has rejected the message. A message can
be rejected for various reasons, such as an incorrect user name or password or an
unacceptable protocol version. For more information on status codes from MQTT brokers,
see MQTT Status Codes.
Topic — Topic of the message
topic/level (default) | any valid topic name
Specify a topic on which the message is to be published. A topic can have a maximum of 128 characters. For information on topics and its structure, see Topics in MQTT.
QoS — Levels of QoS
0 (default) |
Quality of Service (QoS) defines the reliability of the message delivery process in MQTT. MQTT provides three QoS levels for message delivery: QoS 0, QoS 1, and QoS 2. The MQTT broker that you are using might not support all three levels of QoS. For example, ThingSpeak™ MQTT supports only QoS 0.
Select a QoS level from the list:
0: The publisher sends the message to the MQTT broker once. The broker does not send an acknowledgment of the receipt.
1: The publisher sends the message to the MQTT broker at least once. The publisher resends the message if it does not receive an acknowledgment from the broker.
2: The publisher sends the message to the MQTT broker exactly once. The publisher and broker exchange acknowledgments to ensure that the message is received only once.
For more information on QoS levels, see QoS Level for Publish.
Retain message — Option to send message to new subscribers
off (default) |
The Retain message parameter controls how new subscriptions are handled:
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 known message published on a topic.
off–– When a new subscription is made to a topic, the subscriber must wait until the publisher sends the next message.