<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=2854636358152850&amp;ev=PageView&amp;noscript=1">
17 min read

SBA 335: How Does MQTT Work in Building Automation

By Phil Zito on May 4, 2022 4:40:13 PM

Topics: Podcasts

In this episode, we discuss how to MQTT works in building automation systems.

Click here to download or listen to this episode now.

Resources mentioned in this episode

Training Video

Subscribe via iTunes

Subscribe via Stitcher


Phil Zito 0:00
This is the smart buildings Academy podcast with Phil Zito episode 335. Hey folks, Phil Zito here, and welcome to episode 335 of the smart buildings Academy podcast. And in this episode, we are going to be discussing how does MQTT work in building automation? It's pretty easy to know how it works in IoT. But how does it work in building automation we'll be going through that in this episode. As always, everything can be found at podcasts at smart buildings academy.com For slash 335 Once again, that is podcasts that smart buildings academy.com forward slash 335. I do want to bring up a ton of you have asked us to do a live PID Loop tuning training. It's our most listened to podcast our most watched videos. So Tuesday, May 17. At 8am Pacific Time to 12pm Pacific Time, we are going to be doing a live instructor led PID Loop tuning bootcamp, that course is going to have 40 seats available for purchase. So definitely purchase them as soon as you can, because those PID Loop turning anytime we've done it in the past, anytime we've opened up that course has gone really fast. So I really encourage you if this is something you want to learn, get ahead of it and go and make sure you purchase a seat to the live course it's going to be a lot of fun. We're going to learn how to tune loops, we're going to do a lot of loop tuning exercises. And you're going to come out of there being a PID Loop tuning master. Alright, let's dive into MQ tea tea and let's have some fun. So MQ TT came out of the SCADA world, they were looking for a light weight protocol that would be able to essentially take a message from some sort of low power, low requirement device and share that with a lot of devices. Now, you might be saying to yourself, Phil, why in the world would we need MQ T T? When we have BACnet? What would be the point of this because the end of the day BACnet has read property, it even has read property multiple and it has right property, and it has right property multiple, why would we want to go and use em que te t? Well, there's several reasons we're starting to see a lot of sensor providers use em que te te out in the market. First off, whenever we think of a sensor, and we think of a BACnet sensor, like if I said to you BACnet MSTP temperature sensor, what would be the first thing that came to mind. Usually that is expensive. And most of the time, that's true, like if we have a temperature sensor that is BACnet MSTP, or BACnet. IP, it's usually quite expensive. And the way we communicate to those, right, we're limited to MSTP or IP. So we have to use some form of physical medium to connect to the sensor. Now the IoT space Internet of Things space has went in a separate direction MQ TT is one of the leading protocols for IoT sensor, publishing, as well as subscription. Now you may not know what those terms are, by the end of this episode, you're going to definitely know what these terms are. We're going to go through the terminology of a client a broker, we're going to talk through those we're going to talk about the publish subscribe framework. We're going to talk about different encryption and security methods that thank God, they followed just normal standards and didn't do something like BACnet SC where it's like this bastardize standard that yes, I'm railing on BACnet sc again, that tries to implement things, but implemented in a protocol that no one outside of the BAS world is going to be able to understand or like reasoned with themselves on why they're going to support it.

