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 (Collect metadata when a custom trigger is fired.), auto_trigger (Collect metadata when significant node properties change.), interval (Collect metadata periodically.), startup (Collect metadata on the first frame of the source.), shutdown (Collect metadata when the deployment shuts down.) | 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) (Send metadata as JSON with dynamic keys. Use certain attributes, e.g. ROI names, as keys. Useful for JSON path operations.), json_static (Send metadata as JSON with static keys. Convert all attributes to a named static key.), custom_body (Send 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 |
| credential_type | Credential Type. Options: username_password, certificate | enum | username_password | No |
| username | Username. Conditional on credential_type being "username_password". | string | null | No |
| password | Password. Conditional on credential_type being "username_password". | string | null | No |
| certificate | Certificate. Conditional on credential_type being "certificate". | text | null | Yes |
| certificate_key | Certificate Key. Conditional on credential_type being "certificate". | text | null | Yes |
| validate_cert | Validate SSL Certificate? | bool | false | No |
| lastwill_message | Lastwill Message | text | null | No |
| lastwill_topic | 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.<topic> | The specific MQTT topic being referenced. |
| topics.<topic>.last_message | The last message received for a topic. |
| topics.<topic>.messages | All messages received for a topic. |
| topics.<topic>.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 3 days ago
