MQTT Client Publisher and Subscriber

Home / FactoryTalk Optix / Optix for Edge

Description
The latest release of FactoryTalk Optix, v1.5, brings native support for MQTT with an embedded broker and a client that has publisher and subscriber capabilities enhancing connectivity to cloud applications. This video provides a brief look at how to configure one FactoryTalk Optix application to publish MQTT data to a cloud-based broker (HiveMQ Cloud), and then have a separate FactoryTalk Optix application subscribe to that cloud-based broker to read and display the value.

Software used for the demonstration:
FactoryTalk Optix v1.5
Studio 5000 v37
FactoryTalk Logix Echo v3.01
MQTT Explorer 0.4.0-beta.6
HiveMQ Cloud


Transcript
(00:01) in this video I want to go a little bit further into the native mqtt um connectivity that’s been added to the latest release of factor talk Optics version 1.5 again the version 1.5 release came out towards the end of October 20124 and looking at the release notes um you go to the uh question mark and choose release notes we can see that under system features under data connectivity um Native mqtt support is now um you know included U it provides an embedded broker as well as a client that can uh be either a publisher or a
(00:45) subscriber in the last video I did I showed how we could use that embedded mqtt broker and I was able to publish a variable that was inside my Optics application to the embedded broker and then a remote mqt client or subscriber could could use that embedded broker to see the value in this video I want to make the um I’m going to make that same application into a publisher but this time published to a remote uh mqtt broker so to do this um I’m just going to use the cloud version of Hive uh mq and if you know high of mq provides a
(01:34) free little bit of a Sandbox a serverless um cluster uh in the H in the hive mq Cloud it gives you U 100 connections for free uh 10 gig gigabytes of data traffic per month so you know maybe you’re not going to be using this for production systems but this is going to be good for me to test um if you are interested in additional Cloud offerings from from hive mq then you can see there’s uh starter and Enterprise um levels and once you create your cluster you’ll get your own kind of URL kind of like what I have here uh got a port set up the
(02:15) default Port U 8883 if I choose manage cluster um the only other thing I need to do is I need to create a a uh a user uh that can access this so if I look get my credentials I’ve created a user and I’ve named that user Hive user and I went ahead and gave publish And subscribe um permissions to this user in this case probably um well yeah I’m going to you know we could create a user that might be a subscribe only and then perhaps another user that would be publishing but in this case I’m just going to have one user that has uh both
(02:58) privileges or permissions okay so that’s all I had to do to set up this Cod environment again it was completely free and nothing to do once you create your cluster all this stuff gets generated automatically and you just got to create your user or users and their permissions so once I do that I come back to my mqtt client so to to get to this point if if um didn’t watch the previous video I did we’re going to rightclick on mqtt which is now a new item underneath the project view in version 1.
(03:36) 5 I’m going to choose an mqtt client I’ve already got that set up here mqt client one when I do that if I go to the pro the properties of that um mqtt client one I need to just put a few things in here one I need to put the broker address so that is basically that link that I had back in the hi mq cloud um so I’m going to copy paste that link and I’m going to use the default that the or the port number in this case it default it to 8883 which is the same port I was using um there in the hive mq Cloud um can leave the current um the
(04:17) client ID alone or rename it if you wish I’m going to make sure that the SSL uh security is enabled I’m going to turn off my validate broker C certificate and if I kind of stretch this out a little bit maybe do a better job of showing some of the terminology here so this is a validate broker certificate I’m going to go ahead and leave that as a false I’m not going to use a certificate just for this uh demonstration so don’t need to worry about these certificate files since I’m not going to uh use a certificate and
(04:53) the other thing I got to do is I’m going to change um from Anonymous user identity type was default to Anonymous I’m going to change it to username and password and I’m going to enter that username that I created at the uh Hive mq Cloud which I called mine Hive user and I enter my password so that sets up the client but I still got to go and set up the publisher so to do that um if you wouldn’t have this here yet I would right click on client say new publisher when I I click on publisher I’m essentially going to basically
(05:33) telling it what am I publishing so um and then first we could choose what is the sampling mode your options are none periodic or change in value and I’m going to go with change in value still for this um the the folder is where I’m going to read the variable or variables that I want to publish in this case I’m just going to use the the model folder that was already created I created one tag or one variable underneath the model folder and called it tanglin level and then I can choose the uh qos the uh quality of service setting uh
(06:19) mqtt allows for these three settings zero one or two um I’m going to leave it as two and the last uh setting here is a a retain uh functionality uh either true or false I’m just I’ll leave it false um for this and that’s pretty much all I need to do I’m going to go ahead and start my emulator and that will now bring up my demo application that I was using previously you can see that my level is set to 13 right and there’s nothing really to see at the moment um so what I’ll do first is I’m going to bring back up my
(07:06) uh other utility other program that you can download for free and that’s called mqtt Explorer this allows you to kind of just test out that connection this will become a uh like an mqtt client or subscriber basically so I’m going to um I’ve already created a connection called it Hive mq cloud and I’ve uh copied in my link to my instance or my cluster the port number is uh 8883 I’ve entered my credentials for my user and my uh username and password I’ve disabled the validate certificate and I’ve enabled the encryption and I
(07:49) can say connect and now as I change my data you can see I get my tank one tank one level value is 19 level is 19 um change that number again and we can see that we’re going to get some historical trending happening down here right so again I’m I’m uh I’m updating based on change so this number is only going to update when I actually change this value so this is great we show that one Optics is actually connected to that cloud broker passing data up to the cloud broker and um I have a a um a subscriber that can
(08:35) also connect to that cloud broker and get information now what I want to do next is I’m going to go ahead and disconnect this and uh and turn that off um I’m going to leave this application running now this just happens to be in a in a virtual machine that I have running here so this virtual machine is connected to the internet and passing data up to the cloud so for the moment I’m going to um I’m going to um just minimize this and I’m going to bring up an Optics application that is actually running on my on my uh host
(09:19) machine or my my desktop and in this case I want to make this application that’s on my desktop a subscriber to that um to that cloud broker and get that tank level and displayed here now in the uh Optics application that’s sitting there in the virtual machine I made it I I added a mqtt client and then I added a publisher in this case I’m going to add the client and then add an mqt subscriber so for for this you know demonstration I had to create an mqt mqtt client just like I did before right click on the mqtt object here or item
(10:07) and and choose new client and then I get this client one and I set up my client credentials very much like I did in the um just a few minutes ago I have a broker address that’s that same link to the hive mq Cloud um I have the port I I have a client ID I did go ahead and change this from a one to a two just to make it something unique um since I already had the Ft Optics -1 was created in the publishing application on my virtual machine U and I’ve enabled the SSL security I’ve uh disabled the certificate validation and I did the
(10:52) same change the uh user identity type from Anonymous to username password and then I entered my Hive mq username and password that I created um Hive user and then my password then I would right click and I would say new subscriber and I get my mqtt subscriber one gets created here and this is the new part that we haven’t seen yet and I need to basically um set up a few properties for this subscriber one is I need to tell it what topic am I subscribing to so when I had created my publisher I chose the topic name to be tank one so I’m going
(11:39) to basically subscribe to that same topic name tank one I need to choose the folder that the the data that I receive from the broker where does it go to um in this case I’m going to go ahead and use the model folder again just to put put the value in that folder and then I have have my my qos uh setting which again can be um 0 one or two uh it’s set to zero right now think I can go ahead and keep it at that and then the last thing I did was I I did have to create a variable that name matched um you know what was coming off the broker so I had
(12:21) a uh you know back on my other application I was publishing a variable called tank one level and you know publish that to the broker so now I’m going to subscribe to that broker and I’m going to bring it down and put it into a a variable called tank one level and then only other thing we did at this point was I created a uh basically went to the main window added a label just to get the value to read the value of tank one level all right so again this is sitting on my uh on my uh host computer I’m going to go ahead and uh start up my
(13:07) emulator oh that came open in the other window so there pull it into here all right so right now it is reading zero but there has been no update so if I come back to my um if I come back to my virtual machine you can see that we have a value of 39 and um let me pull up the emulator from my desktop right so this is the the screen I just created so if I were to change the number here I do get 22 here try to uh minimize this just to make it a little bit easier to read perhaps all right so let me bring this uh bring this emulator back up uh so we
(13:57) can get a number 38 get 38 all right so uh basically proving that one Optics the native mqtt um you know the new mqt TT native connectivity I can basically publish from one Optics application send it up to a cloud broker perhaps or any broker for that matter it doesn’t really matter it could be the embedded broker or um and you know a third party broker and then have another application Optics application acting as an mqt subscriber to pull that data in from the broker so just uh found that kind of interesting
(14:43) wanted to show that real quick one that was very easy to set up uh very very um very limited amount of configuration required just some basic information about the broker and the broker credentials and setting up you know what variable we want to publish and of course uh subscribe to so again um new version 1.
(15:11) 5 Optics um you know the native mqtt connectivity capabilities