Plugins / ezrobot / EZMQTT Client

EZMQTT Client

MQTT Client Control for EZ-Builder

Register   Download Plugin

This plugin is version 4, was last modified on 2/18/2017, and is 90,281 Bytes. The author is ezrobot.

Requirements

This plugin requires EZ-Builder for Microsoft Windows PC.

  Get EZ-Builder for Windows

Plugin Details

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.

User-inserted image

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.

Connect
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.

Code:


# If not connected, connect to local MQTT broker
IF (!$MQTTClientStatus)
ControlCommand("EZMQTT Client", Connect, "127.0.0.1")
ENDIF

# Connect to default hostname specified in config
ControlCommand("EZMQTT Client", Connect)




Disconnect
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().

Code:


ControlCommand("EZMQTT Client", Disconnect)




Subscribe
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.
User-inserted image


Publish
Publish specified data to the specified topic. The following commands are...

Code:


# Publish a string to the 'asdf' topic
ControlCommand("EZMQTT Client", PublishString, "asdf", "Hello World")



Code:


# Publish binary array to the 'asdf' topic
defineArray($array, 5)
$array[0] = 1
$array[1] = 2
$array[2] = 3
$array[3] = 4
$array[4] = 5
ControlCommand("EZMQTT Client", PublishBinary, "asdf", "$array")



Code:


# 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 EZ-Builder project that demonstrates the MQTT Client connecting to a local MQTT Broker: testmqttclient.EZB