Phil Zito 4:34
But hey, I'm not bitter about that at all. So let's continue. So MQ TT, right, we're sitting there, and we've got this protocol that comes out of the SCADA world out of the industrial world, enters into the IoT space and the reason it entered into the IoT space was these IoT devices are typically low powered devices. Think of something like your doorbell I think of some doorbell would be a poor one. Think of like a contact sensor, something that's not streaming data, it's sending data based on an event. That event may be a change in temperature, that event may be a change in status. But it's an event driven protocol. So when we think back to change a value cov trending, right, we're all familiar with event driven protocols, change values, and event driven, we set a threshold of either a Boolean state change or a numeric state change. And once that threshold is met, then the cov, whatever, subscribe to cov then goes and sends. So I know some of you may be like, okay, Phil, we got cov. We've got read property and write property multiple in BACnet. Why would we be using em to Q TT? Trust me, I promise you, we'll get there. And we'll also talk about how to implement MQ TT, alongside existing BACnet traditional building automation systems. But the thing is MQ T T is a very lightweight protocol. I mean, if I were to go in to an MQ TT stack, and we're gonna see if I can do that here, MQ, T, T, C, sharp example. So let me bring this bad boy up here. And I'm going to switch screens real quick. So if you're looking at this example, I know that for some of you who don't know how to read code, you're going to be like, Okay, what the heck am I looking at. But essentially, all we have to do, the reason this is lightweight, is we initiate the client, we pass through a client ID, and then you can start initializing the broker address. And then you can go and basically connect the client. And when you connect the client, you could do all sorts of like sending stuff, etc. And you could just connect client, you can subscribe to, you know, grabbing a topic, you can also publish a topic, right? And this is it. That's all that has to happen for us to be able to go and as a manufacturer, implement an MQ TT client. And you could do this even lighter weight with other coding languages. Okay. So this is super lightweight. Now, if I were to bring up I don't not sure if I have it, but I'm going to try. Give me a second here while I bring up another screen. And let me log in here. If I were to bring up here we go. The yet another BACnet, Explorer, C sharp library. Let's bring that up. To open it up in Sourceforge. I'm going to download it, get it downloaded, and I'm going to go and open up the code base. So let me just install this real quick. Yes, it's, it's fine. I'm going to run it even though you say it's unsafe. Okay, we'll click OK, we'll accept it. We'll click Next. Open up this bad boy. And I don't want to launch it. But I am actually going to go into the folder that it was installed in. And I'm going to open it up. And let's find it here under Program Files. There we go. There we go. Let me see, I should be able to I have the badge might not have the code base. Well, that's fine. I didn't install the code base that I dadgummit I have to go to somewhere to grab the code base. And there it is. It's on GitHub. So grab code example. I'd have to go to the file. And just want to download this guy. There it is.

Phil Zito 9:19
I'm not even going to download it. I'm just going to switch screens real quick here. So all right, this is which one is this. I don't want to do a storage example. I want to do a readwrite There we go. And let's go to the Read Write to CS project. Okay. And let's go back here read write. Program CS. There we go. This is implementing Read Write. Or there's a lot of stuff and a lot of supporting libraries under the stuff that you're not even seeing. It is a much heavier Protocol. Now, granted, it does give us a lot of capabilities that we don't have otherwise. For example, when we go and we look at that C sharp BACnet protocol, what you're not seeing is the ability to implement a device object, the ability to implement objects to have a graphical user interface overlay with a programming tool that enables us to make programming changes to these devices. You know, there's master devices and slave devices, most of our sensors that we pick up with BACnet are slave devices, but they have a ton of capabilities built into them. Where MQ TT starts to shine is that it is very lightweight. And it's typically focused on one or two objects, usually one object in the case of like a temperature sensor, it would publish that temperature sensor value to a broker, which would then go and distribute that data to all of these clients. That'll become very important a little bit later in the episode, when we start to talk about how do we map in devices that are MQ T T devices. And there's a couple of ways we do that. But the important thing is that all the heavy lifting exists in the MQ TT broker, but Phil, we can make programming changes, and we can do things that are programmatic in a broker. Yes, you're absolutely right. There's overlay stuff like I think hive MQ TT allows you to have a broker appliance, and you can use things like Node red J S, to go and do programming of the broker. You can also host brokers in AWS and do programming in that environment as well. But at so you can have a soft broker or you can have a physical hard burger. But at the end of the day, the actual device itself is very lightweight and can use Lor Wan can use stuff like ZigBee. And I think a notion supports MQ TT, I could be wrong. Usually not Wi Fi, that's usually more energy intensive. And doesn't fish fit the kind of profile that we're looking for. But could if you needed to use Wi Fi. So you have a bunch of wireless distribution methods. Okay, so imagine this scenario, you have a customer and they want to put sensors maybe for environmental purposes throughout their building. But going and putting a bunch of wireless sensors is infeasible. Like if I go to key Lee and I go and I just look up wireless BACnet temperature sensor. So I typed this in, I'm like, okay, wireless BACnet temperature sensor. Let's just see how much that's gonna cost me wireless BACnet oh, I need to type it in. I'm just gonna do Google, wireless BACnet temperature sensor. Let's see 130 909 99. And these are just things I'm finding on Google, I probably wouldn't want to put those on MySpace. But what people traditionally are going to come up to is going to be things like the ACI sensors etc. They're going to be back that they're going to be easy to pull in, but they're typically going to be hundreds to to $100 right in that area. So expensive. MQ TT temperature sensor. Let's look that up. If I grab a baseline MQ TT temperature sensor,

