MQTT Client Control for ARC that can also work with the server
+ How To Add This Control To Your Project (Click to Expand)
- Make sure you have the latest version of ARC installed.
- Select the Get button in this page to download the archive file.
- Double click the downloaded archive file to execute installer.
- The installer will add this control to ARC.
- Load ARC and press the Project -> Add Control button from the menu.
- Choose the Misc category tab.
- Press the EZMQTT Client icon to add the control to your project.
This is an MQTT Client Control that connects to an MQTT broker and subscribes to topics. When messages are published to matching topics, the incoming data will be assigned to a variable and an associated EZ-Script will launch.
MQTT (MQ Telemetry Transport) is a publish-subscribe-based "lightweight" messaging protocol for use on top of the TCP/IP protocol (port 1883). The publish-subscribe messaging pattern requires a message broker. The broker is responsible for distributing messages to interested clients based on the topic of a message.
MQTT defines methods (sometimes referred to as verbs) to indicate the desired action to be performed on the identified resource. What this resource represents, whether pre-existing data or data that is generated dynamically, depends on the implementation of the server. Often, the resource corresponds to a file or the output of an executable residing on the server.
Connects to the hostname of the specified MQTT broker. Either the CONNECT button on the control can be pressed, or a ControlCommand() can be passed. If no parameter is specified in the ControlCommand(), the default value from the config is used. Both examples of specifying a hostname and not are provided below.
# If not connected, connect to local MQTT broker
ControlCommand("EZMQTT Client", Connect, "127.0.0.1")
# Connect to default hostname specified in config
ControlCommand("EZMQTT Client", Connect)
Waits for the MQTT client to finish any work it must do, and for the TCP/IP session to disconnect. This may be executed by pressing the DISCONNECT button on the control, or using the ControlCommand().
ControlCommand("EZMQTT Client", Disconnect)
Subscription to topics are specified in the Config menu of the control. The variable name and script to execute must also be provided. If the data from the published messages are expected to be Binary, then check the Binary box. This will assign the data to an Array of the specified variable. If the Binary checkbox is not checked, the expected data is alphanumeric string.
Publish specified data to the specified topic. The following commands are...
# Publish a string to the 'asdf' topic
ControlCommand("EZMQTT Client", PublishString, "asdf", "Hello World")
# Publish binary array to the 'asdf' topic
$array = 1
$array = 2
$array = 3
$array = 4
$array = 5
ControlCommand("EZMQTT Client", PublishBinary, "asdf", "$array")
# Publish a comma separated list of numeric values, variables and strings to the 'asdf' topic
$x = "Hello"
ControlCommand("EZMQTT Client", PublishBytes, "asdf", $x, 32, "World")
Here is a sample ARC project that demonstrates the MQTT Client connecting to a local MQTT Broker: testmqttclient.EZB