Publish and Receive MQTT Messages

Send and receive metadata from the pipeline to a MQTT topic at a periodic interval or based on a trigger.

Overview

The Publish and Receive MQTT Messages node allows for sending and receiving metadata from the pipeline to a MQTT topic at a periodic interval or based on a trigger. This integration is useful for applications requiring real-time data exchange and monitoring.

Properties

PropertyDescriptionTypeDefaultRequired
publish_topicMQTT topic to publish to. Use Jinja2 template syntax to customize the topic using metadata.stringnullNo
publish_with_retainIf true, marks all published messages to be retained by MQTT broker.boolfalseNo
trigger_typeWhen to collect metadata. Options: Custom Trigger, Auto Trigger, Interval, Startup, Shutdown.enumauto_triggerYes
triggerSend a MQTT message when this condition evaluates to true. Conditional on trigger_type being custom_trigger.trigger-conditionnullNo
intervalHow frequently to send message. Set to 0 to publish every time metadata is collected.number0Yes
formatMessage Format. Options: JSON (Dynamic keys), JSON (Static keys), Custom Body.enumjsonYes
custom_body_templateUse Jinja2 template syntax to customize the body of the message. Conditional on format being custom_body.text"{}"Yes
subscribe_topicComma separated list of MQTT topics to subscribe to. Use Jinja2 template syntax to customize the topic using metadata. Inserts metadata from topic into node metadata.stringnullNo
sanitize_messagesReplace invalid characters in topic name with underscores so you can use them in trigger conditions.booltrueNo
persist_last_messageIf true, retains latest message in node metadata for each topic.booltrueNo
mqtt_protocolMQTT Protocol. Options: MQTT, MQTT with SSL, MQTT over Websocket, MQTT over Websocket with SSL.enummqttNo
mqtt_hostMQTT Host.stringnullYes
mqtt_portPort number to connect to. Leave blank to use default port based on MQTT Protocol.stringnullNo
usernameUsername.stringnullNo
passwordPassword.stringnullNo
validate_certValidate SSL Certificate?boolfalseNo
lastwill_messageLastwill Message. Jinja2 template syntax to customize the message using metadata.textnullNo
lastwill_topicUse Jinja2 template syntax to customize the topic using metadata.stringnullNo
debugLog Debug Messages?boolfalseNo

Template Syntax

custom_body_template, lastwill_message, lastwill_topic, publish_topic, and subscribe_topic uses Jinja2 Template Syntax for customizing the body of the MQTT message.

Variables available to the template:

VariableDescription
metaFrame metadata. Contains keys like nodes, objects, and other custom metadata inserted by Custom function node.
application_idThe application ID of the deployment that produced this metadata.
application_nameThe application name of the deployment that produced this metadata.
deployment_idThe deployment ID of the deployment that produced this metadata.
deployment_nameThe deployment name of the deployment that produced this metadata.
gateway_idThe gateway ID of the deployment that produced this metadata.
gateway_nameThe gateway name of the deployment that produced this metadata.

Example templates

Static text content:

Text content

Reference specific metadata:

{{ deployment_id }}

Metadata reinserted as is:

{{ meta | tojson }}

Output Metadata

Metadata PropertyDescription
topicsThe MQTT topics subscribed to or published.
topicThe specific MQTT topic being referenced.
last_messageThe last message received for a topic.
messagesAll messages received for a topic.
topic_deltaIndicates if there has been a change in the topic.
any_topic_deltaTrue if any topic has changed.
all_topic_deltaTrue if all topics have changed.

Example JSON