MQTT protocol is used for machine to machine (M2M), internet of things (IoT) communication. This publish/subscribe messaging is used where limited device resources are available or network bandwidth is low. The MQTT protocol provides small size, low power usage, minimized data packets, and efficient distribution of information to one or many receivers.
The Stride MQTT Gateway is an industrial 4.0 hardware component (IIoT – Industrial Internet of Things) that provides isolation and can easily interface with existing Modbus RTU and Modbus TCP communication protocols.
We will be connecting a Stride MQTT Gateway to a Click PLC (Ethernet) via Modbus TCP. Previously we connected the Solo process temperature controller with Modbus RTU(RS485). We will leave this connection in place and add the Click PLC. The MQTT Gateway will communicate with HiveMQ Broker. MQTTBox Client will then read and write to the Click PLC and Solo process temperature controller. Let’s get started.
Previously we have discussed the following for MQTT:
Do-More Simulator MQTT Publish / Subscribe – Video
(Designer Simulator Client – HiveMQ Broker – HiveMQ Client)
BRX Do-More PLC MQTT Communications – Video
(BRX Client – Mosquito Broker – MQTTLens)
Stride MQTT Gateway Unboxing Video
Stride MQTT Gateway Modbus RTU TCP – Video
(Solo Process Temperature Controller – Mosquitto Broker – MQTTlens)
Watch the video below to see the MQTT Gateway communicating to our Click PLC and Solo process temperature controller.
We will modify and add to our existing Stride MQTT Gateway program. Using a web browser we will call up the default IP address of our MQTT Gateway. Our user name is admin and the password is accautomation.
Network Interfaces
Select the three dots in the upper left corner and select network interfaces.
Confirm that we have the preferred and alternate DNS servers specified. These were set last time to the Google Domain Name System (DNS) server.
Channels
We will now add another channel to our MQTT Gateway. Select the CHANNELS tab on the main screen.
Select the + symbol.
We will leave the default name on Channel 2. The communication protocol will be set for Modbus TCP. TCP port is left as the default. The IP address is the address of our Click PLC. All of the other selections will be left as their defaults. Select Save.
Finding our Click IP Address
In the click programming software, click on the main menu | Setup | System Configuration…
Our system configuration window will now be displayed.
Click on the CPU unit to display the Com Port Setup Details.
Under the Port1 selection, the RJ45 connector will be displayed and the IP address can be seen along with the subnet mask and default gateway.
Here are our completed channels. Channel 1 – Modbus RTU, Channel 2 – Modbus TCP.
Devices
Select the DEVICES tab.
Select the + symbol.
Our name will be Click on channel 2. Modbus TCP will automatically be shown as the protocol for this channel. The address (Unit No.) will be set as 1.
Select the + symbol.
The read-only will be unselected. Our format will be 1 bit with the variable name of C1. The address will be 16384 and the Modbus function code for read/write is 01 – Read Coil Status and 05 – Force Single Coil. Select OK.
Finding the Click Modbus Address
Select the Address Picker under the Program Tab of the Navigation Window in the Click PLC programming software. Check the display MODBUS address near the bottom of the Address picker window. This will display the modbus address and function codes that can be used. In our case, the C1 modbus address is 16385 – 1 = 16384. This can also be found in the Stride MQTT Gateway manual in appendix A. It will list the Modbus addresses for the Click, Do-More and Productivity series as well.
Check the box beside the RW (read-write) symbol of our C1 variable. Our publish topic will be Click/C1 and this will be published when the value changes. The subscribe topic will be Click/set/C1.
Select the + symbol.
We will add a variable named DS1. This is a 16-bit unsigned integer at modbus address 0. Modbus read function code 03 – Read Holding Registers and modbus write function code 06 – Preset Single Register will be used with this DS1 register in the Click PLC. Select OK.
Finding the DS1 Click Modbus Address
Use the address picker in the click programming software to display the modbus address for the DS1 location. 400001 – 1 = 400000. Since Modbus addresses will have only a five-digit code we will use the address 00000. (0) See the MQTT Gateway manual for a list of all of the modbus addresses for the Automation Direct PLCs.
Check the box beside the RW (read-write) symbol of our DS1 variable. Our publish topic will be Click/DS1 and this will be published when the value changes. The subscribe topic will be Click/set/DS1.
Select the SAVE button.
Our Click device has now been programmed. The green dot beside each of our devices indicates that our communication is good.
MQTT Settings
Select the MQTT tab.
We will change the broker address to broker.hivemq.com. The broker port will be left as the default 1883. This is the address of the public broker at HiveMQ.
Our broker can be found at https://www.hivemq.com/public-mqtt-broker/
Export our MQTT Gateway Configuration
Select the three dots in the upper right corner. Click on the Import / Export configuration.
Select EXPORT to save our configuration to our disk drive.
After the file has been downloaded, a message will appear indicating that the configuration was successfully exported.
Select the three dots again and select LOGOUT. This will end our MQTT Gateway configuration.
Click PLC Program
Our click plc ladder program uses a drum instruction to turn on the six outputs in a pattern. C1 will enable the drum sequence. DS1 contains the current step of the drum instruction.
Here is our Drum Instruction Post. Our entire Click PLC series can be found here.
https://accautomation.ca/series/click-plc/
MQTTBox – MQTT Client
MQTTBox is a free MQTT client. It can be downloaded at the following location.
https://chrome.google.com/webstore/detail/mqttbox/kaajoficamnjijhkeomgfljpicifbkaf
Start MQTTBox. The first thing that we need to do is create a new MQTT client. Select the Create MQTT Client button.
Our MQTT Client Name will be MQTT Gateway. The protocol will be MQTT / TCP and the host will be broker.hivemq.com. Click on save.
Our new client will now appear in a box. This will show the status of our client. Currently, you can see that we are connected.
Click on our MQTT Gateway box.
Here is the main screen for our MQTT Gateway client.
Under the topic to subscribe, we will put in Click\DS. Under the topic to publish, we will put in Click/set/C1. The QoS (Quality of Service) will be left as the default of 0.
The payload type will be Strings / JSON / XML / Characters. Our payload will be 0001 or 0000 depending on if we want to start or stop our Click Drum Instruction.
Here is our completed MQTTBox client working.
The Click PLC Program and Stride MQTT Gateway Configuration can be downloaded here.
Watch the video below to see the MQTTBox client controlling our Click PLC Drum program via the Stride MQTT Gateway.
STRIDE MQTT Gateway Features
– Convert Modbus RTU/TCP to MQTT
– IIoT MQTT protocol with SSL/TLS
– Configurable via a web page
– Hardware watchdog function
– Full electrical isolation
– MQTT cloud compatible with AWS, Mosquitto and more
– Wired or Wi-Fi models available
– CE and FCC agency approvals
Stride MQTT Gateway Specifications
Stride MQTT Gateway Manual
Purchase – Stride MQTT Gateway
Stride MQTT Gateway Firmware Update
Next time we will look at connecting our Stride MQTT Gateway to Adafruit IO broker. We can then graph the PV (present value) and SV (set value) of the Solo Process Temperature Controller in a dashboard. Logging the MQTT data will also take place.
Watch on YouTube: Stride MQTT Gateway Click PLC Modbus RTU TCP
If you have any questions or need further information please contact me.
Thank you,
Garry
If you’re like most of my readers, you’re committed to learning about technology. Numbering systems used in PLC’s are not difficult to learn and understand. We will walk through the numbering systems used in PLCs. This includes Bits, Decimal, Hexadecimal, ASCII and Floating Point.
To get this free article, subscribe to my free email newsletter.
Use the information to inform other people how numbering systems work. Sign up now.
The ‘Robust Data Logging for Free’ eBook is also available as a free download. The link is included when you subscribe to ACC Automation.