This video is part 2 of a 3 part series that details the needed information to setup and use MQTT in the do-more BRX PLC.
This video details the implementation of MQTT in the Do-more BRX PLC.
Our FREE Practical Guide to Programmable Logic Controllers eBook: https://www.automationdirect.com/ebooks/plc-handbook
okay assuming that you have completed the basic training of mqtt using brics plc let's do a very simple example using do-more designer and the brx plc the first thing you must have is the correct hardware there are many models of the brx plc but only those with a built-in ethernet port like this will work these plc's have an e in their part number as shown down here the next thing is you have to configure your ip address now i'm already connected to my brx plc through the ethernet port so this i have already done but in you must configure this port first so if i click here and go to edit ip configuration you have module id name and description these are not necessary settings for the mqtt to work of course you have the ip address subnet mask and the gateway address and you also have the dns address this is required if you're going to use your broker's name or its url instead of its raw ip address then i would ok this and i would write this down to the plc the next step is i must create an mqtt device this is not created by default so i would go to the system configuration here and i would normally go to device configuration and press new device and mqtt client but i've already done that and mine is called mymqtt so let's take a look at those settings i double click here this is the name i gave it and this is the case i was telling you about previously that if i'm going to use the server name which here mine is called broker.hivemq.com then i would have to have a dns server i would have to have that present and configured properly in my ip settings otherwise i could use the raw ip address here now the protocol here is mqtt or i could use the encryption with mqtts and 1883 is the server ports the default port this is the keep a lifetime of 30 seconds that's default and the quality of service is zero i could pick also one i can't pick two the session type is clean or persistent and then here some mqtt brokers require a login before you can use them so here's where i would pick that and set it mine doesn't require that this is the last will and testament where i would give that last one testament a name and then what the data is and whether or not to retain it and this is the enable user specified client id this is a 64 byte id that's unique for each client that connects to the mqtt broker now the brx plc will create one for you using its mac address but you can assign your own if you wanted to by clicking this and then of course i would okay out of these just like so and i would also write that down to the plc next after i have configured plc i actually went and wrote a program it's very simple go here to main and you can see i have just a few c bits and i'm basically going to just initialize r 100 and r 101 to some values and then i'm going to use the mqtt pub instruction to publish those values to the broker and then i'm going to use the mqtt sub-instruction to read those back and store them in r 200 and 201 so after i execute this the values that are in r 100 and 101 will end up in r 200 and 201 and they will be continually updated as i am subscribed to those values so now let's look at the mqtt pub instruction double click on him you notice here i picked my mqtt client device which mine is called my mqtt and i have a choice here of an of how to enable it whether once on a leading edge which basically when if you have that and when you enable it then it will just go through this list of published topics once and determine success or error but i could also publish it continually so here you can see i have continuous on power flow at interval and i selected one second as the constant or the time between when i publish and basically what that is as long as this input is on then it will go through this list every second and try to publish these values now there's also another setting that's going to come into play which i'll show you in just a second now also here is the optional topic prefix i can put this let's say that these topics here have a longer topic name you know sometimes topics do like say greg test slash is actually prepended to this so rather than having to type it in each time down here i could choose this but that also has comes into play in another setting i'll show you in just a second so normally i would use the insert button to put in a new topic but here i put in two topics i've called one my r100 in my r101 and it's pointing to these elements in the memory of the brix plc you also see that these are set to retain and here's the other thing to publish is to publish this value on change so what this means is in the way i have this set up every second it's going to go down through here and see is has r 100 its value changed since the last second that i looked at it if it has changed then publish it if it has not changed then don't publish it don't waste time out on the wire in other words if it hasn't changed there's no need to republish the value so what this looks like is very simple here you can see i could use the common optional topic prefix as well if i wanted to here or not that means if i have this checked then this optional topic prefix would come into play if it's unchecked then not so that way i could have topics down through here that use this optional topic prefix and some that do not so here i called it my r100 and i gave it i told it to send the value that's stored in r100 i told it to retain and then also here i have the publish interval setting and this this tells you how this this is the setting right over here in this column publish at an interval only if the value changed since the last interval or publish at every interval even if the value has not changed that should be clear enough so i made these two topics here to publish and also of course you have the on success and on era behavior in this case i'm choosing to just set some bits probably normally i would use stages to do this and then there's also the extended area information that can be stored in a double word d d10 now the thing about this is that the lower part of this word will contain an error code if it fails and the upper word will contain a topic number of the first topic that failed say you had a list here 10 to 10 things and maybe five of them failed it would only point to the first one so as you can see over here in my data view that i have put up here i divided d10 which is my extended information double word into the lower word in the upper word so that we can see that so what i'm going to do later is i'm going to generate an error so you can just see that happen so that is the mqtt pub instruction that's pretty straightforward and simple now let's look at the mqtt sub it's very similar to the pub instructions so here i picked the client device same thing here i have the optional prefix as described before here i have topics and so if i open this up you can see that i added uh to subscribe to my r101 and my r100 just like i published them up here but i'm going to store the payload that i get from them into r200 and r201 that's pretty straightforward and easy too and then same kind of buttons also same on success and on arrow and extended information is uh also available and i stored this one in d1 or d11 and you can see over here in my data view i have d11 divided into the lower word in the upper word and so basically the mqtt sub as long as its input is on it's going to be subscribed to these topics if i ever turn it off then it won't receive any more updates but as long as i leave it on then whenever this r100 up here changes it should get reflected into r200 for example so let's see how this works first thing i'm going to do is put this guy in the run mode but remember whenever i configured my mqtt broker i had a certain url name let's go there and look at that real quick you see i'm using broker.hivevmq.com is the url of the free one that i'm using that's out on the internet i wouldn't recommend it for actual application but for demonstration it's perfect if you go to mqtt dashboard.com then you can see the dashboard for that particular broker but you can see here that the broker's name is broker ibmq.com that's what i put in as my broker a tcp port number 1883 which was the default for mqtt and so now let's just demonstrate this i'm in the room mode and i initialize r10101 then i will publish i have a success and then i will subscribe and so now you notice that r200 and r201 reflect the values that were up here and if i happen to change them to something else and write that down then you can see because i'm subscribed to that value then i get it back here in my data now normally in the real in the real world uh a particular plc might be publishing information and a different plc would be subscribing that information you wouldn't be doing what i'm doing here so this is just a demonstration and that's how easy it is to use mqtt honor brx plc to see how to troubleshoot mqtt in a brx plc check out our mqtt troubleshooting video you
Voted #1 mid-sized employer in Atlanta
Check out our job openings