Using local environment variables with MQTT nodes

You can find the values that were used by the MQTTSubscribe and MQTTPublish nodes to process the MQTT message. You can also use fields in the local environment to dynamically alter the behavior of the MQTTPublish node.

These fields are available in the following message tree structures:

LocalEnvironment fields

When you use the MQTTSubscribe node, it stores information that you can access in the LocalEnvironment.MQTT.Input message tree. The fields in this structure are described in the following table.
Table 1. List of elements in the LocalEnvironment.MQTT.Input subtree
Element Name Element Data Type Description
Duplicate CHARACTER Whether the message is a duplicate of a previous message. Set to TRUE or FALSE.
Retained CHARACTER Whether the message is a retained message. Set to TRUE or FALSE. Retained is set to TRUE if the message was kept by the server and is now being sent when the client first connects to the server.
Topic CHARACTER The name of the MQTT topic the received message was published to.
QualityOfService CHARACTER Quality of service of the received message. Set to 0 (at most once), 1 (at least once), or 2 (exactly once).
This structure is populated with each message written to the Out terminal of the MQTTSubscribe node.

LocalEnvironment.Destination fields

When you use the MQTTPublish node, you can override certain properties with elements in the LocalEnvironment.Destination.MQTT.Output message tree. The fields in this structure are described in the following table.
Table 2. List of elements in the LocalEnvironment.Destination.MQTT.Output subtree
Element Name Element Data Type Description
retained CHARACTER Whether the message is a retained message. Set to TRUE or FALSE. The default is FALSE. Set to TRUE if the message for a topic must be held by the MQTT server after delivery to all currently connected clients, and then delivered to new clients when they connect to that topic. Each retained message for a topic replaces the previous retained message for that topic. In this way, devices can receive the most recent retained message immediately on connecting to a topic.
TopicName CHARACTER The name of the MQTT topic the message will be published to.
qos CHARACTER Quality of service of the published message. Set to 0 (at most once), 1 (at least once), or 2 (exactly once).
URL CHARACTER The URL that is used to connect to the MQTT server. The URL includes the protocol, the host name, and the port. For example:
tcp://myMQTTserver.com:1883
or, if the connection is encrypted:
ssl://myMQTTserver.com:8883
If set, the value of the URL property takes precedence over the values of the following MQTT message flow node properties:
  • Host name
  • Port
  • Use SSL

LocalEnvironment.WrittenDestination fields

When you use the MQTTPublish node, it stores information that you can access in the LocalEnvironment.WrittenDestination.MQTT message tree. The fields in this structure are described in the following table.
Table 3. List of elements in the LocalEnvironment.WrittenDestination.MQTT subtree
Element Name Element Data Type Description
ClientId CHARACTER The unique name of the client.
DeliveryToken.isComplete BOOLEAN Whether the message was successfully published to the MQTT topic. Set to TRUE or FALSE.
This structure is populated with each message written to the Out terminal of the MQTTPublish node.