# 21 MQTT ### Introduction MQTT (short for MQ Telemetry Transport) is an open OASIS and ISO standard (ISO/IEC PRF 20922) lightweight, publish-subscribe network protocol that transports messages between devices. The protocol usually runs over TCP/IP, although its variant, MQTT-SN, is used over other transports such as UDP or Bluetooth. It is designed for connections with remote locations where a small code footprint is required or the network bandwidth is limited. The broker acts as a post office, MQTT doesn’t use the address of the intended recipient but uses the subject line called “Topic”, and anyone who wants a copy of that message will subscribe to that topic. Multiple clients can receive the message from a single broker (one to many capability). Similarly, multiple publishers can publish topics to a single subscriber (many to one). Each client can both produce and receive data by both publishing and subscribing, i.e. the devices can publish sensor data and still be able to receive the configuration information or control commands. This helps in both sharing data, managing and controlling devices. With MQTT broker architecture the devices and application becomes decoupled and more secure. MQTT might use Transport Layer Security (TLS) encryption with user name, password protected connections, and optional certifications that requires clients to provide a certificate file that matches with the server’s. The clients are unaware of each others IP address. The broker can store the data in the form of retained messages so that new subscribers to the topic can get the last value straight away. The main advantages of MQTT broker are: - Eliminates vulnerable and insecure client connections - Can easily scale from a single device to thousands - Manages and tracks all client connection states, including security credentials and certificates - Reduced network strain without compromising the security (cellular or satellite network) Each connection to the broker can specify a quality of service measure. These are classified in increasing order of overhead:
WCC Lite supports MQTT messaging compatible with MQTT v3.1 standard (starting from version **v1.4.0**). Such messaging is possible via mapping of Redis and MQTT data therefore data can be transmitted from any protocol that is supported by WCC Lite.
All standard functions, except for data encryption, are supported. Encrypted messages are not supported yet, therefore to ensure security a user would have to use a VPN service. A user can choose from three different Quality of Service levels, select if messages are to be retained, authenticate users and optionally send Last Will messages. To configure WCC Lite a user can fill in the needed parameters in Excel configuration. These parameters are shown in the two tables below. Table. MQTT parameters for Devices tab**Parameter** | **Type** | **Description** | **Required | **Default value** (when not specified) | **Range** | |
Min | Max | |||||
name | string | User-friendly device name | Yes | |||
device\_alias | string | Device alias to be used in the configuration | Yes | |||
enable | boolean | Enabling/disabling of a device | No | 0 | 0 | 1 |
protocol | string | Selection of protocol | Yes | MQTT | ||
ip | string | MQTT broker IP address selection | Yes | |||
port | integer | MQTT broker port selection | No | 1883 | ||
enable\_threshold | boolean | A parameter to determine if identical values should not be sent multiple times in a row. | No | 1 | 0 | 1 |
gi\_interval\_sec | integer | Parameter to determine how frequently should all values be sent at once. Disabled if equal to 0. | No | 0 | ||
mqtt\_qos | integer | MQTT Quality of Service for message as in standard | No | 0 | 0 | 2 |
mqtt\_retain | boolean | Selecting if MQTT broker should retain last received messages | No | 0 | 0 | 1 |
user | string | MQTT user name | Yes | |||
password | string | MQTT user password | Yes | |||
use\_last\_will | boolean | Selecting if MQTT should use Last Will and Testament functionality (Default: False) | No | 0 | 0 | 1 |
last\_will\_topic | string | Topic to which an MQTT message would be sent if the device abruptly disconnected message broker | Yes (If use\_last\_will=True) | |||
last\_will\_message | string | Message to be sent over MQTT if the device abruptly disconnected message broker | No | |||
last\_will\_qos | integer | MQTT Quality of Service selection as in standard | No | 0 | ||
last\_will\_retain | boolean | Selecting if MQTT broker should retain last will message | No | 0 | 0 | 1 |
**Parameter** | **Type** | **Description** | **Required | **Default value** (when not specified) | **Range** | |
Min | Max | |||||
signal\_name | string | User-friendly signal name | Yes | |||
device\_alias | string | Device alias from a Devices tab | Yes | |||
signal\_alias | string | Unique signal name to be used | Yes | |||
source\_device\_alias | string | device\_alias of a source device | No | |||
source\_signal\_alias | string | signal\_alias of a source signal | No | |||
enable | boolean | Enabling/disabling of an individual signal | No | 1 | 0 | 1 |
log | integer | Allow signal to be logged. Log signal with 1 and no logging with 0. | No | 0 | ||
topic | string | Topic name to override the value built by default | No |
If MQTT Client does not work properly (e.g. no communication between devices, data is corrupted, etc.), a user can launch a debug session from command line interface and find out why link is not functioning properly.
To launch a debugging session, a user should stop `mqtt-client` process and run `mqtt-client` command with respective flags as was shown above.