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
Property | Description | Type | Default | Required |
---|---|---|---|---|
publish_topic | MQTT topic to publish to. Use Jinja2 template syntax to customize the topic using metadata. | string | null | No |
publish_with_retain | If true, marks all published messages to be retained by MQTT broker. | bool | false | No |
trigger_type | When to collect metadata. Options: Custom Trigger, Auto Trigger, Interval, Startup, Shutdown. | enum | auto_trigger | Yes |
trigger | Send a MQTT message when this condition evaluates to true. Conditional on trigger_type being custom_trigger. | trigger-condition | null | No |
interval | How frequently to send message. Set to 0 to publish every time metadata is collected. | number | 0 | Yes |
format | Message Format. Options: JSON (Dynamic keys), JSON (Static keys), Custom Body. | enum | json | Yes |
custom_body_template | Use Jinja2 template syntax to customize the body of the message. Conditional on format being custom_body. | text | "{}" | Yes |
subscribe_topic | Comma 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. | string | null | No |
sanitize_messages | Replace invalid characters in topic name with underscores so you can use them in trigger conditions. | bool | true | No |
persist_last_message | If true, retains latest message in node metadata for each topic. | bool | true | No |
mqtt_protocol | MQTT Protocol. Options: MQTT, MQTT with SSL, MQTT over Websocket, MQTT over Websocket with SSL. | enum | mqtt | No |
mqtt_host | MQTT Host. | string | null | Yes |
mqtt_port | Port number to connect to. Leave blank to use default port based on MQTT Protocol. | string | null | No |
username | Username. | string | null | No |
password | Password. | string | null | No |
validate_cert | Validate SSL Certificate? | bool | false | No |
lastwill_message | Lastwill Message. Jinja2 template syntax to customize the message using metadata. | text | null | No |
lastwill_topic | Use Jinja2 template syntax to customize the topic using metadata. | string | null | No |
debug | Log Debug Messages? | bool | false | No |
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:
Variable | Description |
---|---|
meta | Frame metadata. Contains keys like nodes , objects , and other custom metadata inserted by Custom function node. |
application_id | The application ID of the deployment that produced this metadata. |
application_name | The application name of the deployment that produced this metadata. |
deployment_id | The deployment ID of the deployment that produced this metadata. |
deployment_name | The deployment name of the deployment that produced this metadata. |
gateway_id | The gateway ID of the deployment that produced this metadata. |
gateway_name | The 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 Property | Description |
---|---|
topics | The MQTT topics subscribed to or published. |
topics. | The specific MQTT topic being referenced. |
topics..last_message | The last message received for a topic. |
topics..messages | All messages received for a topic. |
topics..topic_delta | Indicates if there has been a change in the topic. |
topics.any_topic_delta | True if any topic has changed. |
topics.all_topic_delta | True if all topics have changed. |
Example JSON
{
"nodes": {
"mqtt1": {
"type": "mqtt",
"topics": {
"topic1": {
"last_message": "message",
"messages": ["message"],
"topic_delta": true
}
},
"any_topic_delta": true,
"all_topic_delta": true
}
},
}
Updated about 1 month ago