iRidi for MQTT
Tools for creating a visualization interface
The driver is designed to control equipment that uses the MQTT protocol. Use the sample project to get started:
download example: *iRidi MQTT
Examples: Connecting Modbus TCP devices to MQTT cloud services Connecting iRidi Server to IBM Watson IoT
Description
iRidi for MQTT is a set of tools for creating an interface to control a home or office based on equipment that uses the MQTT protocol. It implements MQTT protocol commands.
Supported: MQTT MQisdp and MQTT 3.1.1.
Connection
Control panels (iOS, Android, Windows, Mac) can control the equipment only through an MQTT controller.

You can add the MQTT driver by importing a CSV file or entering the data manually.
Importing a CSV file (*.csv)
Universal import from CSV File lets you import drivers from a table in CSV format.
For detailed instructions on creating a CSV file and importing it into iRidi Studio, follow this link.
Adding the driver manually
Add the MQTT driver to the project from the iRidi database:
- Start iRidi Studio and create a new iRidi project;
- Open the Devices side panel and select the MQTT driver.

Specify the controller address in the iRidi project; otherwise, it will not work.
Configuring connection parameters
Configure connection settings after adding the driver.

- Host - controller IP address,
- Port - controller connection port,
- Login - user login (if set on the controller),
- Password - user password (if set on the controller),
- MQTT Version - protocol version on the controller: 3 - legacy MQ Integrator SCADA Device Protocol (MQisdp), 4 - support for MQTT version 3.1.1,
- Client ID - panel identifier,
- Keep Alive - connection keep-alive time in seconds,
- Clean - clean-start flag, which deletes subscriptions when the connection is lost: true - clean session, false - persistent connections,
- SSL - enable/disable encryption.
- SSL/TLS supports only CA signed server certificate; certificates of the types Self signed certificates and CA certificate only are not supported.
- In the old version of Studio, Client ID must contain a unique identifier for each panel for the driver to work correctly. In the new version (iRidi Studio 2019), this field is optional.
Changing connection parameters
You need to change connection parameters when you disconnect from the automation site's Wi-Fi network and start using 3G or another Wi-Fi network. For control to continue working, switch from the local IP address to the Internet router's public IP address.
Switching is not automatic; you need to press the connection mode selection button. For remote access, the automation system's control ports must be made public. To do this, configure Port Forwarding on the Internet router. A VPN can provide a secure connection.
-
Download the template (*.js) (right-click and save the target), then add it to the script editor using (+) Add Script from file
-
Configure the script parameters as shown in the example:
function Internal_1() {
IR.GetDevice('MQTT').SetParameters({Host: "192.168.0.95", Port: 5001, MQTTVersion: "4", ClientID: "client1", KeepAlive: 20, Clean: true, Login: "admin", Password: "admin"});
}
function External_1() {
IR.GetDevice('MQTT').SetParameters({Host: "215.110.10.10", Port: 5001, MQTTVersion: "4", ClientID: "client1", KeepAlive: 20, Clean: true, Login: "admin", Password: "admin"});
}
Copy the driver name from the device panel; copy the parameter list exactly as shown in the example.
- Select the button that will switch between the Internal and External parameters. Open the macros editor for the Press event (Object Properties > Programming), select the Script call command, and double-click to add it. Select the name of the function the button will call:

Each button press now applies the corresponding connection settings.
Commands & Feedbacks
Bind commands and feedback channels to graphical items to control the equipment:
- Bind a command to a graphical item.
- Bind a feedback channel to a graphical item to display the variable's state
To link a command or channel to a graphic item, use drag&drop - dragging an object onto another.
To send a command, drag it onto a graphical item. To display feedback, drag the channel onto a graphical item and specify where to display its Value:

Configuration
Configure a command or feedback by setting these fields:
- Topic - MQTT path (up to 268435456 bytes of data can be sent to an MQTT topic);
- Value Type - value type;
- QoS - quality of service, which guarantees message delivery from the publisher to the broker:
- At most once - at most once, without duplicates; delivery is not guaranteed;
- At least once - one or more times, with possible duplicates; delivery is guaranteed;
- Exactly once - exactly once, without duplicates; delivery is guaranteed.
- Retain - retain the publication: the broker stores the retained topic and sends it to new subscribers with the retain flag.
Value Types
| Type | Description |
|---|---|
| Boolean | Boolean value type (true, false). |
| Signed 8-bit | Signed 8-bit value. |
| Unsigned 8-bit | Unsigned 8-bit value. |
| Signed 16-bit | Signed 16-bit value. |
| Unsigned 16-bit | Unsigned 16-bit value. |
| Signed 32-bit | Signed 32-bit value. |
| Float 32-bit | 32-bit floating-point value. |
| Unsigned 32-bit | Unsigned 32-bit value. |
| Signed 64-bit | Signed 64-bit value. |
| Float 64-bit | 64-bit floating-point value. |
| Unsigned 64-bit | Unsigned 64-bit value. |
| String | String. |
On a WB controller that translates ZigBee to MQTT, a single topic contains several values. To display these values, implement the logic in a script.
Example:
var device = IR.GetDevice("MQTT");
var topic_value = 0;
var topic_name = "Aqara001"; // название фидбэка, как указано в драйвере
IR.AddListener(IR.EVENT_TAG_CHANGE, device, function(name, value) {
if (name == topic_name) {
try {
topic_value = JSON.Parse(value); // приходит строка, поэтому преобразуем в JSON
var humidity = topic_value.humidity; // берём из JSON только влажность
var pressure = topic_value.pressure; // берём из JSON только давление
var temperature = topic_value.temperature; // берём из JSON только температуру
var voltage = topic_value.voltage; // берём из JSON только напряжение
IR.Log("humidity = " + humidity);
IR.Log("pressure = " + pressure);
IR.Log("temperature = " + temperature);
IR.Log("voltage = " + voltage);
}
catch (err) {
IR.Log('Invalid data')
}
}
});