Эта страница является
переводом страницы
MQTT. Перевод выполнен на 100%.
iRidium for MQTT
a set of tools for creating visualization interfaces
The driver is meant to control MQTT equipment. To understand the driver, use the project example:
Description
iRidium for MQTT is a set of tools to create an interface to control Smart home or office on the basis of MQTT equipement. It realizes commands of MQTT protocol.
Supported: MQTT MQisdp and MQTT 3.1.1.
Connection
Control panels (iOS, Android, Windows, Mac) can control BACnet equipment only via MQTT controller.
You can add an MQTT driver by importing from a CSV file or manually filling in the data.
Import from a CSV file (*.csv)
Universal import from CSV File - a capability to import drivers from a table in the CSV format.
You can read more about detailed instructions on creating a CSV file and importing it into IRidium Studio here.
Adding the driver manually
Add MQTT driver to your project from database
- Launch iRidium Studio and create a new iRidium project
- Open Device side panel and choose the MQTT driver
Indicate the controller address in iRidium project otherwise it will not work.
Connection settings
When the driver is added to the project, specify the connection settings.
- Host - IP address
- Port - port
- Login - user's login (if set on the bus)
- Password - user's password (if set on the bus)
- MQTT version - Protocol version on a bus: 3 - old protocol MQ Integrator SCADA Device Protocol (MQisdp), 4 - support for MQTT v 3.1.1,
- Client ID - client identificator
- Keep Alive - timeout for connection in seconds
- Clean - "clean start" flag, deleting any subscriptions after disconnect: true - clean session, false - durable connections
- SSL - turn on/off encription
When SSL/TLS are used only CA signed server certificate can be used. Self signed certificates and CA certificate only are not supported.
In the old studio for the correct work of the driver the Client ID field had to contain the unique ID for each panel.
In the new studio (iRidium Studio 2019) this field is not compulsory.
Change of Connection Settings
You need the possibility to change connection properties when you disconnect from the Wi-Fi network of the automation object and start using 3G or another Wi-Fi network. To maintain control of the object you need to switch from the local to public IP-address of the Internet router.
The switch is not automatic. You have to select the connection mode. For remote acces you have to make ports for controlling the automation system public. In order to do that you have o set up the Port Forwarding service on your Internet router. VPN can provide protected connection.
1 Download the template (*.js) (right-click button: "Save object as ..."), add the template in the script editor with the button
(+) Add Script from file
2 Set up script properties as it is 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 Projeсt Device Panel - the list of properties has to be copied from the example.
3 Select the button which will be responsible for the switch of Internal and External properties. Open Macros Editor for the Press event (Object Properties > Programming), select the Script Call command and add it by double-clicking on it. Select the name of the function which will be activated by the button:
Now each pressing on the button will apply the corresponding connection properties.
Commands & Feedbacks
Commands and feedback channels have to be assigned to graphic items to control equipment:
- A command is assigned to a graphic item.
- Feedback channel is assigned to a graphic item to display the variable state.
To assign commands or channels to graphic items use the drag&drop method.
To send a command, drag it on a graphic item. To display feedback, drag the channel on the graphic item and indicate where to output the value (Value):
Settings
To configure the command or feedback, you must set the following fields:
- Topic is the MQTT path (the max size of data sent to MQTT topic is up to 268435456 bytes);
- Value Type is the value type;
- QoS - quality of service, guarantee that a message is delivered from the publisher to the broker:
- At most once - no more than one time, without repetition, delivery is not guaranteed;
- At least once - one and more times, there can be repetitions, delivery is guaranteed;
- Exactly once - only one time, without repetition, delivery is guaranteed;
- Retain - saving a publication: broker stores the retain topic and when new subscriptions appear sends it to subscribers with a retain flag.
Value Types
| type |
description
|
| Boolean |
logic 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 |
Float 8-bit value
|
| Unsigned 32-bit |
Unsigned 32-bit value
|
| Signed 64-bit |
Signed 64-bit value
|
| Float 64-bit |
Float 64-bit value
|
| Unsigned 64-bit |
Unsigned 64-bit value
|
| String |
String
|
A WB controller, that transmits ZigBee to MQTT, has several values in one topic. It's required to write logic via the script to display these values.
Example:
var device = IR.GetDevice("MQTT");
var topic_value = 0;
var topic_name = "Aqara001"; // the name of a feedback channels as it is written in the driver
IR.AddListener(IR.EVENT_TAG_CHANGE, device, function(name, value) {
if (name == topic_name) {
try {
topic_value = JSON.Parse(value); // a string comes, and it must be transformed into JSON
var humidity = topic_value.humidity; // take only humidity from JSON
var pressure = topic_value.pressure; // take only pressure from JSON
var temperature = topic_value.temperature; // take only temperature from JSON
var voltage = topic_value.voltage; // take only voltage from, JSON
IR.Log("humidity = " + humidity);
IR.Log("pressure = " + pressure);
IR.Log("temperature = " + temperature);
IR.Log("voltage = " + voltage);
}
catch (err) {
IR.Log('Invalid data')
}
}
});