Phil Zito 13:52
I can find these as low as $29. I can find some as low as $7. Granted, that's more of a do it yourself Arduino, which I wouldn't recommend in a production environment. But you can find them relatively inexpensive. And just to show you what I'm talking about here. This is kind of what's going on, right you have a sensor, you have some sort of broker and then you have some sort of client that is going to receive from that sensor. And the node red allows you to set it up now this is all like Do It Yourself automation stuff here, but that's where the market is going and that is why not do it yourself. But this lightweight kind of single purpose sensors. That's why you see people who are advocating MQ T T as a solution for low cost high density sensors, which you better believe are coming down the pipe, post COVID. And with all of these utility costs increasing, people are going to want to get really dialed in on their environmental variables so that they can one show a perception of good environmental quality to their tenants to measure the environmental quality of their building and make appropriate energy based sequencing decisions, and three, so that they can be in compliance in certain municipalities, which are going to require IQ measurements down the road. And it's a lot cheaper to do it with these kinds of sensors than it is to go and implement it with traditional BACnet sensors. Additionally, MQ TT provides not only the ability to have lightweight communication, but it also can go over unreliable, specific networks, things like cellular networks, and has the ability to store reconnect and resend. So kind of like what we can do with our trend buffers. But a lot of points are not going to store that historical data from the sensor, it's or in the sensor, kind of sort of, it's going to rely on the actual field device, like the supervisory device to store all that. So we see that the broker enables us a lightweight, low cost way of storing data that is significantly less expensive than a supervisory device. Additionally, it has security built into it. Not a terribly important thing, in my opinion, to be totally honest. But it's something that is becoming more important to specific customers, where they want to know what is connecting to their network, and they want to be aware of it. Okay, so at this point, a lot of you are like, alright, Phil, how do we connect this to our building automation network? How do we go and get this to work with like, whatever we're trying to do. So the first thing we want to do is we want to get some form of MQ TT driver or device, right, we want to have a way to go and actually pull that MQ TT data into our building automation system. Now, traditionally, an easy way to do this was with Node red. So node red is basically let me go here, and let me share this I'm going to show you is basically a software that basically takes the programmatic aspects of programming and extrapolates them into visual programming. So you can just use drag and drop blocks, and then enables you to run this kind of supervisory environment that sits on top or this, this code environment allows you to run it on your computer on a device in the cloud, etc. And the nice thing about it, if I bring it up here is that you'll see there's a library of flows that you can pull from flows are basically what node read calls like design patterns. And so we could go in here, we could type in an MQ TT flow. And we would be able to grab an MQ TT flow.

Phil Zito 18:49
Take that MQ TT flow, and then we could write it to an API. We could write it too. This one's interesting. I'm going to grab these ones right here. And Qt T pump control. So what's going on here? You know, basically, they are like if I zoom into this, this is a flow to create an HTTP request with MQ TT published. Is this an actual pump? Or is this just their calling? Be very interesting to find this one's a little more difficult to read. This one has an air quality though. So this is controlling indoor air quality and ventilation using ZigBee devices. So right here is they're talking about taking a sensor a ZigBee, two MQ TT based topic right and they are going to then publish the IQ as well as some other things like garage door status, backdoor entry, light, bathroom vents, etc. And then they are going to one report that as well as communicated to the Allen Bradley PLC, and then that's going to enable them to control the H vac system. So this is what you could do like you can go, once you learn this, you can go and start to see patterns that are previously developed. So you would develop this in Node red, you would push it out via an API, or with Node red, I'm going to bring this guy up. You could use the node red BACnet flows. So you could actually go and grab em que te T data. And you could execute a BACnet. Right? Right, you could stand up a BACnet client, that your node read as a client, or as a device, most likely a device, and then give it his device, Id give it his IP address, discover it, and then execute write commands or read commands from that MQ T date MQT T data. So the MQ TT data would then be typed into something that could be used as a BACnet read. And you would be able to then read that into your building automation system. So these are some of the ways that I see a lot of people doing MQ TT implement implementations into their building automation systems. I'm just gonna switch real quick. See if anybody's asked anything? Will I talk about products such as ignitions? I'm not sure I'd have to dig into that. But what I want you all to take out of this, is there's a whole world of protocols and sensors that are available to you. And you can go and using libraries like Node red, you can look up flows, that's the nice thing about open source software, is you can look at these flows, you can see like, Okay, I'm trying to maybe there's an h u flow, I'm gonna type in Hu, maybe there's like, roof top, I'm going to just type in H fac, let's see what we get with H Mac. So I get a couple things for H fac, right, I get some climate control, I get a raspberry pi h back, which I'm not going to trust on my building. I get some dashboarding though. And that's like another nice thing, right? Let's say you wanted to create an on demand dashboard, you could do that you could pull em que te T data, you could pull not EZRI. Once that one from the utility, I forgot what that's called. But you could pull the data from the utility. And you could pull that into Node red. And then you can push all of this out as an HTML file on to a web browser, and you could display the data. This is stuff I used to do in my previous life.

