Skip to main content

Message Queuing Telemetry Transport (MQTT)

The mqtt node-type uses [libmosquitto] to publish and subscribe messages via the MQTT protocol. It is similar to the amqp node-type.

Prerequisites​

This node-type requires mosquitto (>= 1.4.15).

Implementation​

The source code of the node-type is available here: https://github.com/VILLASframework/node/blob/master/lib/nodes/mqtt.cpp

Configuration​

Format Object (object) or Format Name (string) (format_spec)
object (Input configuration (received by VILLASnode))
object (Output configuration (sent out by VILLASnode))
username
string

The username which is used for authentication with the MQTT broker.

password
string

The username which is used for authentication with the MQTT broker.

host
required
string

The hostname of the MQTT broker.

port
integer
Default: 1883

The port number of the MQTT broker.

retain
boolean
Default: false

Set to true to make the will a retained message.

keepalive
integer
Default: 5

The MQTT keepalive value.

qos
integer
Default: 0

The quality of service (QoS) to use for the subscription.

object
vectorize
integer
Default: 1

This setting allows to send multiple samples in a single message to the destination nodes.

The value of this setting determines how many samples will be combined into one packet.

Array of Hook Object (object) or Hook Name (string) (hook_list)
builtin
boolean (Builtin hook functions)
Default: true

By default, each node and paths has a couple of default hooks attached to them. With this setting the attachment of built-in hooks can be disabled.

{
  • "format": "villas.human",
  • "in": {
    },
  • "out": {
    },
  • "username": "string",
  • "password": "string",
  • "host": "example.com",
  • "port": 1883,
  • "retain": false,
  • "keepalive": 5,
  • "qos": 0,
  • "ssl": {
    },
  • "vectorize": 1,
  • "hooks": [
    ],
  • "builtin": true
}

Example​

node/etc/examples/nodes/mqtt.conf
nodes = {
mqtt_node = {
type = "mqtt"

format = "protobuf"

username = "guest"
password = "guest"
host = "localhost"
port = 1883

# Send ping every 5 seconds to keep connection alive
keepalive = 5
retain = false
qos = 0

out = {
publish = "test-topic"
}

in = {
subscribe = "test-topic"
}

ssl = {
enabled = false
insecure = true
cafile = "/etc/ssl/certs/ca-bundle.crt"
certfile = "/etc/ssl/certs/my.crt"
keyfile = "/etc/ssl/keys/my.key"
}
}
}