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

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 (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.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. Unit: seconds.number0Yes
formatMessage 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.enumjsonYes
custom_body_templateUse Jinja2 template syntax to customize the body of the message. Conditional on format being custom_body.string{}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); MQTT with SSL (mqtts); MQTT over Websocket (ws); MQTT over Websocket with SSL (wss).enummqttNo
mqtt_hostMQTT HoststringnullYes
mqtt_portPort number to connect to. Leave blank to use default port based on MQTT Protocol.stringnullNo
credential_typeCredential Type. Options: Username and Password (username_password); Certificate (certificate).enumusername_passwordNo
usernameUsername. Conditional on credential_type being username_password.stringnullNo
passwordPassword. Conditional on credential_type being username_password.stringnullNo
certificateCertificate. Conditional on credential_type being certificate.stringnullYes
certificate_keyCertificate Key. Conditional on credential_type being certificate.stringnullYes
validate_certValidate SSL Certificate?boolfalseNo
lastwill_messageLastwill MessagestringnullNo
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

The fields below are declared by this node's metadata schema; the JSON values are representative examples.

PathTypeDescription
nodes.<node_id>.topics.<topic>.topic_deltabooleanWhen this topic has one or more new messages
nodes.<node_id>.topics.<topic>.last_messagestringLast message received for this topic
nodes.<node_id>.topics.<topic>.messagesarrayAll messages received for a topic.
nodes.<node_id>.any_topic_deltabooleanWhen any topic has one or more new messages
nodes.<node_id>.all_topic_deltabooleanWhen all topics have one or more new messages
nodes.<node_id>.typestringIdentifies 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
    }
  },
}

Did this page help you?