Skip to content

Scripting

Artek-MQTT-Pub adds four system.artekmqtt.* functions for publishing to MQTT and checking connections from Ignition scripts.

Where they work

Scope Behavior
Gateway (gateway event scripts, tag event scripts, Perspective scripts) Run directly on the gateway, where the broker connections are.
Designer (Script Console, script and binding editors) Autocomplete and show documentation. Each call is forwarded to the gateway and runs there, so no broker traffic comes from the Designer.
Other client sessions (for example a Vision client) Refused.

Arguments are positional only; keyword arguments are refused.

Functions

Function Returns Notes
system.artekmqtt.publish(connection, topic, payload[, qos[, retain]]) Outcome name: PUBLISHED, QUEUED, REJECTED, NO_CONNECTION or NO_SERVICE The payload is sent as UTF-8. qos defaults to 0 and retain to false. A QoS outside 0 to 2, or an empty topic, is refused.
system.artekmqtt.isConnected(connection) bool True when the named profile has a live broker connection.
system.artekmqtt.getConnectionNames() list of str All connection profile names.
system.artekmqtt.getConnectionStatus(connection) dict state, brokerInUse, connectedSinceEpochMs, reconnectAttempts, lastError and the store-and-forward counters (see Connection status).

connection is the name of a connection profile (see Connections).

Publish outcomes

publish returns PUBLISHED when the message was sent and QUEUED when the broker is unreachable and the message was put in the connection's store-and-forward queue, to be sent when it reconnects. Any other outcome (REJECTED, NO_CONNECTION, NO_SERVICE) means the message was not sent; check the connection name and the connection's status.

QoS 0 messages are not queued while disconnected (see Store-and-forward). On the standby node of a redundant pair, publishes are refused rather than queued (see Security).

Example

if system.artekmqtt.isConnected("SiteBroker"):
    result = system.artekmqtt.publish("SiteBroker", "site/area1/line2/state", "RUNNING", 1, True)
    system.util.getLogger("MyMQTT").info("Publish result: %s" % result)

Receiving messages in a script

Artek-MQTT-Sub has no system.* functions. To run a script when a message arrives, configure a script callback on the subscription (see Script callbacks).