<!--DEBUG:--><!--DEBUG:dc3-united-states-software-in-english-pdf-2--><!--DEBUG:--><!--DEBUG:dc3-united-states-software-in-english-pdf-2--><!--DEBUG-spv-->{"id":2044518,"date":"2021-11-28T16:55:00","date_gmt":"2021-11-28T14:55:00","guid":{"rendered":"http:\/\/nhub.news\/?p=2044518"},"modified":"2021-11-28T18:03:26","modified_gmt":"2021-11-28T16:03:26","slug":"using-mqtt-for-iiot-apps","status":"publish","type":"post","link":"http:\/\/nhub.news\/de\/2021\/11\/using-mqtt-for-iiot-apps\/","title":{"rendered":"Using MQTT for IIOT Apps"},"content":{"rendered":"<p style=\"text-align: justify;\"><b>Learn about the MQTT communication protocol and how it&#8217;s used in the manufacturing sector to send and receive data from an Opto 22 industrial controller.<\/b><br \/>\nJoin the DZone community and get the full member experience. MQTT is a communication protocol that has taken off in the IIoT community. It\u2019s a lightweight, efficient protocol that works through a publisher\/broker\/subscriber model. It creates an easy way for field devices to communicate and retrieve data from a single location. In this tutorial, we\u2019ll go over MQTT and dive into an example of how you can publish data using a groov EPIC PAC and retrieve the data using an MQTT client. The Open Systems Interconnection (OSI) model is used to describe the way machines and applications communicate between themselves. The model was developed with the idea that a provider can utilize different protocols or software components at every layer without having to re-architect the entire structure. The MQTT protocol will come into play at Layer 7 of the model; on top of TCP\/IP (Layer 4). The reason that this is important is that this keeps a lot of infrastructure in place while redefining how the packets are being sent between devices. As mentioned in the introduction, MQTT will have three large buckets for each node: We thus have the following topology in the world of MQTT: It can be immediately apparent that this type of model has multiple advantages over the traditional polling model. MQTT is often sold to have the following advantages: The protocol will send data when a change is detected. In other words, digital values need to toggle while the analog ones need to change beyond a set threshold \/ deadband. This reduces the amount of traffic on the network and provides only meaningful updates to all the subscribers. The MQTT protocol was designed with efficiency in mind. While HTTP (same OSI layer) has close to 8000 bytes in the header, MQTT has 2. The smaller header once again contributes to faster and more efficient transmission of data over the network. MQTT supports TLS \/ SSL encryptions and thus secures IoT data sent over the protocol. In most instances, MQTT will utilize TCP\/IP. However, it\u2019s possible to use the protocol over other popular IoT networks such as Zigbee and UDP. MQTT provides a special standard called MQTT-SN for these types of applications. IoT devices are designed with unstable network connections in mind. Therefore, Quality Of Service (QoS) plays an important role within the MQTT protocol. The QoS flags will guarantee message delivery and update based on network conditions. Should the network deteriorate, MQTT will enable a higher level of QoS which will ensure repeated attempts at delivering system messages. If you want to learn the basics of the Opto 22 groov EPIC PAC and how to program the various I\/O of the controller, you can read this tutorial. Now, we will enable the onboard MQTT broker, configure the settings and pass the data to a public broker supplied by HiveMQ. Follow the step-by-step guide if you want to get the most out of the configuration and try this on your own. We are using Sparkplug for this example; therefore, the first field should be \u201cMQTT with Sparkplug payloads&#8220;. You may choose to use string payloads; you\u2019ll have to decrypt the data using a different protocol later on. The second, third, and fourth fields are optional. You\u2019ll use them later to retrieve the data. There are multiple MQTT broker software packages available online. One of such solutions is HiveMQ. In addition to the MQTT broker software, HiveMQ provides a public server that is accessible across the globe and can be easily used for testing purposes. Note: We certainly do not recommend using the public MQTT broker for any production solutions. However, it\u2019s an excellent inexpensive and fast way to test an application. HiveMQ Public MQTT Broker Based on the information above, we \u201cAdd MQTT Broker\u201d from our Opto 22 groov EPIC. It\u2019s important to note that the \u201cClient ID\u201d, \u201cUsername\u201d and \u201cPassword\u201d are optional. However, they should be utilized for a production system to maximize security. In our example, we\u2019re publishing to an online public broker; anyone can access the data we\u2019re producing. The Opto 22 groov EPIC PAC works with a wide range of Input and Output modules. The \u201cDemo Centre\u201d we had reviewed in a previous tutorial comes with 4 I\/O cards. One of these cards is configured as an Analog Input Card and can read voltage signals. For the purpose of this example, we\u2019ve wired in an ifm O1D155 distance sensor into input 1 of the analog card. The configuration of the input can be accessed directly from the \u201cgroov Manage\u201d. In our case, the card is in slot 3. Note: Your card may be different and located in a different slot. As mentioned above, we\u2019ve selected a distance sensor to use in this demo. The same procedure can be applied to a different analog or digital type sensor. In addition to the configuration above, we need to open \u201cPAC Control Basic\u201d that we\u2019ve looked at in a previous tutorial and open the Input to external providers. Open the software and load the program that\u2019s running on the PAC or create a new program. Navigate to the Configuration of the IO channel through the menu and set the channel you want to publish through MQTT to \u201cPublic Access\u201d The nearly-last step in the MQTT configuration we need to complete is adding the controller as a \u201cDevice\u201d and source of data. Add the PLC per the configuration below. The \u201cDevice ID\u201d will be used to poll for data. Now that we\u2019ve finalized the configuration, enable the client on the Opto 22 groov EPIC PAC and make sure that the status is set to \u201cRunning\u201d. MQTT.fx is an MQTT client that can request data from an MQTT broker. At this point, our PAC should be publishing data to HiveMQ. We need this software to view the published data. The tool can be downloaded here: MQTT.fx Download Launch MQTT.fx and Click the Gear Icon to configure the server. Configure the server to the same settings we had outlined above. Use the \u201cConnect\u201d button on the main screen to connect to the server you\u2019ve configured. We now need to build the string that would retrieve the data from the server. Let\u2019s look at every element of the string. Here\u2019s the string we subscribe to: Note that there are other strings you can use to see additional data about the processor. You can use the wildcard (\u201c#\u201d) to open your connection to all substrings. For example, It\u2019s convenient to test with the string \u201cspBv1.0\/SolisPLC\/#\u201d and see the status of MQTT being enabled and disabled. The GIF below displays the data coming into the MQTT.fx software. This tool is used to retrieve the string from the broker which can be accessed by any other Consumer as needed. The string we see has the following format: The two values most important to us are the \u201ctimestamp\u201d and \u201cvalue\u201d. These represent at which point in time the reading from the input was taken and what was the value at that time in Volts. MQTT is quickly gaining popularity among IIoT device manufacturers. It is a robust, lightweight protocol that is being utilized to centralize data, decrease traffic load on the network, and optimize how data is being distributed across different nodes. MQTT uses a publisher\/subscriber model. The publisher pushes data to the server while the subscriber retrieves the data it requires. In this tutorial, we\u2019ve implemented a simple MQTT example using the Opto 22 groov EPIC hardware with one of the inputs tied to a distance measurement sensor. We\u2019ve published the data from the sensor to a public HiveMQ broker and retrieved it using the MQTT.fx tool. We\u2019ve learned how to create the data and retrieve the information we need. Published at DZone with permission of Vladimir Romanov. See the original article here. Opinions expressed by DZone contributors are their own.<\/p>\n<script>jQuery(function(){jQuery(\".vc_icon_element-icon\").css(\"top\", \"0px\");});<\/script><script>jQuery(function(){jQuery(\"#td_post_ranks\").css(\"height\", \"10px\");});<\/script><script>jQuery(function(){jQuery(\".td-post-content\").find(\"p\").find(\"img\").hide();});<\/script>","protected":false},"excerpt":{"rendered":"<p>Learn about the MQTT communication protocol and how it&#8217;s used in the manufacturing sector to send and receive data from an Opto 22 industrial controller. Join the DZone community and get the full member experience. MQTT is a communication protocol that has taken off in the IIoT community. It\u2019s a lightweight, efficient protocol that works [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2044517,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[93],"tags":[],"_links":{"self":[{"href":"http:\/\/nhub.news\/de\/wp-json\/wp\/v2\/posts\/2044518"}],"collection":[{"href":"http:\/\/nhub.news\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/nhub.news\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/nhub.news\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/nhub.news\/de\/wp-json\/wp\/v2\/comments?post=2044518"}],"version-history":[{"count":1,"href":"http:\/\/nhub.news\/de\/wp-json\/wp\/v2\/posts\/2044518\/revisions"}],"predecessor-version":[{"id":2044519,"href":"http:\/\/nhub.news\/de\/wp-json\/wp\/v2\/posts\/2044518\/revisions\/2044519"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/nhub.news\/de\/wp-json\/wp\/v2\/media\/2044517"}],"wp:attachment":[{"href":"http:\/\/nhub.news\/de\/wp-json\/wp\/v2\/media?parent=2044518"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/nhub.news\/de\/wp-json\/wp\/v2\/categories?post=2044518"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/nhub.news\/de\/wp-json\/wp\/v2\/tags?post=2044518"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}