MQTT is an extremely simple and lightweight messaging protocol
and is a great way to pass data between multiple platforms
without a lot of protocol confusion and very little development time.
Messaging in MQTT is based upon Topics. These topics can either be Subscribed or Published to
from a central repository. This central repository of topics is called a Broker.
The devices Subscribing or Publishing to this broker are called Clients.
Each client can publish or subscribe to one or more of the topics on the Broker.
To setup MQTT on your Productivity PLC, you must have version 3.11 software or above.
The Productivity can only work as a client. You must have already setup a Broker to handle the
messaging. There are too many brokers and their setups is way too varied to cover in this video.
Please see MQTT.org for more information on this topic. I am using a Raspberry PI
4 with Mosquito loaded. There is a really good tutorial on this setup, and you can find a link
to that in the description below. Productivity has made using MQTT very
simple. It does not require any instructions in the ladder code.
To setup MQTT on Productivity, this is done under the Hardware Configuration.
Then Select the MQTT tab. Drag the this Client into the active window.
Here you can create a structure that will include tags to handle these entries. These tags will give
you status info on the connection between your broker and the client and this bit will need to go
high to enable the MQTT communication. Give the device a -name.
Here you can use a static IP address of your Broker or use a Server name. If you are using
a server name you will have had to setup the DNS server on the CPU Hardware configuration.
Now, for my setup, I am on an isolated network so I am going to use a static IP address.
The standard Server port for MQTT is 1883,
consult your broker information, to ensure that this number is correct for you.
Once you have established a connection to a broker, the CPU will send periodic PINGs,
at this rate specified by the Keep Alive Time, to ensure the broker is still available.
If your broker requires Authentication enter that here.
This option will allow the broker to purge information from any previous session.
Select this option to enable the broker to send a message to other MQTT clients
if the CPU loses connection with the broker function. Enabling this option requires the
following fields to be completed. This allows you to select the Last
Will Quality of Service. Selecting 0 is the fastest method but also the most
unreliable because the CPU does not wait for the message to be acknowledged by the broker.
Selecting 1 causes the CPU to send a message and then wait
for an acknowledgment. This guarantees that the message will be delivered at least once.
Select this option if the broker should retain the Last Will and Testament.
This is where the Last will topic will be sent, and this is the message to send.
For this example, I will forgo the last will setup.
Here is where you can add your subscribes and publish. Each broker target can support up to
3 Publishers and 1 Subscriber and each Publish and Subscribe can support up to
10 different Broker Topics. I will setup 1 subscribe and 1 Publish for an example.
This bit will enable you to subscribe, and this tag is part of the structure we created above,
and these tags will give us communication status of the subscribe.
Here you enter in the Broker topic to read from.
When I set up my broker it created a Test Topic that I will enter here.
Payload will be the string tag that will store the message read from this topic. Received must
be an integer tag. Indicating how many messages have been received for the corresponding topic.
On to publish. Like before these tags will be part of the structure that we create from above.
This enables the publish. This is the rate at which it will publish the message,
and these are your status flags for the publish.
I will use the same test topic that was in my subscribe. This will be string tag
that contains the info that is sent to the topic when this is enabled. If you select this option,
it will cause the broker to retain the payload in the topic when it is sent.
That completes the client setup, so when I select ok,
All the tags entered in this window will now be created. By default, the strings we be
15 characters. I will change this 128 just in case I need to send something larger.
To test this setup, I will go back into the MQTT hardware configuration and select this
monitor button. This will add a data view tab, that was all the relevant tags for this setup.
Now send this to the PLC.
Now, I will go into Data View. First, I will enable the Client
by turning on this bit and here we see that we are connected.
Now, I will write in a message to publish to this topic. Then I will enable the publish,
which writes this message directly into the test topic.
Now I will enable the subscribe and here we see that we read this message back.
I will go ahead and edit this message a couple more time so, you see how this works.
Quick and easy little setup for MQTT. Now you can pass information
between multiple platforms very easy. If you have any question on this video,
please feel free to comment below or call into our tech support department.
Please follow this link to see more videos on the Productivity PLC
and select here to subscribe to our YouTube channel for upcoming products and solutions.