content/flux/v0/stdlib/experimental/mqtt/publish.md
mqtt.publish() sends data to an MQTT broker using MQTT protocol.
(
broker: string,
message: string,
topic: string,
?clientid: string,
?password: string,
?qos: int,
?retain: bool,
?timeout: duration,
?username: string,
) => bool
{{% caption %}} For more information, see Function type signatures. {{% /caption %}}
({{< req >}}) MQTT broker connection string.
({{< req >}}) MQTT topic to send data to.
({{< req >}}) Message to send to the MQTT broker.
MQTT Quality of Service (QoS) level. Values range from [0-2].
Default is 0.
MQTT retain flag. Default is false.
MQTT client ID.
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 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.
MQTT connection timeout. Default is 1s.
import "experimental/mqtt"
mqtt.publish(
broker: "tcp://localhost:8883",
topic: "alerts",
message: "wake up",
clientid: "alert-watcher",
retain: true,
)
import "experimental/mqtt"
import "sampledata"
sampledata.float()
|> map(
fn: (r) =>
({r with sent:
mqtt.publish(
broker: "tcp://localhost:8883",
topic: "sampledata/${r.id}",
message: string(v: r._value),
clientid: "sensor-12a4",
),
}),
)