ApplicationEdge 1.0.0

MQTT Trigger Node

The MQTT Trigger fires a workflow whenever a message is published to a topic of your choosing on the Losant MQTT broker, Edge Agent Broker (edge only), or an MQTT Integration.

MQTT Trigger

Node Properties

There are two properties that can be configured for the MQTT Trigger:

Broker

You can specify the MQTT broker that triggers the workflow. By default, this is the Losant MQTT broker, but you can also choose the Edge Agent Broker (edge only) or an MQTT Integration.

In Edge Agent versions 1.17.0 or higher, the Edge Agent’s local MQTT broker is available as an option. You can learn more in the Edge Agent broker documentation.

MQTT Topic

When the trigger is configured to use the default Losant MQTT broker, you must also define a single topic on which the workflow should trigger when a message is published to that topic. This must be a valid MQTT topic, and furthermore, it cannot be an MQTT system topic, or a Losant-specific topic.

MQTT Trigger Config

In the above example, the workflow will trigger whenever any message is published to the Losant broker on the MQTT topic “alerts/power”.

Single-level and multi-level wildcard topics such as custom/+/temperature or custom/# are valid when using the MQTT Trigger Node in Application Workflows, but are not able to be used when using the Losant Broker and MQTT Trigger Node on the Edge Agent.

Payload

The payload will include the MQTT message on the data field, as well as the standard workflow payload information. The triggerType will be “mqttTopic” when using the Losant broker, and “integration” when using one of your integrations.

Note: Incoming messages to custom topics will come in as raw text. If sending a message as a JSON object, it is recommended to use a JSON Decode Node to turn the raw text to a JSON Object.

Cloud Broker

When triggering from the Losant broker, the value of data for the MQTT Trigger will be a string (unlike most other triggers, where the value of the data field is an object).

In the general case, an MQTT workflow payload triggered by the Losant broker will look like the following:

{
  "time": <time of the message>,
  "data": <the mqtt message payload as a string>,
  "applicationId": <id of the current application>,
  "applicationName": <name of the current application>,
  "triggerId": <id of the mqtt trigger>,
  "triggerType": "mqttTopic",
  "flowId": <id of the current workflow>,
  "flowName": <name of the current workflow>,
  "globals": <object of workflow globals>
}

MQTT Integration

An MQTT workflow payload triggered by a MQTT Integration will look like the following:

{
  "time": <time of the message>,
  "data": {
    "message": <the mqtt message payload as a string>,
    "topic": <the topic the message was published on>
  },
  "applicationId": <id of the current application>,
  "applicationName": <name of the current application>,
  "triggerId": <id of the mqtt integration>,
  "triggerType": "integration",
  "flowId": <id of the current workflow>,
  "flowName": <name of the current workflow>,
  "globals": <object of workflow globals>
}

Edge Broker

An MQTT workflow payload triggered by the Edge Agent’s local broker will also include the client’s clientId.

The payload will look like the following:

{
  "time": <time of the message>,
  "data": {
    "clientId": <unique identifier of the publishing client>,
    "message": <the mqtt message payload as a string>,
    "topic": <the topic the message was published on>
  },
  "applicationId": <id of the current application>,
  "applicationName": <name of the current application>,
  "triggerId": <id of the mqtt integration>,
  "triggerType": "integration",
  "flowId": <id of the current workflow>,
  "flowName": <name of the current workflow>,
  "globals": <object of workflow globals>
}

If the published message is coming from the local broker itself, clientId will be omitted from the data.