BRX Do-More Simulator MQTT Publish Subscribe

MQTT stands for Message Queuing Telemetry Transport. It is a simple publish and subscribe communication protocol that does not take too many resources.
Constrained devices with low bandwidth are ideal for MQTT. This protocol provides machine to machine (M2M) connectivity which is ideal for the Internet of Things (IoT) or Industrial Internet of Things. (IIoT)
BRX Do-More Simulator MQTT Publish Subscribe
We will be using a free on-line public MQTT broker from HiveMQ. Messages will be published and subscribed to by two clients. The first will be an MQTT Browser Client by HiveMQ. The Do-More Designer Simulator PLC will be the second MQTT Client. Information in the form of bits and words will be published and sent to both clients. Let’s get started.


Previously in this BRX series PLC, we have discussed:
System HardwareVideo
Unboxing – Video
Installing the SoftwareVideo
Establishing CommunicationVideo
Firmware Update – Video
Numbering Systems and AddressingVideo
First ProgramVideo
Monitoring and Testing the ProgramVideo
Online Editing and Debug ModeVideo
TimersVideo
CountersVideo
High-Speed IOVideo
Compare InstructionsVideo
Math InstructionsVideo
Program ControlVideo
Shifting InstructionsVideo
Drum InstructionVideo
Serial Communication – Modbus RTU to Solo Process Temperature ControllerVideo
Data LoggingVideo
Email – Text SMS Messaging GmailVideo
Secure Email Communication Video
AdvancedHMI Communication – Modbus TCPVideo
Analog IO – System ConfigurationVideo
HTTP JSON InstructionsVideo
Analog Dusk to Dawn ProgramVideo
INC DEC 512 Registers for DMX512Video
PID with PWM OutputVideo
PID Ramp Soak ProfileVideo

Our entire series can be found here.
The programming software and manuals can be downloaded from the Automation Direct website free of charge.

Watch the video below to see the BRX Do-More Simulator MQTT Publish-Subscribe Communications in action.

MQTT

MQTT was invented by Dr. Andy Stanford-Clark and Arlen Nipper in 1999. It was invented to connect oil pipelines telemetry systems over satellite. MQTT is one of the main protocols for IoT (internet of things) deployments.
MQTT Organization website will provide various news, documents, software and other information on this communication protocol.
Steve’s Internet Guide is a great website that will help in understanding this fast adapting communication protocol.

HiveMQ Public MQTT Broker

The MQTT broker is a server. It will receive all messages from the client. (Publish) The broker will then route the messages to the appropriate destination clients. (Subscribe).

We will be using the HiveMQ Public Broker for our two clients to share information.
Here is the information that we need in order for our clients to connect.
Host: broker.hivemq.com
TCP Port: 1883 (Default for MQTT)
Websocket Port: 8000 (Used if using a WebSocket supported client.)

BRX Do-More Simulator MQTT Client

An MQTT client connects to an MQTT broker and is able to subscribe and publish to MQTT topics in the broker. The Do-More Designer Simulator can be an MQTT Client.

We will start a new project using the Do-more Simulator.

Select System Configuration from the Tools under the Project Browser or select from the main menu | PLC | System Configuration…

Select Device Configuration on the left side. Press the New Device button.

Select MQTT Client (IoT) from the list of available devices. Select OK.

Our Device Name will be MQTT_Client. The MQTT server address will be set for the server name of broker.hivemq.com as mentioned above. We will leave all of the other settings as their default values.

Here are the completed MQTT Client Settings. Select OK.

You can see we now have our @MQTT_Client settings selected.

Quality of Service (QoS) – MQTT 

QoS refers to the communications between the sender and receiver of the messages.
QoS 0 – This is the minimum level. This service level is a best-effort delivery. There is no guarantee of delivery.
QoS 1 – This level guarantees that a message is delivered at least one time to the receiver. The sender will store the message until a PUBACK packet from the receiver acknowledges the message.
QoS 2 – This is the highest level of service in MQTT. The message is guaranteed that the intended recipients get the message once. The sender and receiver use the packet identifier of the original PUBLISH message to coordinate the delivery of the message.

BRX Do-More Simulator PLC Program

We will not write our ladder diagram for our MQTT client.

MQTTPUB – IoT Publish MQTT Topics

