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.
Inputs & Outputs
- Input media: Raw Video.
- Output media: Raw Video.
- Output metadata:
topics, -topic, --last_message, --messages, --topic_delta, any_topic_delta, all_topic_delta.
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 (custom_trigger): Collect metadata when a custom trigger is fired; Auto Trigger (auto_trigger): Collect metadata when significant node properties change; Interval (periodic): Collect metadata periodically; Startup (startup): Collect metadata on the first frame of the source; Shutdown (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. Unit: seconds. | number | 0 | Yes |
format | Message Format. Options: JSON (Dynamic keys) (json): Send metadata as JSON with dynamic keys. Use certain attributes, e.g. ROI names, as keys. Useful for JSON path operations; JSON (Static keys) (json_static): Send metadata as JSON with static keys. Convert all attributes to a named static key; Custom Body (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. | string | {} | 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); MQTT with SSL (mqtts); MQTT over Websocket (ws); MQTT over Websocket with SSL (wss). | 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 and Password (username_password); Certificate (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. | string | null | Yes |
certificate_key | Certificate Key. Conditional on credential_type being certificate. | string | null | Yes |
validate_cert | Validate SSL Certificate? | bool | false | No |
lastwill_message | Lastwill Message | string | 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
The fields below are declared by this node's metadata schema; the JSON values are representative examples.
| Path | Type | Description |
|---|---|---|
nodes.<node_id>.topics.<topic>.topic_delta | boolean | When this topic has one or more new messages |
nodes.<node_id>.topics.<topic>.last_message | string | Last message received for this topic |
nodes.<node_id>.topics.<topic>.messages | array | All messages received for a topic. |
nodes.<node_id>.any_topic_delta | boolean | When any topic has one or more new messages |
nodes.<node_id>.all_topic_delta | boolean | When all topics have one or more new messages |
nodes.<node_id>.type | string | Identifies the node type that produced this metadata. |
JSON example
{
"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