Phil Zito 23:13
But it's a lot of fun. So at the end of the day, MQ TT is another way of delivering data. Now. I haven't talked about the publish subscribe, and we're gonna talk about that real quick. So how am QTT works in a nutshell, is you have an MQ TT client. And that client will publish to a topic and this is a key value structure very similar to JSON. So the topic temperature, and then it will publish a value to that topic that goes to the MQ TT broker. And at the broker, the broker will have clients that are subscribed to the topic. So this temperature sensor is publishing to topic temperature, and it's publishing a value. And then these clients will go and subscribe to this topic. And so anytime this threshold is hit, and this device publishes, they will get a published value sent to them by the MQ TT broker. So that's essentially how MQT works. Now the nice thing about MQTT is that it allows you to do things like oh, auth and TLS Oh, auth being an authentication service where you can basically it's similar to LDAP, but not, it enables you to basically stand up your own authentication server using IDs. And you can basically authenticate anything that connects to your network. Additionally, you can use TLS, which is Transport Layer Security. I mean, it's basically what we use now since SSL is compromised, and you can use TLS and you can use certificate ng to not only encrypt your data, but also to non repudiation. Data make sure that the data came from the right person eliminate man in the middle attacks, all that fun stuff. So MQ TT adds a lot of capabilities. And it is something that if you are trying to do wide scale data monitoring of sensors, I really encourage you to explore. It is very, very easy to work through. I think anyone with about two to three months of programming could probably create their own MQ TT device using the MQ TT library, like you grab an Arduino board off Amazon, if you wanted to look at some example code. I mean, literally, there's only what is this nine functions to write for an MQ TT client on an Arduino device, and that's if you're using something heavy, like C sharp, you could use a scripting language like Python, and be even lighter than that. So just be aware of that. But you know, you could implement your own MQ TT device at home if you wanted to play around with it. But at the end of the day, from a production perspective, MQ TT, what you're going to do is you're gonna find sensors and find a broker software, or implement your own broker. And you could implement your own broker actually, in a node red appliance that you run on the same server as your BAS server. So like, maybe your BAS servers, Port 443, maybe your node read is like 4343. And so that's your port for that. And you would go implement a broker and that broker then could subscribe, right? Or, Yeah, could subscribe to a bunch of topics from a bunch of different sensors. And then could publish those to like an API or a BACnet endpoint or an HTTP endpoint, in Node red, that you could then pull into your building automation system, you could pull it into like digital signage, you could pull it into, you know, just a simple web page, there's a variety of things you can do. So I hope this has been helpful. I know it was a little geeky, I, I kind of I'm always cautious about going down this rabbit hole of whether I get like super geeky on this because I don't want to lose my audience.

Phil Zito 27:24
And, you know, you all it's up to you to tell me like, Is this too in depth? Not in depth enough? I mean, I need that feedback from you. I tried to give you all a bunch of different looks, try to give you you know, workforce development stuff, sales stuff, technical stuff. And so we're gonna continue to give a bunch of different looks and a bunch of different information as we go through these podcast episodes. Best thing you can do for us is to like and subscribe and comment that fuels the algorithm which gets more eyeballs on these episodes. If you're listening to this on like iTunes, Stitcher, Facebook, etc. You also like subscribe, comment and rate. Those really help out. Everything will be available at podcast smart builders academy.com For slash 335. And I also really encourage you to check out our PID Loop tuning bootcamp live paid course, which will be coming Tuesday, May 17, at 8am pacific time and running for four hours if you've struggled with PID loops, or maybe you have a friend that struggles with PID loops. Definitely, you'll want to attend this course. Thank you so much for being here. I'll see you all on Friday. I believe we're going to be talking about some sales stuff on Friday, so it's gonna be a lot of fun. Thanks so much. And I will see y'all on the next episode. Take care

Phil Zito

Written by Phil Zito

Want to be a guest on the Podcast?