BRX Do-More Simulator MQTT Publish Subscribe
Select the MQTTPUB – IoT Publish MQTT Topics from the instruction toolbox.
BRX Do-More Simulator MQTT Publish Subscribe
Our MQTT client will be automatically selected because we have programmed only one above. The enable will be selected for continuous power flow at the interval. Our constant will be set for 200 milliseconds.
We will use the optional topic prefix and set it for PLC/BRX/. With this set, we do not have to continuously write this prefix for all of the topics that we are publishing.
BRX Do-More Simulator MQTT Publish Subscribe
Select the first topic and press edit.
BRX Do-More Simulator MQTT Publish Subscribe
Since we are using the common topic prefix enter “WX0” for the topic. So our topic will be PLC\BRX\WX0. The payload or value we are writing into the topic will be address WX0.
Retain when set, will save the value in the broker so the value will be given every time a new client connects to the broker.
We will publish at the interval only if the value has changed since the last interval. This will limit the amount of data being sent on our network.
BRX Do-More Simulator MQTT Publish Subscribe
Here is our completed new topic. Hit the OK button.
BRX Do-More Simulator MQTT Publish Subscribe
We will now add another topic.
BRX Do-More Simulator MQTT Publish Subscribe
Our topic will be PLC/BRX/X0 and our payload will be the value of the bit X0. This again will be published at the interval only when the value has changed.
Hit OK.
BRX Do-More Simulator MQTT Publish Subscribe
Here is our completed MQTTPUB instruction. Hit OK.

A warning is given indicating version 2.3 or newer must be used to use this instruction. Select OK.
BRX Do-More Simulator MQTT Publish Subscribe
We are using an always-on bit (ST1) to trigger our MQTTPUB instruction. Information only will be published when a change occurs at 200-millisecond intervals.

MQTTSUB – IoT Subscribe MQTT Topics

BRX Do-More Simulator MQTT Publish Subscribe
Select the MQTTSUB – IoT Subscribe MQTT Topics from the instruction toolbox.
BRX Do-More Simulator MQTT Publish Subscribe
Our MQTT client (@MQTT_Client) will be automatically selected because we have programmed only one above.
We will use the optional topic prefix and set it for PLC/BRX/.
BRX Do-More Simulator MQTT Publish Subscribe
Select the first topic and press edit.
BRX Do-More Simulator MQTT Publish Subscribe
Since we are using the common topic prefix enter “WY0” for the topic. So our topic will be PLC\BRX\WY0. The payload or value we are reading into the topic will be address WY0. This will place our subscribed information directly into the PLC register.
BRX Do-More Simulator MQTT Publish Subscribe
We will also add the topic PLC\BRX\Y0. The payload or bit information that we are reading into the topic will be bit Y0. This will place the subscribed information directly into the bit location of the PLC.
BRX Do-More Simulator MQTT Publish Subscribe
Here is our completed MQTTSUB instruction. Hit OK.
BRX Do-More Simulator MQTT Publish Subscribe
We are using an always-on bit (ST1) to trigger our MQTTSUB instruction. Watch below to see our MQTT communication network in action.

HiveMQ Websockets Client

We will be using the online HiveMQ Browser Websockets Client.
BRX Do-More Simulator MQTT Publish Subscribe
Our connection will use all of the default values. Select the Connect button.
BRX Do-More Simulator MQTT Publish Subscribe
You will notice that we are now connected to the broker. Select the Add New Topic Subscription button.
BRX Do-More Simulator MQTT Publish Subscribe
We can select different colours for our subscribed information. Our QoS will be left at the default of 2.
Our Topic will be PLC/BRX/WX0. This is the address of the word of information that we want to read. Hit the Subscribe button.
BRX Do-More Simulator MQTT Publish Subscribe

Select the Add New Topic Subscription button again. Add the topic PLC\BRX\X0. This will subscribe to the individual bit.
BRX Do-More Simulator MQTT Publish Subscribe
Here are the subscriptions and corresponding information coming into the browser client.

We can also use the browser WebSocket client to publish information.
BRX Do-More Simulator MQTT Publish Subscribe
The topic will be set for PLC/BRX/Y0. Place a 1 in the message and press the Publish button.
BRX Do-More Simulator MQTT Publish Subscribe
This will cause the first output bit on our Do-More Designer Simulator to turn on.
BRX Do-More Simulator MQTT Publish Subscribe
The topic will be set for PLC/BRX/WY0. Place a value of 1234 in the message and press the Publish button.
BRX Do-More Simulator MQTT Publish Subscribe
This will put the value of 1234 in the WY0 address as seen on our Do-More Designer Simulator. Watch below to see the video of the browser WebSocket client communicating to the broker.

Watch the video below to see the do-more simulator MQTT publish/subscribe in action on our BRX Series PLC.

You can download the program here.

BRX Series PLC from Automation Direct – Power to deliver
Overview Link (Configure and purchase a system)
Manuals and Product Inserts (Installation and Setup Instruction)
Do-More Designer Software v2.0.3 (Free Download Link) – The software will contain all of the instruction sets and help files for the BRX Series PLC.

Watch on YouTube: BRX Do-More Simulator MQTT Publish Subscribe


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.


Leave a Comment