MQTTClient communication driver

 

The MQTTClient communication driver is a communication driver for sending and receiving messages using the MQTT protocol.

It supports MQTT Subscribe functionality with the read settings and MQTT Publish functionality with the write settings described below.

 

Note:   1. The paho-mqtt3as.dll file must be placed in the folder where PLC_SCAN.exe is located or in the PROTOCOL folder. (EPL-2.0 license)  (Default deployment from Autobase 10.3.6.21)

2.  The ssleay32.dll and libeay32.dll files must be placed in the folder where PLC_SCAN.exe is located. (Default deployment from Autobase 10.3.6.21)

3. The msvcp90d.dll file must be placed in the PROTOCOL\Microsoft.VC90.DebugCRT folder. (Default deployment from Autobase 10.3.6.21)

    >> Go to MQTTClient communication driver related installation folder

4. Visual C++ Redistributable Package for Visual Studio 2015 (vc_redist.x86.exe) must be installed.
      https://www.microsoft.com/en-us/download/details.aspx?id=48145

1. Read Settings

<Figure 1> shows an example of editing a communication file using the MQTTClient communication driver. 

<Figure 1> Read setting example of MQTTClient driver.

In <Figure 1>, edit the communication file of the MQTTClient communication driver according to the following information:

Device : None.

ReadCycle : Set as short as possible (less than 1 second) as message reception count update, error occurrence, and connection status check are performed every read cycle. 

                        Message reception is done in a separate thread, so it is stored in memory immediately upon reception regardless of the read cycle.

WriteCycle : Set as short as possible as message publishing occurs every write cycle.

Read Timeout : Set between 2 seconds and 60 seconds as this is the retry interval for reconnection when connection fails.

Write Timeout : Not used.

 

Also, enter the host and port of the MQTT Broker to connect to in the options section, separated by a comma (,).

Note:  The default value is broker.mqtt-dashboard.com, 1883.

(This address is HIVEMQ's public MQTT Broker, so all topics and message contents are public.)

 (Use this address for testing purposes and change it to your own server address or self-built MQTT Broker address in the field.)

 

MQTTClient communication drvier read schedule

The read request for the MQTTClient communication driver is written as 'READ' only.

 

Read setting example)

READ,

 

Clicking the  icon in the protocol options section of <Figure 1 > brings up the dialog box in Figure 2, where you can write a list of topics to subscribe to.

 

Subscribe Items are entered by separating the Topic, Quality of Service (QoS), and SaveBufferAddress with commas (,).

The created subscription list is saved in the form of "\SCAN\SUBSCRIBE%03d.txt" and subscription starts all at once when communication begins.

 If topics in the subscription list are duplicated, the read message is stored in the memory address of the first written order.

Wildcard characters (+, #) are not supported.

You can also write the MQTT Broker Host, Port, Username, and Password to connect to.

 

Additionally, you can specify the MQTT Broker Host, Port, SSL usage, and SSL certificate paths (CA File, Cert File, privateKey), Username, and Password.

Host: The host of the MQTT Broker to connect to.

Port: The port of the MQTT Broker to connect to.

Use SSL: Whether to use TLS/SSL for the connection.

CA File: Path to the server's CA certificate (leave blank if not used).

Cert File: Path to the client's certificate (leave blank if not used).

Private Key: Path to the client's private key (leave blank if not used).

Username: Client ID (leave blank if not used).

Password: Client password (leave blank if not used).

<Figure 2> Example of MQTTClient communicatoin driver's Option dialogue box.

The values read by the MQTTClient communication driver are stored in WORD/DWORD/FLOAT/DOUBLE/STRING memory with the same value (only the storage format is different).

However, if the received message exceeds 255 characters, the message is stored in the "[Project Path]\SCAN\MQTT[Topic Name].txt" file.

(The slash (/) character in the topic name is replaced with an underscore (_).)

And the path name is stored in the memory (STRING) location to be saved.

 

 

2. Write Settings

You can use the MQTT Publish function with the write settings of the MQTTClient driver.

 

2-1. Digital Write

Digital write function is not supported.

 

2-2. Analog Write

The analog output tag settings for analog write are as follows:

1) Port: Connected communication port number. (Not COM number)

2) Station: Whether to use the retain function. (0 or 1)

3) Address: Not used.

4) Extra1: Topic name to publish

5) Extra2: QoS (Quality of Service) (Choose from 0, 1, 2)

 

Example 1)

PORT: 0,  STATION: 1,  ADDRESS: 0,  EXTRA1: Autobase/gr1/AI_0000,  EXTRA2: 1. 

If you set analog output to 10, it publishes Topic: Autobase/gr1/AI_0000, Value: 10. (Retain function used)

 

Example 2)

@PlcScanWriteWord(0, 1, 0, "my/test/topic1", 0, 1.1);     // Publishes Topic: my/test/topic1, Value: 1.1 (Retain ON)

 

Example 3)

@PlcScanWriteWord(0, 0, 0, "Autobase/gr1/DI_0000", 0, $DI_0000);    // Publishes Topic: Autobase/gr1/DI_0000, Value: [$DI_0000 value] (Retain OFF)

 

2-3. Block Write (String message publishing)

Block write is set using the @PlcScanWriteBlock function in the script as follows:

Script name and format: @PlcScanWriteBlock(int port, int station, int address, string extra1, int extra2, object array_value, int array_size);

 

In the MQTTClient driver, it operates in the following format:

@PlcScanWriteBlock(int port, int retain, 0, string topic, int QoS, object array_value, int array_size);

   

Example 1)

@strcpy(buf, "Test Value");

size = @strlen(buf);

@PlcScanWriteBlock(0, 1, 0, "my/test/topic1", 0, buf, size);    // Publishes Topic: my/test/topic1, Message: Test Value (Retain ON)

 

Example 2)

@strcpy(buf, $ST_0000);
size = @strlen(buf);
@PlcScanWriteBlock(0, 0, 0, "Autobase/Alarm/msg1", 0, buf, size);   // Publishes Topic: Autobase/Alarm/msg1, Message: [Value of string tag $ST_0000] (Retain ON)