MQTT Publish Receive

The MQTT Publish Receive event subscribes to a topic for MQTT publishes being sent on the MQTT device's MQTT connection. The MQTT Publish Receive event will listen on a specific topic being published by the MQTT broker.

Defining a MQTT Publish Receive event trigger

To define a MQTT Publish Receive event trigger, follow these steps:

  1. From the Workbench left pane, expand the node where you want to define the MQTT Publish Receive event trigger.
  2. Click Project to display the Projects window.
  3. Right-click a specific project to display its short cut menu, and then select New.
    It is also possible to click New button at the bottom of the Projects window when a specific project has already been selected.
  4. The new Trigger window appears.
    Name the trigger. The trigger name can be up to 64 characters and include letters, numbers, and the underscore character. Spaces are allowed.
  5. From the Event tab, select the Trigger Event Type down-arrow, expand the Networking category, and then select MQTT Publish Receive.

    The Event tab becomes active with parameters that accommodate the MQTT Publish Receive event.
Parameter Description
MQTT Client The MQTT device that represents the MQTT connection to use for this subscription. The list contains the MQTT devices on this gateway.
Topic Filter An expression is used to specify one or more topic names the subscription should filter on when subscribing to publishes from the MQTT broker.

This expression can include wildcard characters to filter on. This field is required and supports a String up to 65535 bytes.

Wildcard characters '+' and '#' are supported as follows:

  1. The '#' is a wildcard character that matches any number of levels within a topic, referred to as the multi-level wildcard.
    1. The multi-level wildcard character must be specified either on its own or following a topic level separator, where a topic level separator is a '/' character.
    2. The multi-level wildcard must be the last character specified in the Topic Filter.
    3. The multi-level wildcard includes the parent level.
    4. The multi-level wildcard can be specified alone and will subscribe to all messages.
    5. Usage examples:
      • "sport/tennis/player1/#" matches "sport/tennis/player1", "sport/tennis/player1/ranking", "sport/tennis/player1/score/wimbledon"
      • "sport/#" also matches the singular "sport", since # includes the parent level.
      • "#" is valid and will receive every application message.
      • "sport/tennis/#" is valid.
      • "sport/tennis#" is not valid.
      •  sport/tennis/#/ranking" is not valid.
  2. The '+' is a wildcard  that matches only one topic level, referred to as the single-level wildcard.
    1. The single-level wildcard can be used at any level in the Topic Filter, including first and last levels.
    2. The single-level wildcard must occupy the entire level of the filter.
    3. The single-level wildcard matches only a single level.
    4. Usage examples:
      • “sport/tennis/+" matches "sport/tennis/player1" and "sport/tennis/player2" but not "sport/tennis/player1/ranking".
      • "sport/+" does not match “sport” but it does match “sport/” due to the single level matching restriction.
      • "+" is valid.
      • "+/tennis/#" is valid.
      • "sport+" is not valid.
      • "sport/+/player1" is valid.
      • "/finance" matches "+/+" and "/+", but not "+".
Quality of Service Quality of service (QoS) that is used to send the publish. Default is set to 0.
  1. QoS 0: The defined behavior for QoS 0 is that an acknowledge for a subscribed topic is not expected from the gateway when the subscribed topic data is sent from the MQTT broker.
  2. QoS 1: The defined behavior for QoS 1 is that an acknowledge for a subscribed topic is expected from the gateway when the subscribed topic data is sent from the MQTT broker.
  3. QoS 2: The defined behavior for QoS 2 is that an acknowledge for the publish is returned from the server. The trigger then sends a message to the server to release the message for publishing. The server will acknowledge that request. All these steps must be performed for the action to be successful.
Payload Type Type of payload to receive, either String or Binary. The default is String.

MQTT Publish Receive event type trigger event variables

The input event variables available to a MQTT Publish Receive event trigger are:

Event variable Data type Description
Topic STRING The topic name of the incoming publish.  
Payload STRING or BINARY The payload of the incoming publish. The data type depends on the option selected for the  Payload Type parameter.
Payload Length UINT4 The length of the Payload for the incoming publish.

Related Topics Link IconRelated Topics