You have been redirected from an outdated version of the article. Below is the content available on this topic. To view the old article click here.

MQTTClient

MQTTClient is a specialization of the MessageClient included in the Messaging-Engine Module module.

The MQTTClient connects to a MQTT broker and handles the publication as well as subscription of messages.

MQTTClient extends MessageClient and provides the following additional properties.

Name Type Description
protocol String Protocol used for the MQTT connections. Default: tcp://
url String The URL for the MQTT connection
port Integer The port to connect to
qos Integer Quality of Service Range: 0~2
isEnabled Boolean A boolean value that indicates whether this MQTTClient is enabled (should connect to the broker)
isConnected Boolean A boolean value that indicates whether this MQTTClient is connected to the broker

Search results for "MQTTClient"

MQTTClient

MQTTClient is a specialization of the MessageClient included in the Messaging-Engine Module module.

The MQTTClient connects to a MQTT broker and handles the publication as well as subscription of messages.

MQTTClient extends MessageClient and provides the following additional properties.

Name Type Description
protocol String Protocol used for the MQTT connections. Default: tcp://
url String The URL for the MQTT connection
port Integer The port to connect to
qos Integer Quality of Service Range: 0~2
isEnabled Boolean A boolean value that indicates whether this MQTTClient is enabled (should connect to the broker)
isConnected Boolean A boolean value that indicates whether this MQTTClient is connected to the broker

Step 3: Create MQTTClient and MessageSubscriber

In our structr instance we navigate to the data section and select the type MQTTClient.

We create a new object with the following attributes (the default settings for RabbitMQ)

mainBrokerURL = 'ws://localhost:15675/ws'
username = 'guest'
password = 'guest'

Afterwards we check the isEnabled checkbox which triggers the client to connect to the server. If everything is configured properly it will blink green - otherwise it will blink red and result in an error.

Then we select the type MessageSubscriber and create a new MessageSubscriber with the following attributes:

topic = '*'
callback = "{ $.log($.topic, ': ', $.message) }"

This instructs the subscriber to listen to any topic and simply log the messages to the server log. We could also forward the messages to any global schema method - for example handleIncomingMQTTMessage like this:

{
  $.call('handleIncomingMQTTMessage', { topic: $.topic, message: $.message });
}

Step 2: Install RabbitMQ Web MQTT plugin

KafkaClient