def
func:mqttPublish
mqttPublish(conn, topic, payload, cfg: {})
Publish an MQTT message to the given topic on the broker. Currently, the payload of the message must be a Str.
The following configuration options are supported:
mqttQos: The quality-of-service to use for publishing the message. If not specified, then QoS0is used. SeemqttQos.mqttRetain: Should the message be retained on the broker (true|false). If not specified, thenfalseis used. SeemqttRetain.mqttExpiryInterval: Sets the expiry interval for the message as a Duration. This is only supported in MQTT 5.mqttUserProps: A Dict of user properties to include in the message. This is only supported in MQTT 5.
read(@mqttConn).mqttPublish("/test", "{a: a JSON object}", {mqttQos: 2, mqttExpiryInterval: 30min, mqttUserProps: {key: "value"}})