MQTT Publish

Summary

Publishes a message to a MQTT topic.

A message is sent each time an event is received. The broker, topic and text of the message, among other parameters are configured in Settings -> Parameters. Most parameters may take on dynamic values through variable interpolation.

For example, the function could be used to publish a heartbeat message on some regular schedule.

LoLo app where some schedule triggers the MQTT publish function.
Parameters to send

Ports

The in port is used to trigger the sending of a message. When an event is received on this port, the function will establish a connection to the broker, send the message, and finally disconnect.

After a message is successfully published, an event is routed to success.

If an error occurs during the process outlined above, then the process is aborted, and the occured error is routed to the error port. (The connection is always properly closed, even if an error occurs.)

Input/Output Format

The recieved event is assumed to be an object. Variable interpolation in Settings -> Parameters may suppose further assumptions.

On the success port is the received event re-emitted.

In case of an error occurring, the value routed to the error port will be the received event, but with the property mqttErr added on. The purpose of this property is to provide some information about the error that has occured. The value assigned to this property may have any format. In general it is intended to be logged.

Events

This function does not listen to nor emit any events.

Other

If the broker requires authentication, then provide username and password in Settings -> Parameters. Otherwise can the auth field be left empty.

NOTE: authentication credentials are by default sent in plaintext in MQTT. Use a secure transport to protect credentials. The schemes URI mqtts, wss, and tls signifies to establish a secure connection over TLS to the broker.

Examples

Using variable interpolation, dynamic messages are easy to craft.