Documentation

mqtt.to() function

Flux 0.40.0+

The mqtt.to() function is experimental and subject to change at any time. By using this function, you accept the risks of experimental functions.

The mqtt.to() function outputs data to an MQTT broker using MQTT protocol.

import "experimental/mqtt"

mqtt.to(
  broker: "tcp://localhost:8883",
  topic: "example-topic",
  message: "Example message",
  qos: 0,
  clientid: "flux-mqtt",
  username: "username",
  password: "password",
  name: "name-example",
  timeout: 1s,
  timeColumn: "_time",
  tagColumns: ["tag1", "tag2"],
  valueColumns: ["_value"]
)

Parameters

broker

The MQTT broker connection string.

topic

The MQTT topic to send data to.

message

The message or payload to send to the MQTT broker. The default payload is an output table. If there are multiple output tables, it sends each table as a separate MQTT message.

When you specify a message, the function sends the message string only (no output table).

qos

The MQTT Quality of Service (QoS) level. Values range from [0-2]. Default is 0.

clientid

The MQTT client ID.

username

The username to send to the MQTT broker. Username is only required if the broker requires authentication. If you provide a username, you must provide a password.

password

The password to send to the MQTT broker. Password is only required if the broker requires authentication. If you provide a password, you must provide a username.

name

(Optional) The name for the MQTT message.

timeout

The MQTT connection timeout. Default is 1s.

timeColumn

The column to use as time values in the output line protocol. Default is "_time".

tagColumns

The columns to use as tag sets in the output line protocol. Default is [].

valueColumns

The columns to use as field values in the output line protocol. Default is ["_value"].

Examples

Send data to an MQTT endpoint

import "experimental/mqtt"

from(bucket: "example-bucket")
  |> range(start: -5m)
  |> filter(fn: (r) => r._measurement == "airSensor")
  |> mqtt.to(
    broker: "tcp://localhost:8883",
    topic: "air-sensors",
    clientid: "sensor-12a4",
    tagColumns: ["sensorID"],
    valueColumns: ["_value"]
  )

Upgrade to InfluxDB Cloud or InfluxDB 2.0!

InfluxDB Cloud and InfluxDB OSS 2.0 ready for production.