Optix with Multiple MQTT Subscriptions

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 a FactoryTalk Optix application to act as a dashboard for displaying data from more than one remote asset, such as a tank. FactoryTalk Optix will work as both the MQTT Broker and MQTT Client/Subscriber, to receive in multiple MQTT topics. This video shows how to create the data folders for each subscribed MQTT topic.

Software used for the demonstration:
FactoryTalk Optix v1.5
MQTT Explorer 0.4.0-beta.6


Transcript
(00:02) I want to come back to mqtt in this video I had made a couple of previous videos when version 1.5 of Optics was released that showed the new native mqtt capabilities one was that we could create a mqtt broker in Optics have Optics to be the broker or we can natively create an mqtt client where we can be either a publisher or a subscriber and in those two videos I showed how you set up the rer as well as how you can uh make uh Optics a publisher and subscriber and in that situation I used um Optics to go to a
(00:42) cloud uh broker I want to kind of go back to a maybe a a different use case where you maybe we’re going to monitor three various remote tanks and use mqtt as um as that mechanism to send data from each tank back here to some sort of dashboard so to speak and what I really want to show is kind of that uh mqtt payload structure uh that that version 1.
(01:15) 5 supports so to do that I want to first go to the help and go up to the question mark and press uh choose help and if I just type in mqtt and search for that we get quite a few entries but I want to go to this um just this Main mqtt uh link and talks a little bit about you know those capabilities but it shows this payload structure which kind of gives the uh you know the the time stamp uh the tag name value and you know multiple times based on the number of tags that you have so kind of want to show and play with this here in a minute
(01:51) and show how this works and I’m going to go ahead and use my mqtt Explorer to kind of be the um the remote publish of the tanks just to show as as an example um but coming back to Optics let’s go through a few things that would be set up the other thing I should mention there was in that those previous videos I only showed where we were subscribing or publishing to one topic here I want to do multiple topics we’re going to have essentially a topic for tank one tank two and tank three so three separate topics how about we do
(02:27) that it’s pretty straightforward but just want to show it so just to kind of Refresh on a few things one I already have the mqtt broker set up so under mqtt I uh I right clicked and added a broker the properties for that broker over here the uh essentially there’s not a lot to set up in version 1.
(02:50) 5 still it is the port and your qos the number of connections is fixed 25 is the max um do you want to retain the data setting and then right now uh it’s around you want C certificates so got that turned off next step is we would need to create a client so we create an mqt client and in the client essentially we need to tell it you know where is the broker address uh what port what’s our client ID and are we enabling SSL or TLS security or Brokers U I’m sorry or broker certificates so we’re going to um keep those both off for this
(03:35) example and um the then once we create a client I would right click on client and say new subscriber and here is the difference from what I kind of did last time um I will have multiple subscribers or subscriptions so uh subscription one I call at tank one and I’m going to point to a folder and I’m going to go show you that uh BAS basically so we have subscription one two and three of three very separate subscriptions topics one tank one tank two tank three and then a folder which is essentially like the model where is
(04:13) the data going to go you know from the broker where is it going to go be stored at and it’s going to be in a folder called tank one tank two and tank three so that’s the differences we’re going to put that data in these separate folders so to do that I went to the model folder and I created a structure called tank one and in tank one I created three variables level status and name level will be uh a double integer status is going to be a Boolean and name is going to be a string and then once I created that structure I was
(04:55) able to just kind of copy and paste tank one uh in when you paste it it became tank two and tank three could of course rename those folders but for this example keeping it simple whereas each tank will have the same data structure kind of coming back to it all right of course each one could be completely different unique but key is you know that we need to have the variables here in the folder that match what’s going to be coming in from the mqtt um publisher out in the field and at that point all I did was link
(05:33) these variables to the objects inside of this little panel so uh right here we have a label that will show tank one name we have a LED that’ll show tank one status and we have a tank that’ll show tank one level and this label will also display the level right it’s pretty simple pretty straightforward so basically had to set up the mqtt uh broker so that you know Optics here will be the broker uh set up the client so that it can go out and subscribe to these um three tanks Publishers and then of course set up the model the data model
(06:19) of where that data is going to go for each topic so let’s go ahead and start up the emulator and uh we we’ll see this work out now uh I’m going to go ahead and open up my mqtt explore and I’m going to go ahead and connect so what I’m going to do is just to show that we can go back and use this payload structure that Rockwell has put on their help page I’m just going to copy this and bring it to my mqtt explore so down here in my uh Json uh box I’m just going to paste that now uh a couple things uh we need to change the tag names and of course the
(07:11) values so our first one is level our second one is status and our third one is name now name is a string and I just wanted to show show the ability to do an analog value a Boolean value and a string value just kind of common variables so the this name of course since it’s a string we’ll have to have the quotation marks around the value and uh maybe we’ll call this you know tank 101-a or something give it something a little more than just tank one for my Boolean which is status is going to be the Boolean tag um I’m just going to
(07:57) type in a lowercase true so it going be true or false for the Boolean lowercase and then for the level that’ll actually be the tank level which will be a number between zero and 100 so maybe I’ll start with 25 now what’s interesting here is that when I push this code in here um doesn’t seem to like this one that comma there also um notice that it’s throwing a little error here unexpected uh quotation marks um don’t know why mqtt does this but uh sometimes you just need to retype it and it fixes it um there was a comma
(08:47) there before too and I noticed that when the comma is there it throws up an error so get rid of the comma and there’s no error all right so that’s the payload structure and then I’m going to go ahead and get my emulator window kind of visible in the background so the only other thing I got to do now is just say what is the topic that we’re publishing to and it’s going to be called tank one and I hit publish and then instantly we’ve got our 25 we get our level we did get our status as true and our tank name is being displayed there if I want to
(09:22) turn off the status to make it false I can publish that and I do the same for tank two I want to give it a different level say it’s at 45 of course maybe it’s going to be tank 2011 right so there’s uh tank two information being displayed and then if I choose my topic as tank three um maybe give a different uh say 32 and let’s go ahead and make this one true I go ahead and publish it we see that right now there’s no data there publish it and now there’s data 32 true and the name which I didn’t change so just wanted to show that you
(10:12) know one like I said before that we did not show previously how to do multiple topics we just kind of showed one so essentially we’re putting you we’re going to create the folder uh typically under the model folder doesn’t necessarily have to go under the model folder but we’ll create a a folder that will have the the variables or the uh the structure of the variables that would be coming from those mqtt Publishers and then um in this case just using Optics as the as the broker so I did make a little architecture picture
(10:48) here so kind of a use case for this would be again if we had kind of some remote tanks or remote whatever pieces of equipment out in the field we can bring that information you know into Optics and Optics itself can act as a publisher and then back here in our central location Optics can act as the broker so the broker can basically manage all those clients and you know send the uh the published data out to the various subscribers so the fact that Optics can be both a publisher broker and subscriber um looks you know makes
(11:30) it kind of interesting some of the solutions it can solve now uh just one other thing to note here is that to do that uh you you do need to have some tokens to do that so back on the Optics runtime sizing tool that’s up on Factor talk Hub if you kind of go through to the um to the inter operability uh section there’s you know tokens for opcua or mqtt so to be a broker would take one token and to you know be connected to three subscribers would take a token for each subscriber um that you’re or each sub you know publisher you’re subscribing to
(12:14) so that brings up to about four tokens just to do this little example that I’ve done right here so that was it just wanted to show that ability and uh hope that helps