<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: EMQ Technologies</title>
    <description>The latest articles on DEV Community by EMQ Technologies (@emqtech).</description>
    <link>https://dev.to/emqtech</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F874099%2Fccf5f3c9-3233-4eba-a839-8b13265a4e98.jpg</url>
      <title>DEV Community: EMQ Technologies</title>
      <link>https://dev.to/emqtech</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/emqtech"/>
    <language>en</language>
    <item>
      <title>How to Use MQTT in C# with MQTTnet</title>
      <dc:creator>EMQ Technologies</dc:creator>
      <pubDate>Thu, 24 Oct 2024 08:25:46 +0000</pubDate>
      <link>https://dev.to/emqx/how-to-use-mqtt-in-c-with-mqttnet-1j97</link>
      <guid>https://dev.to/emqx/how-to-use-mqtt-in-c-with-mqttnet-1j97</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;With the rise of IoT, the .Net framework has become increasingly popular in building IoT applications. Microsoft's .Net Core and .Net Framework provide developers with a set of tools and libraries to build IoT applications that can run on Raspberry Pi, HummingBoard, BeagleBoard, Pine A64, and more.&lt;/p&gt;

&lt;p&gt;MQTTnet is a high-performance .Net library that implements the &lt;a href="https://www.emqx.com/en/blog/the-easiest-guide-to-getting-started-with-mqtt" rel="noopener noreferrer"&gt;MQTT protocol&lt;/a&gt;. It is open source on &lt;a href="https://github.com/dotnet/MQTTnet" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt; and has a rich set of features, including MQTT 5.0 protocol and TLS/SSL supports.&lt;/p&gt;

&lt;p&gt;This blog post demonstrates how to use the MQTTnet library to connect to a serverless MQTT broker. The whole project can be downloaded at &lt;a href="https://github.com/emqx/MQTT-Client-Examples/tree/master/mqtt-client-Csharp-MqttNet" rel="noopener noreferrer"&gt;MQTT Client Examples&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prepare an MQTT Broker
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.emqx.com/en/cloud/serverless-mqtt" rel="noopener noreferrer"&gt;EMQX Serverless&lt;/a&gt; is an &lt;a href="https://www.emqx.com/en/blog/the-ultimate-guide-to-mqtt-broker-comparison" rel="noopener noreferrer"&gt;MQTT broker&lt;/a&gt; offering on the public cloud with all the serverless advantages. You can start the Serverless deployment in seconds with just a few clicks. Additionally, users can get 1 million free session minutes every month, sufficient for 23 devices to be online for a whole month, making it perfect for tiny IoT test scenarios.&lt;/p&gt;

&lt;p&gt;You can follow &lt;a href="https://www.emqx.com/en/blog/a-comprehensive-guide-to-serverless-mqtt-service" rel="noopener noreferrer"&gt;the guide in this blog&lt;/a&gt; to create a serverless deployment for free. Once you have completed the registration process with the online guide, you will get a running instance with the following similar information from the “Overview” in your deployment. We will use the connection information and CA certificate later.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz34cdkg9nwa35cztuinv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz34cdkg9nwa35cztuinv.png" alt="EMQX MQTT Cloud" width="800" height="381"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  MQTT C# Demo
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Install .Net and Visual Studio
&lt;/h3&gt;

&lt;p&gt;If you haven't installed the .NET environment on your computer yet, you can visit the &lt;a href="https://learn.microsoft.com/en-us/dotnet/core/install/" rel="noopener noreferrer"&gt;official Microsoft documentation&lt;/a&gt; for detailed instructions.&lt;/p&gt;

&lt;p&gt;Visual Studio is a comprehensive IDE for .NET developers that provides a feature-rich environment for developing, debugging, and deploying .NET applications. You can download and install it &lt;a href="https://visualstudio.microsoft.com/downloads/" rel="noopener noreferrer"&gt;here&lt;/a&gt;, based on your computer's system and version.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Install the MQTTnet package
&lt;/h3&gt;

&lt;p&gt;MQTTnet is delivered via NuGet package manager. To install it, create a Console Application and use NuGet to install the MQTTnet package. For detailed instructions on using NuGet in Visual Studio, refer to the &lt;a href="https://learn.microsoft.com/en-us/nuget/consume-packages/install-use-packages-visual-studio" rel="noopener noreferrer"&gt;official documentation&lt;/a&gt;. If you're using Visual Studio for Mac, refer to &lt;a href="https://learn.microsoft.com/en-us/visualstudio/mac/nuget-walkthrough?toc=/nuget/toc.json" rel="noopener noreferrer"&gt;install and manage NuGet packages in Visual Studio for Mac&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Set up the MQTT connection
&lt;/h3&gt;

&lt;p&gt;To connect to the EMQX Serverless broker, you need to create an instance of the &lt;code&gt;MqttClientOptionsBuilder&lt;/code&gt; class and set the necessary options like broker address, port, username, and password. The code snippet below demonstrates how to create an instance of the &lt;code&gt;MqttClientOptionsBuilder&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;        &lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;broker&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"******.emqxsl.com"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;port&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;8883&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;clientId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Guid&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;NewGuid&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;ToString&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;topic&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Csharp/mqtt"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;username&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"emqxtest"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"******"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="c1"&gt;// Create a MQTT client factory&lt;/span&gt;
        &lt;span class="n"&gt;var&lt;/span&gt; &lt;span class="n"&gt;factory&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;MqttFactory&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="c1"&gt;// Create a MQTT client instance&lt;/span&gt;
        &lt;span class="n"&gt;var&lt;/span&gt; &lt;span class="n"&gt;mqttClient&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;factory&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CreateMqttClient&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="c1"&gt;// Create MQTT client options&lt;/span&gt;
        &lt;span class="n"&gt;var&lt;/span&gt; &lt;span class="n"&gt;options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;MqttClientOptionsBuilder&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithTcpServer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;broker&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// MQTT broker address and port&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithCredentials&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;username&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Set username and password&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithClientId&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;clientId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithCleanSession&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Build&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Please replace the connection parameters with your EMQX connection information and login credentials.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Broker and port: Obtain the connection address and port information from the server deployment overview page.&lt;/li&gt;
&lt;li&gt;Topic: Topics are used to identify and differentiate between different messages, forming the basis of MQTT message routing.&lt;/li&gt;
&lt;li&gt;Client ID: Every MQTT client must have a unique client ID. You can use &lt;code&gt;Guid.NewGuid()&lt;/code&gt; to generate a new unique identifier in .NET.&lt;/li&gt;
&lt;li&gt;Username and password: To establish a client connection, please make sure that you provide the correct username and password. The following image shows how to configure these credentials under 'Authentication &amp;amp; ACL - Authentication' on the server side.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpvf1ctk2vwhqdofmfmhe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpvf1ctk2vwhqdofmfmhe.png" alt="Authentication &amp;amp; ACL" width="800" height="181"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Using TLS/SSL
&lt;/h3&gt;

&lt;p&gt;When connecting to EMQX Serverless, it is important to note that it relies on a multi-tenant architecture, which enables multiple users to share a single EMQX cluster. In order to ensure the security and reliability of data transmission within this multi-tenant environment, TLS is required. And if the server is utilizing a self-signed certificate, you must download the corresponding CA file from the deployment overview panel and provide it during the connection setup process.&lt;/p&gt;

&lt;p&gt;To add TLS and set the certificate file to the &lt;code&gt;MqttClientOptionsBuilder&lt;/code&gt; instance, you can use &lt;code&gt;WithTls()&lt;/code&gt;. The following code snippet shows how to create a TLS instance of &lt;code&gt;MqttClientOptionsBuilder&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;        &lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;broker&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"******.emqxsl.com"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;port&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;8883&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;clientId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Guid&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;NewGuid&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;ToString&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;topic&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Csharp/mqtt"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;username&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"emqxtest"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"******"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="c1"&gt;// Create a MQTT client factory&lt;/span&gt;
        &lt;span class="n"&gt;var&lt;/span&gt; &lt;span class="n"&gt;factory&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;MqttFactory&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="c1"&gt;// Create a MQTT client instance&lt;/span&gt;
        &lt;span class="n"&gt;var&lt;/span&gt; &lt;span class="n"&gt;mqttClient&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;factory&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CreateMqttClient&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="c1"&gt;// Create MQTT client options&lt;/span&gt;
        &lt;span class="n"&gt;var&lt;/span&gt; &lt;span class="n"&gt;options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;new&lt;/span&gt; &lt;span class="n"&gt;MqttClientOptionsBuilder&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithTcpServer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;broker&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// MQTT broker address and port&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithCredentials&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;username&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Set username and password&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithClientId&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;clientId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithCleanSession&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithTls&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                &lt;span class="n"&gt;o&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
                &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="c1"&gt;// The used public broker sometimes has invalid certificates. This sample accepts all&lt;/span&gt;
                    &lt;span class="c1"&gt;// certificates. This should not be used in live environments.&lt;/span&gt;
                    &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CertificateValidationHandler&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

                    &lt;span class="c1"&gt;// The default value is determined by the OS. Set manually to force version.&lt;/span&gt;
                    &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;SslProtocol&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;SslProtocols&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Tls12&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;;&lt;/span&gt;

                    &lt;span class="c1"&gt;// Please provide the file path of your certificate file. The current directory is /bin.&lt;/span&gt;
                    &lt;span class="n"&gt;var&lt;/span&gt; &lt;span class="n"&gt;certificate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;new&lt;/span&gt; &lt;span class="n"&gt;X509Certificate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/opt/emqxsl-ca.crt"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
                    &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Certificates&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;new&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;X509Certificate&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;certificate&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Build&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  5. Connect to the MQTT broker
&lt;/h3&gt;

&lt;p&gt;Now that you have created the &lt;a href="https://www.emqx.com/en/blog/mqtt-client-tools" rel="noopener noreferrer"&gt;MQTT client&lt;/a&gt; and set up the connection options, you are ready to connect to the broker. Simply use the &lt;code&gt;PublishAsync&lt;/code&gt; method of the MQTT client to establish a connection and start sending and receiving messages.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="n"&gt;var&lt;/span&gt; &lt;span class="n"&gt;connectResult&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;await&lt;/span&gt; &lt;span class="n"&gt;mqttClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ConnectAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we use asynchronous programming, which allows message publishing while subscribing to prevent blocking.&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Subscribe to topics
&lt;/h3&gt;

&lt;p&gt;Once connected to the broker, you can verify the success of the connection by checking the value of &lt;code&gt;ResultCode&lt;/code&gt;. If the connection is successful, you can subscribe to &lt;a href="https://www.emqx.com/en/blog/advanced-features-of-mqtt-topics" rel="noopener noreferrer"&gt;MQTT topics&lt;/a&gt; to receive messages.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;connectResult&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ResultCode&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;MqttClientConnectResultCode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Success&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Connected to MQTT broker successfully."&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

            &lt;span class="c1"&gt;// Subscribe to a topic&lt;/span&gt;
            &lt;span class="n"&gt;await&lt;/span&gt; &lt;span class="n"&gt;mqttClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;SubscribeAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;topic&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

            &lt;span class="c1"&gt;// Callback function when a message is received&lt;/span&gt;
            &lt;span class="n"&gt;mqttClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ApplicationMessageReceivedAsync&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="s"&gt;"Received message: {Encoding.UTF8.GetString(e.ApplicationMessage.PayloadSegment)}"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CompletedTask&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Within this function, you can also print the the corresponding received messages. This allows you to view and process the received data as needed.&lt;/p&gt;

&lt;h3&gt;
  
  
  7. Publish messages
&lt;/h3&gt;

&lt;p&gt;To send messages to the broker, use the &lt;code&gt;PublishAsync&lt;/code&gt; method of the MQTT client. Here is an example for sending messages to the broker in a loop, with one message sent every second:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;var&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;new&lt;/span&gt; &lt;span class="n"&gt;MqttApplicationMessageBuilder&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
                    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithTopic&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;topic&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithPayload&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="s"&gt;"Hello, MQTT! Message number {i}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithQualityOfServiceLevel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;MqttQualityOfServiceLevel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AtLeastOnce&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithRetainFlag&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
                    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Build&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

                &lt;span class="n"&gt;await&lt;/span&gt; &lt;span class="n"&gt;mqttClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;PublishAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
                &lt;span class="n"&gt;await&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Delay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Wait for 1 second&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  8. Unsubscribe
&lt;/h3&gt;

&lt;p&gt;To unsubscribe, call:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="n"&gt;await&lt;/span&gt; &lt;span class="n"&gt;mqttClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;UnsubscribeAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;topic&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  9. Disconnect
&lt;/h3&gt;

&lt;p&gt;To disconnect, call:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="n"&gt;await&lt;/span&gt; &lt;span class="n"&gt;mqttClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;DisconnectAsync&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Complete Code
&lt;/h2&gt;

&lt;p&gt;The following code shows how to connect to the server, subscribe to topics, and publish and receive messages. For a complete demonstration of all functions, see the project's &lt;a href="https://github.com/emqx/MQTT-Client-Examples/tree/master/mqtt-client-Csharp-MqttNet" rel="noopener noreferrer"&gt;GitHub repository&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="n"&gt;using&lt;/span&gt; &lt;span class="n"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Security&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Authentication&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;using&lt;/span&gt; &lt;span class="n"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Security&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Cryptography&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;X509Certificates&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;using&lt;/span&gt; &lt;span class="n"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;using&lt;/span&gt; &lt;span class="n"&gt;MQTTnet&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;using&lt;/span&gt; &lt;span class="n"&gt;MQTTnet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Client&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;using&lt;/span&gt; &lt;span class="n"&gt;MQTTnet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Protocol&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;class&lt;/span&gt; &lt;span class="n"&gt;Program&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="n"&gt;async&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt; &lt;span class="n"&gt;Main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;broker&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="o"&gt;******&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;emqxsl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;port&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;8883&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;clientId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Guid&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;NewGuid&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;ToString&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;topic&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Csharp/mqtt"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;username&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="n"&gt;emqxtest&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="o"&gt;**********&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="c1"&gt;// Create a MQTT client factory&lt;/span&gt;
        &lt;span class="n"&gt;var&lt;/span&gt; &lt;span class="n"&gt;factory&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;new&lt;/span&gt; &lt;span class="n"&gt;MqttFactory&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="c1"&gt;// Create a MQTT client instance&lt;/span&gt;
        &lt;span class="n"&gt;var&lt;/span&gt; &lt;span class="n"&gt;mqttClient&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;factory&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CreateMqttClient&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="c1"&gt;// Create MQTT client options&lt;/span&gt;
        &lt;span class="n"&gt;var&lt;/span&gt; &lt;span class="n"&gt;options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;new&lt;/span&gt; &lt;span class="n"&gt;MqttClientOptionsBuilder&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithTcpServer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;broker&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// MQTT broker address and port&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithCredentials&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;username&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Set username and password&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithClientId&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;clientId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithCleanSession&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithTls&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                &lt;span class="n"&gt;o&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
                &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="c1"&gt;// The used public broker sometimes has invalid certificates. This sample accepts all&lt;/span&gt;
                    &lt;span class="c1"&gt;// certificates. This should not be used in live environments.&lt;/span&gt;
                    &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CertificateValidationHandler&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

                    &lt;span class="c1"&gt;// The default value is determined by the OS. Set manually to force version.&lt;/span&gt;
                    &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;SslProtocol&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;SslProtocols&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Tls12&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 

                    &lt;span class="c1"&gt;// Please provide the file path of your certificate file. The current directory is /bin.&lt;/span&gt;
                    &lt;span class="n"&gt;var&lt;/span&gt; &lt;span class="n"&gt;certificate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;new&lt;/span&gt; &lt;span class="n"&gt;X509Certificate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/opt/emqxsl-ca.crt"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
                    &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Certificates&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;new&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;X509Certificate&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;certificate&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Build&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="c1"&gt;// Connect to MQTT broker&lt;/span&gt;
        &lt;span class="n"&gt;var&lt;/span&gt; &lt;span class="n"&gt;connectResult&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;await&lt;/span&gt; &lt;span class="n"&gt;mqttClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ConnectAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;connectResult&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ResultCode&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;MqttClientConnectResultCode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Success&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Connected to MQTT broker successfully."&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

            &lt;span class="c1"&gt;// Subscribe to a topic&lt;/span&gt;
            &lt;span class="n"&gt;await&lt;/span&gt; &lt;span class="n"&gt;mqttClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;SubscribeAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;topic&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

            &lt;span class="c1"&gt;// Callback function when a message is received&lt;/span&gt;
            &lt;span class="n"&gt;mqttClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ApplicationMessageReceivedAsync&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="s"&gt;"Received message: {Encoding.UTF8.GetString(e.ApplicationMessage.PayloadSegment)}"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CompletedTask&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="p"&gt;};&lt;/span&gt;

            &lt;span class="c1"&gt;// Publish a message 10 times&lt;/span&gt;
            &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;var&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;new&lt;/span&gt; &lt;span class="n"&gt;MqttApplicationMessageBuilder&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
                    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithTopic&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;topic&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithPayload&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="s"&gt;"Hello, MQTT! Message number {i}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithQualityOfServiceLevel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;MqttQualityOfServiceLevel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AtLeastOnce&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithRetainFlag&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
                    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Build&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

                &lt;span class="n"&gt;await&lt;/span&gt; &lt;span class="n"&gt;mqttClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;PublishAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
                &lt;span class="n"&gt;await&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Delay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Wait for 1 second&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;

            &lt;span class="c1"&gt;// Unsubscribe and disconnect&lt;/span&gt;
            &lt;span class="n"&gt;await&lt;/span&gt; &lt;span class="n"&gt;mqttClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;UnsubscribeAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;topic&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="n"&gt;await&lt;/span&gt; &lt;span class="n"&gt;mqttClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;DisconnectAsync&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="s"&gt;"Failed to connect to MQTT broker: {connectResult.ResultCode}"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Test
&lt;/h2&gt;

&lt;p&gt;Run the project in Visual Studio, we can see the output information on the terminal window as follows. The client has successfully connected to the MQTT broker, and received a message every second.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6abqalkkjrdz6fqep7gb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6abqalkkjrdz6fqep7gb.png" alt="Run the project in Visual Studio" width="800" height="456"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also use &lt;a href="https://mqttx.app/" rel="noopener noreferrer"&gt;MQTT Client Tool - MQTTX&lt;/a&gt; as another client for the message publishing and receiving the test. If you subscribe the “&lt;code&gt;Csharp/mqtt&lt;/code&gt;" topic in MQTTX, you will receive the message every second.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fati6q35xafzozf691cuk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fati6q35xafzozf691cuk.png" alt="MQTTX" width="800" height="524"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When you publish a message to the topic, the server will receive the message and you can view it both on MQTTX and in the console.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4opg0ptcn3lfvxbly2mx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4opg0ptcn3lfvxbly2mx.png" alt="Received message displayed on MQTTX" width="800" height="524"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Received message displayed on MQTTX&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx3lts89prvn58h2lwbvz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx3lts89prvn58h2lwbvz.png" alt="Received message displayed on terminal" width="800" height="507"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Received message displayed on terminal&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;This blog provides a step-by-step guide on connecting to a serverless MQTT deployment via the MQTTnet library. By following these instructions, you have successfully created a .Net application capable of publishing and subscribing to Serverless MQTT.&lt;/p&gt;

&lt;p&gt;Originally published at &lt;a href="https://www.emqx.com/en/blog/connecting-to-serverless-mqtt-broker-with-mqttnet-in-csharp" rel="noopener noreferrer"&gt;wwww.emqx.com&lt;/a&gt;.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Running EMQX MQTT Broker on Docker (Bonus: Clustering and Persistence)</title>
      <dc:creator>EMQ Technologies</dc:creator>
      <pubDate>Wed, 23 Oct 2024 07:18:26 +0000</pubDate>
      <link>https://dev.to/emqtech/running-emqx-mqtt-broker-on-docker-bonus-clustering-and-persistence-4mo3</link>
      <guid>https://dev.to/emqtech/running-emqx-mqtt-broker-on-docker-bonus-clustering-and-persistence-4mo3</guid>
      <description>&lt;h2&gt;
  
  
  What Is MQTT on Docker?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.emqx.com/en/blog/the-easiest-guide-to-getting-started-with-mqtt" rel="noopener noreferrer"&gt;MQTT&lt;/a&gt; (Message Queuing Telemetry Transport) is a lightweight messaging protocol designed for low-bandwidth, high-latency networks. Docker is an open-source platform that allows you to automate the deployment, scaling, and management of applications within containers. So, when you run MQTT on Docker, you are deploying the &lt;a href="https://www.emqx.com/en/blog/the-ultimate-guide-to-mqtt-broker-comparison" rel="noopener noreferrer"&gt;MQTT broker&lt;/a&gt; within a Docker container.&lt;/p&gt;

&lt;p&gt;This combination provides a scalable and reliable solution to handle data streams in real-time, particularly in IoT applications. The MQTT broker receives messages from publishers (devices or applications that produce data) and dispatches them to subscribers (devices or applications that consume data). By running the broker on Docker, you can make it easier to deploy and scale your MQTT broker.&lt;/p&gt;

&lt;p&gt;We’ll show how to deploy MQTT on Docker with &lt;a href="https://github.com/emqx/emqx" rel="noopener noreferrer"&gt;EMQX&lt;/a&gt;, a popular, open source MQTT broker. EMQX provides powerful capabilities not available in other open source brokers, such as clustering, persistence, and support for very large scale deployments.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Should You Run an MQTT Broker on Docker?
&lt;/h2&gt;

&lt;p&gt;Running an MQTT broker on Docker provides several advantages.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Rapid deployment:&lt;/strong&gt; Docker containers can be started in a matter of seconds, which means your MQTT broker can be up and running quickly.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Isolation:&lt;/strong&gt; Docker containers run in isolation from each other, ensuring that the broker's processes do not interfere with each other or with the host system. This lets you run multiple instances of the MQTT broker on the same host without any conflicts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scalability:&lt;/strong&gt; Docker allows you to scale your MQTT broker horizontally (by adding more containers) or vertically (by adding more resources to a container). This scalability allows you to handle larger data or transaction volumes. You can automate scalability for large deployments with an orchestrator like Kubernetes (read our guide to &lt;a href="https://www.emqx.com/en/blog/running-mqtt-on-kubernetes" rel="noopener noreferrer"&gt;MQTT with Kubernetes&lt;/a&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Portability:&lt;/strong&gt; Docker containers can run on any system that has Docker installed, regardless of the underlying operating system. This means you can build your MQTT broker on your local system, test it, and then deploy it reliably on any cloud or on-premise server.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Setting Up an MQTT Broker in Docker with Clustering and Persistence
&lt;/h2&gt;

&lt;p&gt;EMQX is the leading open source MQTT broker. It provides a Docker Official Image which is &lt;a href="https://hub.docker.com/_/emqx" rel="noopener noreferrer"&gt;available on Docker Hub&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;A major advantage of EMQX is that it &lt;strong&gt;supports clustering&lt;/strong&gt; for large scale MQTT deployments. Most other articles on this topic show how to set up the &lt;a href="https://www.emqx.com/en/blog/mosquitto-mqtt-broker-pros-cons-tutorial-and-modern-alternatives" rel="noopener noreferrer"&gt;Mosquitto MQTT broker&lt;/a&gt; with Docker - but Mosquitto does not support clustering. Additional EMQX features include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ability to scale up to 100M+ IoT devices in 1 cluster, while maintaining 1M message per second throughput and sub-millisecond latency.&lt;/li&gt;
&lt;li&gt;100% compliant with MQTT 5.0 and 3.x, support for multiple open standard protocols like HTTP, &lt;a href="https://www.emqx.com/en/blog/quic-protocol-the-features-use-cases-and-impact-for-iot-iov" rel="noopener noreferrer"&gt;QUIC&lt;/a&gt;, and WebSocket.&lt;/li&gt;
&lt;li&gt;Secures bi-directional communication with MQTT over TLS/SSL and various authentication mechanisms.&lt;/li&gt;
&lt;li&gt;Uses powerful SQL-based rules engine to extract, filter, enrich and transform IoT data in real-time.&lt;/li&gt;
&lt;li&gt;Ensures high availability and horizontal scalability with a masterless distributed architecture.&lt;/li&gt;
&lt;li&gt;More than 20K+ enterprise users across 50+ countries and regions, connecting 100M+ IoT devices worldwide. Trusted by over 400 customers in mission-critical scenarios including over 70 Fortune 500 companies.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is how to use the EMQX Docker image to quickly get up and running with MQTT.&lt;/p&gt;

&lt;h3&gt;
  
  
  Install Docker
&lt;/h3&gt;

&lt;p&gt;To install Docker, open a terminal window and install Docker using the appropriate command for your operating system. If you're using Ubuntu, for example, you'd use the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight viml"&gt;&lt;code&gt;sudo apt&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="nb"&gt;get&lt;/span&gt; &lt;span class="k"&gt;update&lt;/span&gt;
sudo apt&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="nb"&gt;get&lt;/span&gt; install &lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="k"&gt;y&lt;/span&gt; docker&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="k"&gt;ce&lt;/span&gt; docker&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="k"&gt;ce&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;cli containerd&lt;span class="p"&gt;.&lt;/span&gt;io
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the installation is complete, you can confirm that Docker is running by typing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo systemctl status docker
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output should look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn6shjqo574bkfyfnnj63.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn6shjqo574bkfyfnnj63.png" alt="Install Docker" width="800" height="316"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If everything is set up correctly, you should see Docker listed as active (running).&lt;/p&gt;

&lt;h3&gt;
  
  
  Pull the EMQX Broker Image
&lt;/h3&gt;

&lt;p&gt;To get started with EMQX, the first step is to download the EMQX Docker image from Docker Hub. Open your terminal and run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight nginx"&gt;&lt;code&gt;&lt;span class="k"&gt;docker&lt;/span&gt; &lt;span class="s"&gt;pull&lt;/span&gt; &lt;span class="s"&gt;emqx:latest&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command fetches the latest EMQX broker image and prepares it for use on your machine.&lt;/p&gt;

&lt;h3&gt;
  
  
  Run the EMQX Broker Image
&lt;/h3&gt;

&lt;p&gt;After pulling the image, you can start a new EMQX container. Use the following command to run the EMQX Docker image:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight apache"&gt;&lt;code&gt;docker run -d --name emqx -p 18083:18083 -p 1883:1883 emqx:latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can check if the container is running by executing the docker ps command. The output should look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5f8vlcrcu0jxrpw5sjbg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5f8vlcrcu0jxrpw5sjbg.png" alt="Run the EMQX Broker Image" width="800" height="145"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, the -d flag runs the container in detached mode. Ports 18083 and 1883 are mapped to your host machine, allowing you to interact with the EMQX broker. The EMQX broker runs as the Linux user emqx inside the container.&lt;/p&gt;

&lt;h3&gt;
  
  
  Set MQTT Configuration
&lt;/h3&gt;

&lt;p&gt;You can set configurations via environment variables when running your Docker container. All EMQX settings in etc/emqx.conf can be configured this way (to learn about EMQX configuration options, refer to the &lt;a href="https://docs.emqx.com/en/emqx/v5.0/configuration/configuration-manual.html" rel="noopener noreferrer"&gt;official documentation&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Environment variables with the prefix EMQX_ map to key-value pairs in the configuration files. For example, here's how to set the MQTT TCP port to 1883:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight apache"&gt;&lt;code&gt;docker run -d --name emqx -e EMQX_LISTENERS__TCP__DEFAULT__BIND=1883 -p 18083:18083 -p 1883:1883 emqx:latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, EMQX_LISTENERS*&lt;em&gt;TCP&lt;/em&gt;*DEFAULT__BIND=1883 sets the MQTT TCP port to 1883. The -e flag specifies the environment variable.&lt;/p&gt;

&lt;h3&gt;
  
  
  Set Up Clustering
&lt;/h3&gt;

&lt;p&gt;Before proceeding with this step, please ensure docker-compose is installed on your system.&lt;/p&gt;

&lt;p&gt;For clustering, you can create a &lt;code&gt;docker-compose.yaml&lt;/code&gt; file as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;version: '3'
services:
  emqx1:
    image: emqx:latest
    container_name: emqx1
    environment:
      - "EMQX_NAME=emqx1"
      - "EMQX_HOST=emqx1.emqx.io"
      - "EMQX_CLUSTER__DISCOVERY_STRATEGY=dns"
      - "EMQX_CLUSTER__DNS__RESOLVER=8.8.8.8"
      - "EMQX_CLUSTER__DNS__INTERVAL=5000"
    networks:
      emqx-net:
        aliases:
          - emqx1.emqx.io
    ports:
      - "1883:1883"
      - "8083:8083"

  emqx2:
    image: emqx:latest
    container_name: emqx2
    environment:
      - "EMQX_NAME=emqx2"
      - "EMQX_HOST=emqx2.emqx.io"
      - "EMQX_CLUSTER__DISCOVERY_STRATEGY=dns"
      - "EMQX_CLUSTER__DNS__RESOLVER=8.8.8.8"
      - "EMQX_CLUSTER__DNS__INTERVAL=5000"
    networks:
      emqx-net:
        aliases:
          - emqx2.emqx.io
    ports:
      - "1884:1883"
      - "8084:8083"

networks:
  emqx-net:
    driver: bridge
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then run the cluster with this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;docker-compose&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; &lt;span class="nt"&gt;my_emqx&lt;/span&gt; &lt;span class="nt"&gt;up&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To view the cluster status, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight applescript"&gt;&lt;code&gt;&lt;span class="nv"&gt;docker&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;exec&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="k"&gt;it&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;emqx1&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;sh&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;c&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"emqx_ctl cluster status"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output should look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxmmo60p1m9d885keiiz5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxmmo60p1m9d885keiiz5.png" alt="The output" width="800" height="56"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Set Up Persistence
&lt;/h3&gt;

&lt;p&gt;To persist container data, EMQX requires the following directories to be saved:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;/opt/emqx/data&lt;/li&gt;
&lt;li&gt;/opt/emqx/etc&lt;/li&gt;
&lt;li&gt;/opt/emqx/log&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To make these directories persistent, use volume mounts in your &lt;code&gt;docker-compose.yaml&lt;/code&gt; file like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;services:
  emqx:
    # ... previous configurations
    volumes:
      - vol-emqx-data:/opt/emqx/data
      - vol-emqx-etc:/opt/emqx/etc
      - vol-emqx-log:/opt/emqx/log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output should look something like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F22ezmj9lggx79knrmpiv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F22ezmj9lggx79knrmpiv.png" alt="docker compose up" width="800" height="592"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To ensure the same state when the container restarts, make sure to specify the &lt;code&gt;EMQX_NAME&lt;/code&gt; and &lt;code&gt;EMQX_HOST&lt;/code&gt; variables as previously defined.&lt;/p&gt;

&lt;h2&gt;
  
  
  Large-Scale MQTT Deployment with EMQX
&lt;/h2&gt;

&lt;p&gt;Running MQTT on Docker offers several compelling advantages, including rapid deployment, isolation, scalability, and portability. Leveraging Docker containers for MQTT deployment allows for efficient resource utilization and ease of management.&lt;/p&gt;

&lt;p&gt;For those looking to set up MQTT on Docker with clustering and persistence, EMQX proves to be a powerful choice. EMQX's support for clustering, compliance with MQTT standards, and advanced features make it suitable for large-scale MQTT deployments.&lt;/p&gt;

&lt;p&gt;Read these blog posts to see how to massively scale up MQTT with EMQX:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.emqx.com/en/blog/reaching-100m-mqtt-connections-with-emqx-5-0" rel="noopener noreferrer"&gt;Reaching 100M MQTT connections with EMQX 5.0&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.emqx.com/en/blog/how-emqx-5-0-achieves-100-million-mqtt-connections" rel="noopener noreferrer"&gt;How EMQX with the Mria + RLOG architecture achieves 100M MQTT connections&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.emqx.com/en/blog/running-mqtt-on-kubernetes" rel="noopener noreferrer"&gt;Running MQTT on Kubernetes: A Practical Guide&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.emqx.com/en/blog/rebalancing-mqtt-connections-for-emqx-cluster-on-kubernetes" rel="noopener noreferrer"&gt;Rebalancing MQTT Connections for a More Balanced EMQX Cluster on Kubernetes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.emqx.com/en/blog/exploring-geo-distribution-in-emqx-for-enhanced-scalability" rel="noopener noreferrer"&gt;Beyond Boundaries: Exploring Geo-Distribution in EMQX for Enhanced Scalability&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Originally published at&lt;/em&gt; &lt;a href="https://www.emqx.com/en/blog/running-mqtt-broker-on-docker" rel="noopener noreferrer"&gt;&lt;em&gt;www.emqx.com&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>mqtt</category>
      <category>docker</category>
      <category>emqx</category>
    </item>
    <item>
      <title>A Cloud-Edge Collaborative Solution for Intelligent Oil &amp; Gas Production and Operation</title>
      <dc:creator>EMQ Technologies</dc:creator>
      <pubDate>Thu, 30 Nov 2023 15:13:22 +0000</pubDate>
      <link>https://dev.to/emqx/a-cloud-edge-collaborative-solution-for-intelligent-oil-gas-production-and-operation-3bno</link>
      <guid>https://dev.to/emqx/a-cloud-edge-collaborative-solution-for-intelligent-oil-gas-production-and-operation-3bno</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;With the reduction of oil and gas reserves and the intensification of global market competition, oil and gas production enterprises are seeking digital transformation to optimize resources and enhance production efficiency. EMQ provides a one-stop cloud-edge collaborative IoT solution that addresses common industry challenges such as data collection, system construction and maintenance. It consolidates data generated by different systems onto one platform, facilitating more precise management and reduced costs.&lt;/p&gt;

&lt;p&gt;Based on historical cases, EMQ’s solution can help oil and gas companies save more than 25% in annual collection system maintenance costs and over 40% in data point access costs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Building Intelligent Oil&amp;amp;Gas System with EMQ
&lt;/h2&gt;

&lt;p&gt;EMQ provides a comprehensive cloud-edge collaborative architecture encompassing industrial data acquisition, edge computing, data integration, and remote operational management. This solution can be used by oil and gas companies for real-time monitoring, equipment management, HSE(Health, Safety, Environment) management, smart production, and intelligent applications. With EMQ, enterprises can achieve greater efficiency and better control over their operations.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa200eongahn02k9lfn2r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa200eongahn02k9lfn2r.png" alt="Image description" width="800" height="338"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Real-time Industrial Data Acquisition
&lt;/h3&gt;

&lt;p&gt;The industrial protocol gateway software, NeuronEX, supports various bus and industrial protocols, such as &lt;a href="https://www.emqx.com/en/blog/modbus-protocol-the-grandfather-of-iot-communication" rel="noopener noreferrer"&gt;&lt;strong&gt;Modbus&lt;/strong&gt;&lt;/a&gt;, &lt;a href="https://www.emqx.com/en/blog/opc-ua-protocol" rel="noopener noreferrer"&gt;&lt;strong&gt;OPC UA&lt;/strong&gt;&lt;/a&gt;, Siemens, ABB, Mitsubishi, and Schneider. It collects real-time data from devices in production sites and then converts them into standard &lt;a href="https://www.emqx.com/en/blog/the-easiest-guide-to-getting-started-with-mqtt" rel="noopener noreferrer"&gt;&lt;strong&gt;MQTT protocol&lt;/strong&gt;&lt;/a&gt; messages, with data points adhering to unified formatting standards and millisecond-level timestamps. NeuronEX also caches data offline to ensure the integrity of historical data during network interruptions.&lt;/p&gt;

&lt;p&gt;NeuronEX’s rule engine enables real-time computation and analysis, message standardization, data filtering, intelligent alarms, business routing, data persistence, and more at the edge. This allows oil and gas producers to preprocess data and process event logic at the edge.&lt;/p&gt;

&lt;p&gt;NeuronEX’s HTTP PULL feature allows the perception of the configuration status and operating data of intelligent IT devices at the production field.&lt;/p&gt;

&lt;p&gt;Moreover, NeuronEX can integrate AI for intelligent video monitoring, safety management, equipment maintenance, fault prediction, inspection, and safety monitoring through real-time processing of IoT data and video streams.&lt;/p&gt;

&lt;h3&gt;
  
  
  Enterprise-Grade IoT Message Bus
&lt;/h3&gt;

&lt;p&gt;EMQX Enterprise deployed in the plant-level information center or group cloud provides a unified platform for oil and gas production data on private networks or the internet. This achieves high availability, high concurrency, and low-latency data transmission, analysis, processing, and integration. EMQX Enterprise MQTT platform can simultaneously handle connections from over a million IoT devices and process over a hundred thousand data interactions per second. It is highly suitable for the oil and gas production environment.&lt;/p&gt;

&lt;h2&gt;
  
  
  What You Can Achieve with EMQ
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Comprehensive Perception and Centralized Management
&lt;/h3&gt;

&lt;p&gt;EMQ’s solution facilitates data collection and management from intricate production equipment in oil and gas production, as well as safety and monitoring devices in the field. The cloud-edge collaborative architecture and data aggregation capabilities can address the challenge of centralizing the management of data from originally independent and scattered systems.&lt;/p&gt;

&lt;h3&gt;
  
  
  Cost Reduction and Efficiency Improvement
&lt;/h3&gt;

&lt;p&gt;The solution simplifies the complex maintenance tasks involved in oil and gas production through the unified intelligent management of equipment access, inspections, configurations, upgrades, updates, and alarm handling. This significantly reduces costs caused by manual operation and improves efficiency.&lt;/p&gt;

&lt;h3&gt;
  
  
  Scalability and Flexibility for Future Innovation
&lt;/h3&gt;

&lt;p&gt;The solution provides expandable interfaces to facilitate the integration of new systems and technologies into the business platform. At the edge, it supports the integration of algorithms in MATLAB, C, C++, Python, GO, and AI, promoting innovative development in edge intelligence.&lt;/p&gt;

&lt;p&gt;Standardized configurations speed up IoT platform construction, making it easier to replicant and scale as the business grows.&lt;/p&gt;

&lt;p&gt;The entire solution can be deployed through containerization, supporting cloud-native architecture to achieve unified container orchestration and management. This promotes the integration and innovation of smart oil and gas systems with cloud-native technologies.&lt;/p&gt;

&lt;h2&gt;
  
  
  Related Products
&lt;/h2&gt;

&lt;h3&gt;
  
  
  EMQX Enterprise
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.emqx.com/en/products/emqx" rel="noopener noreferrer"&gt;&lt;strong&gt;EMQX Enterprise&lt;/strong&gt;&lt;/a&gt; is a powerful enterprise-level IoT messaging platform designed for large-scale deployments and high reliability in IoT applications. The following capabilities of EMQX Enterprise can benefit the industry:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;High Reliability and Scalability:&lt;/strong&gt; EMQX Enterprise adopts a distributed architecture with high availability and scalability to handle large-scale concurrent message transmission. It supports horizontal scaling to accommodate the growing number of IoT devices and data traffic, ensuring system stability.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rich Protocol Support:&lt;/strong&gt; EMQX Enterprise supports multiple messaging protocols besides the MQTT protocol. It allows developers to extend to support all kinds of private protocols for their application needs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data Integration:&lt;/strong&gt; EMQX Enterprise seamlessly integrates with various data storage services, message queues, cloud platforms, and applications. It can connect with cloud services, enabling remote data transmission and cloud-based analysis.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Security and Authentication:&lt;/strong&gt; EMQX Enterprise provides robust security features, including TLS/SSL encrypted transmission, client authentication, and access control. It supports various authentication methods such as username/password, X.509 certificates, and OAuth, ensuring the security of IoT communication.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rule Engine and Data Processing&lt;/strong&gt;: EMQX Enterprise has a flexible rule engine for real-time data processing and forwarding based on device data. It supports operations such as data filtering, transformation, aggregation, and persistence, helping users analyze and make decisions based on their business needs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Visual Monitoring and Management&lt;/strong&gt;: EMQX Enterprise provides an intuitive visual monitoring and management interface, allowing users to monitor IoT devices and message transmission in real-time. Users can view connection status, message traffic, and other metrics and perform device management, troubleshooting, and system configuration operations.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  NeuronEX
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.emqx.com/en/products/neuronex" rel="noopener noreferrer"&gt;&lt;strong&gt;NeuronEX&lt;/strong&gt;&lt;/a&gt; is software tailored for the industrial sector, focusing on equipment data collection and edge intelligent analysis. It is primarily deployed in industrial settings, facilitating industrial equipment communication, industrial bus protocol acquisition, industrial system data integration, edge-level data filtering and analysis, AI algorithm integration, and integration with &lt;a href="https://www.emqx.com/en/blog/iiot-platform-key-components-and-5-notable-solutions" rel="noopener noreferrer"&gt;&lt;strong&gt;IIOT platforms&lt;/strong&gt;&lt;/a&gt;. It offers the following features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Diverse Connectivity&lt;/strong&gt;: NeuronEX provides multi-protocol access capability, supporting simultaneous access to dozens of industrial protocols such as Modbus, &lt;a href="https://www.emqx.com/en/blog/opc-ua-protocol" rel="noopener noreferrer"&gt;&lt;strong&gt;OPC UA&lt;/strong&gt;&lt;/a&gt;, Ethernet/IP, &lt;a href="https://www.emqx.com/en/blog/bacnet-protocol-basic-concepts-structure-obejct-model-explained" rel="noopener noreferrer"&gt;&lt;strong&gt;BACnet&lt;/strong&gt;&lt;/a&gt;, Siemens, Mitsubishi, and more. It enables integration with multiple data sources from systems like MES and WMS within the enterprise. NeuronEX also supports bidirectional data flow, allowing both data acquisition and control command issuance to devices.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Deploy anywhere:&lt;/strong&gt; Neuron has very low memory footprints and is suitable for running on low-profile architecture devices like x86, ARM, RISC-V, etc. It also supports docker-like containerized deployment, running with other co-located containers in Kubernetes environments.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data Processing&lt;/strong&gt;: NeuronEX incorporates 100+ built-in functions, supporting data filtering, data manipulation, device control, and data persistence, storing data in a time-series database.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Algorithm Integration&lt;/strong&gt;: NeuronEX supports the integration of algorithms written in languages such as C, Python, and Go. It facilitates real-time inference of industrial mechanism models, machine learning, and deep learning models at the edge, enabling alerts and intelligent decision-making.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Edge to Cloud&lt;/strong&gt;: Through protocols like MQTT and SparkplugB, NeuronEX aggregates and pushes industrial data to cloud platforms. The bidirectional data flow between NeuronEX and the cloud platform establishes cloud-edge data coordination and control synergy, leveraging the platform's big data storage and analysis capabilities to amplify the value of NeuronEX usage.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Originally published at &lt;a href="https://www.emqx.com/en/blog/promoting-cost-reduction-and-efficiency-in-oil-and-gas-production" rel="noopener noreferrer"&gt;www.emqx.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>oil</category>
      <category>gas</category>
      <category>mqtt</category>
    </item>
    <item>
      <title>From Data to Intelligence: One-Stop MQTT Platform for Smart Factory Advancements</title>
      <dc:creator>EMQ Technologies</dc:creator>
      <pubDate>Tue, 21 Nov 2023 12:18:55 +0000</pubDate>
      <link>https://dev.to/emqx/from-data-to-intelligence-one-stop-mqtt-platform-for-smart-factory-advancements-68e</link>
      <guid>https://dev.to/emqx/from-data-to-intelligence-one-stop-mqtt-platform-for-smart-factory-advancements-68e</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In the age of advanced manufacturing, the need for extensive data collection and analysis across all aspects of production is crucial. This data enables factories and enterprises to discover optimization opportunities, improve efficiency and quality, and make informed decisions.&lt;/p&gt;

&lt;p&gt;EMQ smart factory solution is designed to establish comprehensive data collection, transmission, distribution, and other mechanisms. This solution empowers factories to rapidly deploy a wide array of intelligent applications, including equipment health management, optimization of energy consumption equipment, production monitoring and analysis, product quality traceability, parameter optimization in the supply chain, predictive maintenance, and defect detection. This facilitates the manufacturing industry's transition towards digital and intelligent transformation.&lt;/p&gt;

&lt;h2&gt;
  
  
  EMQ Smart Factory Solution: Overcoming Challenges of Manufacturing
&lt;/h2&gt;

&lt;p&gt;EMQ smart factory solution offers real-time monitoring of crucial data such as equipment status, production metrics, and quality markers. This enables factory management to stay up-to-date on production statuses, allowing quick decision-making and adjustments to improve production efficiency and product quality.&lt;/p&gt;

&lt;p&gt;In addition to real-time monitoring, this solution also facilitates data analysis and extraction. By utilizing machine learning and AI algorithms, it uncovers valuable insights from vast production data. For instance, it can predict equipment failures and recommend necessary maintenance measures by analyzing equipment performance and operational data, preventing production disruptions and losses.&lt;/p&gt;

&lt;h3&gt;
  
  
  Eliminating Data Silos
&lt;/h3&gt;

&lt;p&gt;In manufacturing factories, different devices and systems often use diverse protocols and formats, causing a lack of efficient data sharing akin to isolated islands. This results in a scattered distribution of a company's digital resources. EMQ comes to the rescue by enabling seamless access and sharing of extensive real-time data. It supports industrial equipment protocols and can seamlessly amalgamate diverse system data within the organization. With EMQ’s solution, unifying access to millions of data points becomes feasible, effectively eradicating data silos.&lt;/p&gt;

&lt;h3&gt;
  
  
  Improving Industrial Intelligence
&lt;/h3&gt;

&lt;p&gt;Conventional manufacturing factories often encounter delays in information flow. This can lead to challenges in obtaining real-time data promptly, resulting in excess product inventory and hindered responsiveness to market shifts. EMQ steps in with robust capabilities like data filtering, cleansing, real-time computing, AI-driven analysis, and smart alerts. These tools enhance the intelligence of industrial equipment and enable companies to achieve equipment autonomy, independent decision-making, and nimble production strategies.&lt;/p&gt;

&lt;h3&gt;
  
  
  Break System Barriers And Enhance Data Collaboration
&lt;/h3&gt;

&lt;p&gt;Collaboration obstacles frequently emerge within diverse departments in manufacturing plants, encompassing production, logistics, and quality control. Issues like limited information exchange and communication barriers often result in suboptimal efficiency in collaborative production efforts. By harnessing the power of flexible open APIs, a multi-layer rule engine, and stream data processing, this solution effectively reduces the burden of data processing at the central end and dismantles barriers between systems. This empowers companies to swiftly create advanced applications tailored to specific business scenarios, facilitating seamless teamwork across various machines and systems.&lt;/p&gt;

&lt;h3&gt;
  
  
  Agile Response to Business Growth
&lt;/h3&gt;

&lt;p&gt;The architecture boasts remarkable scalability and flexibility. It can seamlessly expand horizontally as the enterprise's information infrastructure and data volume grow. This expansion ensures a robust SLA to effectively address the increasing demands posed by business growth and diverse data sources.&lt;/p&gt;

&lt;h2&gt;
  
  
  How EMQ Enables Smart Manufacturing
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8s66n31k61is0vq96w0v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8s66n31k61is0vq96w0v.png" alt="Image description" width="800" height="556"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Heterogeneous Data Acquisition
&lt;/h3&gt;

&lt;p&gt;In the industrial domain, a multitude of devices operate using various industrial protocols. Neuron industrial protocol gateway software offers support for common industrial protocols such as &lt;a href="https://www.emqx.com/en/blog/modbus-protocol-the-grandfather-of-iot-communication" rel="noopener noreferrer"&gt;&lt;strong&gt;Modbus&lt;/strong&gt;&lt;/a&gt;, OPC UA, IEC 61850, and IEC 104. This versatile capability allows for the collection of device data from diverse protocols, consolidating it into a unified data platform.&lt;/p&gt;

&lt;p&gt;Furthermore, the solution seamlessly integrates this aggregated data into various other factory systems, encompassing traditional systems like PLC, SCADA, and DCS, as well as production management software like MES, WMS, and ERP. It extends its reach to enterprise service bus (ESB), various databases, and third-party software. Notably, it's also adept at handling unstructured data such as videos and documents, providing comprehensive data integration for enhanced operational insights.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1in3mjhn2x7dgo82na4b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1in3mjhn2x7dgo82na4b.png" alt="Image description" width="800" height="430"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Enterprise-Level MQTT Platform
&lt;/h3&gt;

&lt;p&gt;In contrast to the conventional ISA95 architecture commonly employed in manufacturing, EMQX harnesses the &lt;a href="https://www.emqx.com/en/blog/the-easiest-guide-to-getting-started-with-mqtt" rel="noopener noreferrer"&gt;&lt;strong&gt;MQTT&lt;/strong&gt;&lt;/a&gt; protocol's publish/subscribe model, effectively decoupling data producers and consumers. This approach offers increased ease and flexibility for applications to access real-time factory data.&lt;/p&gt;

&lt;p&gt;The innovative factory data architecture established by the EMQX enterprise-level MQTT platform offers several notable advantages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It provides a unified data access platform, simplifying application development and integration compared to the traditional point-to-point communication in ISA95 setups.&lt;/li&gt;
&lt;li&gt;It enhances data timeliness with low-latency data transmission, enabling intelligent applications such as alarms, instructions, and autonomous equipment operation.&lt;/li&gt;
&lt;li&gt;It streamlines data storage by breaking down data silos, facilitating unified data asset management, and aiding in constructing the factory's data model to unlock the full potential of factory data.&lt;/li&gt;
&lt;li&gt;Its adaptable architecture expansion features, including high-availability clustering, dynamic horizontal scaling, and support for hot upgrades and configurations, ensure a high level of service agreement (SLA) for the system.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Real-Time Processing and Forwarding
&lt;/h3&gt;

&lt;p&gt;EMQX offers robust capabilities for handling real-time streaming data, addressing both low-latency raw data processing and analysis at the device level, as well as large-scale data conversion and distribution in the cloud or data centers.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;With an SQL-like ease of use, it simplifies real-time data tasks such as filtering, transformation, and distribution, thereby maximizing the value derived from data.&lt;/li&gt;
&lt;li&gt;It boasts responsive event triggering, allowing for the swift execution of predefined conditional actions to flexibly process real-time data.&lt;/li&gt;
&lt;li&gt;EMQX provides an array of built-in functions that enhance the effectiveness and efficiency of its rule engine for data stream processing and manipulation.&lt;/li&gt;
&lt;li&gt;It also supports custom function expansions for data processing needs and seamless integration with AI algorithms.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftgaf08fd1ihnr1mqo559.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftgaf08fd1ihnr1mqo559.png" alt="Image description" width="800" height="269"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Data Integration
&lt;/h3&gt;

&lt;p&gt;The EMQX enterprise-level MQTT platform stands out for its efficient data storage capabilities. It seamlessly harnesses EMQX's integrated rule engine to swiftly direct a wide range of device data to various database types, including relational, time series, and hybrid databases. This integration results in the creation of a cohesive repository of enterprise data assets, fostering real-time data sharing and collaboration across departments and teams.&lt;/p&gt;

&lt;p&gt;Notably, each database type achieves an impressive 100,000 transactions per second (TPS) in terms of data writing performance, supporting the real-time storage of over a million high-throughput data measurement points in industrial applications.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9keuz2brewhkqv0qjtv8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9keuz2brewhkqv0qjtv8.png" alt="Image description" width="800" height="326"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Solution Components
&lt;/h2&gt;

&lt;h3&gt;
  
  
  EMQX Enterprise - The One MQTT Platform for IIoT
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.emqx.com/en/products/emqx" rel="noopener noreferrer"&gt;&lt;strong&gt;EMQX Enterprise&lt;/strong&gt;&lt;/a&gt; is the one MQTT platform that helps build and grow your business-critical IoT applications without barriers and limits. It enables you to connect any device, at any scale, anywhere, as well as move and process your IoT data reliably in real-time.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;High Reliability and Scalability:&lt;/strong&gt; EMQX utilizes a distributed architecture with high availability and scalability to handle large-scale concurrent messaging. It supports horizontal scaling to accommodate growing IoT devices and data traffic, ensuring system stability.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rich Protocol Support&lt;/strong&gt;: EMQX supports multiple messaging protocols in addition to MQTT. It allows developers to extend to support a variety of industrial protocols to meet their application needs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data Integration:&lt;/strong&gt; EMQX seamlessly integrates with various data storage services, message queues, cloud platforms, and applications. It can connect to cloud services for remote data transfer and cloud-based analytics.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Security Guarantee:&lt;/strong&gt; EMQX provides strong security features, including TLS/SSL encrypted transmission, client authentication, and access control. It supports multiple authentication methods such as username/password, X.509 certificates, and OAuth to ensure secure IoT communications.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rule Engine and Data Processing&lt;/strong&gt;: EMQX has a flexible rule engine for real-time data processing and forwarding. It supports operations such as data filtering, conversion, aggregation and persistence to help users analyze and make decisions based on business needs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Monitoring and Management&lt;/strong&gt;: EMQX provides an intuitive visual monitoring and management interface that allows users to monitor IoT devices and messaging in real-time. Users can view connection status, message traffic and other metrics, as well as perform device management, troubleshooting and system configuration operations.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  NeuronEX
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.emqx.com/en/products/neuronex" rel="noopener noreferrer"&gt;&lt;strong&gt;NeuronEX&lt;/strong&gt;&lt;/a&gt; is a specialized software designed for the collection of equipment data and edge intelligence analysis within the industrial sector. Its primary application is in industrial environments, where it facilitates communication between industrial equipment, collects data from industrial bus protocols, integrates industrial system data, filters and analyzes data at the edge, and seamlessly integrates AI algorithms. It also enables seamless integration with Industrial Internet platforms and facilitates various related functions.&lt;/p&gt;

&lt;p&gt;NeuronEX, offered as a commercial software service, encompasses both Neuron and eKuiper.&lt;/p&gt;

&lt;p&gt;Originally published at &lt;a href="https://www.emqx.com/en/blog/data-infrastructure-for-smart-factory" rel="noopener noreferrer"&gt;www.emqx.com&lt;br&gt;
&lt;/a&gt;&lt;/p&gt;

</description>
      <category>mqtt</category>
      <category>smartfactory</category>
    </item>
    <item>
      <title>Exploring ISA95 Standards in Manufacturing</title>
      <dc:creator>EMQ Technologies</dc:creator>
      <pubDate>Mon, 16 Oct 2023 13:43:59 +0000</pubDate>
      <link>https://dev.to/emqx/exploring-isa95-standards-in-manufacturing-1im</link>
      <guid>https://dev.to/emqx/exploring-isa95-standards-in-manufacturing-1im</guid>
      <description>&lt;p&gt;In today's rapidly evolving industrial landscape, data has become a critical asset for organizations seeking to streamline processes, improve efficiency, and gain competitive advantage. The realm of automation, particularly in the context of ISA-95, presents both opportunities and challenges in effectively managing data.&lt;/p&gt;

&lt;p&gt;This blog series examines the challenges of data organization in ISA-95 and explores the concept of a &lt;a href="https://www.emqx.com/en/blog/unified-namespace-next-generation-data-fabric-for-iiot" rel="noopener noreferrer"&gt;&lt;strong&gt;unified namespace&lt;/strong&gt;&lt;/a&gt; and its benefits. We will also outline its implementation, including the use of the ISA-95 Equipment Model Standard and clustering for multi-site data replication.&lt;/p&gt;

&lt;p&gt;The first blog explores the fundamental concepts of the ISA-95 standards, their importance in improving manufacturing processes, and their role in fostering cross-functional collaboration, all of which contribute to the optimization and implementation of traditional industrial operations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding ISA-95 Standards
&lt;/h2&gt;

&lt;p&gt;The ISA-95 standard, also known as ANSI/ISA-95 or ISA-95, is an international standard developed by the International Society of Automation (ISA). It focuses on the integration of enterprise and control systems within the manufacturing industry. ISA-95 stands for "Enterprise-Control System Integration," and it provides a framework for designing and implementing interoperability between an organization's business and manufacturing processes, with the goal of improving the interactions between them.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjxuypg6ijvrordbwamj1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjxuypg6ijvrordbwamj1.png" alt="Image description" width="800" height="354"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The primary goal of ISA-95 is to establish a common language and structure for communication and data exchange between different levels of an organization, ranging from the enterprise level, where business decisions are made, down to the control level, where real-time production processes are managed. This standard helps bridge the gap between the information technology (IT) and operational technology (OT) domains.&lt;/p&gt;

&lt;h2&gt;
  
  
  ISA-95 Hierarchy (Automation Pyramid)
&lt;/h2&gt;

&lt;p&gt;The Manufacturing Automation Pyramid is a conceptual representation of ISA-95 hierarchy that is often associated with industrial automation and control systems. The Automation Pyramid, also known as the automation hierarchy of "Industrial 3.0", illustrates the hierarchical structure of control and automation systems within industrial environments. It's a visualization that helps understand the different levels of control and their interconnections in a manufacturing setting.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4naetsa6s2oqcejrh5as.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4naetsa6s2oqcejrh5as.png" alt="Image description" width="800" height="310"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The levels of the Automation Pyramid, from bottom to top, typically include:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Level 0: Field Devices and Instruments:&lt;/strong&gt; This is the lowest level of the pyramid, where physical field devices such as sensors, actuators, and instruments are located. These devices gather data from the manufacturing process and send it to higher levels for processing, and control machinery.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Level 1: Control Devices and PLCs (Programmable Logic Controllers):&lt;/strong&gt; At this level, basic control functions are executed. PLCs and control devices receive input from field devices and make decisions based on pre-programmed logic. They control processes and machinery directly.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Level 2: Supervisory Control:&lt;/strong&gt; This level involves supervisory control systems that gather data from multiple PLCs and control devices. It provides real-time monitoring, data aggregation, and limited control capabilities for specific areas or processes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Level 3: Manufacturing Execution Systems (MES):&lt;/strong&gt; MES is responsible for managing production scheduling, work orders, quality control, and overall coordination of manufacturing operations. It bridges the gap between the shop floor and enterprise systems.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Level 4: Enterprise Systems:&lt;/strong&gt; This is the highest level of the pyramid and includes enterprise resource planning (ERP) systems, which manage business operations, including finance, sales, procurement, and planning. Data from the lower levels feed into these systems for higher-level decision-making.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;ISA-95 is more than just a pyramid hierarchy. On the other hand, it provides a more comprehensive and standardized approach to integrating enterprise and control systems, helping organizations design and implement interoperability between business and manufacturing processes. The Automation Pyramid can be a useful visualization to consider when thinking about the different levels of control within the context of implementing standards like ISA-95.&lt;/p&gt;

&lt;h2&gt;
  
  
  Categories of Information Model
&lt;/h2&gt;

&lt;p&gt;The Categories of Information Model refers to a classification system that organizes and categorizes information exchanged between different levels of an organization's manufacturing processes. This model provides a structured framework for defining and understanding the types of information that need to be exchanged to ensure effective communication and integration between business and manufacturing processes.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Control and Monitoring:&lt;/strong&gt; This category includes information related to the real-time control and monitoring of equipment, processes, and production activities. It involves data such as sensor readings, setpoints, alarms, operational statuses, and other data needed for immediate operational control.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Production Schedule:&lt;/strong&gt; This category encompasses information about production planning and scheduling. It includes data on production orders, work orders, production sequences, start and end times of tasks, and any changes to the production schedule.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Performance Analysis:&lt;/strong&gt; This category involves information that is used to analyze the performance of manufacturing processes. It includes data related to cycle times, production rates, downtime, efficiency metrics, quality measurements, and other performance indicators.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Quality and Compliance:&lt;/strong&gt; Information related to quality control and compliance falls under this category. It includes data about quality standards, inspection results, testing data, non-conformities, corrective actions, and compliance with regulations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Maintenance and Reliability:&lt;/strong&gt; This category includes information about equipment maintenance, reliability, and asset management. It covers data on maintenance schedules, maintenance activities, spare parts inventory, equipment condition monitoring, and predictive maintenance.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Material Flow and Inventory:&lt;/strong&gt; Information regarding the movement of materials, inventory levels, and material requirements is included in this category. It involves data on material consumption, material requests, inventory quantities, and material tracking.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resource Allocation:&lt;/strong&gt; This category encompasses information related to the allocation and utilization of resources, including personnel, equipment, tools, and facilities. It includes data on resource availability, assignments, and usage.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Order Fulfillment:&lt;/strong&gt; Information related to order processing and fulfillment is categorized here. It includes data on customer orders, order status, order changes, shipping details, and delivery schedules.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Equipment Object Model
&lt;/h2&gt;

&lt;p&gt;The Equipment Object Model within the ISA-95 standard focuses on representing the physical and logical equipment and resources used in the manufacturing and production processes. This model provides a structured framework for organizing, categorizing, and managing equipment, allowing for effective monitoring, control, and maintenance within the manufacturing environment.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvqjxc5l4h6afw9i4qzuo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvqjxc5l4h6afw9i4qzuo.png" alt="Image description" width="800" height="545"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This model hierarchy is designed to reflect the physical and logical relationships between different equipment units and their respective roles within the production process. While specific terminologies might vary based on the industry and organization, here is a common organization of the Equipment object model hierarchy:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Enterprise:&lt;/strong&gt; This is the highest level of the hierarchy, representing the entire organization or company. It encompasses all sites and facilities.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Site:&lt;/strong&gt; A site is a physical location or facility where manufacturing operations occur. It can be a factory, plant, or any other facility. Multiple areas or zones can exist within a site.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Area:&lt;/strong&gt; An area represents a specific section within a site where a particular type of manufacturing activity takes place. Areas could be designated for different processes, products, or functions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Unit:&lt;/strong&gt; A unit refers to a distinct piece of equipment or a specific production unit within an area. Units can be individual machines, assembly lines, or process units. They are the primary operational components of the manufacturing process.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Control Module:&lt;/strong&gt; A control module represents a functional aspect or module of a unit that can be controlled and monitored independently. It could be a specific subsystem, device, or component within a larger unit.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Component:&lt;/strong&gt; A component represents smaller parts or sub-components that make up a control module. This level might not be present in all hierarchies and is particularly useful for complex systems.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The purpose of ISA88 is to provide standards and recommended practices as appropriate for the design and specification of batch control systems as used in the process control industries.&lt;/p&gt;

&lt;h2&gt;
  
  
  Information Exchange between Level 4 (ERP) and Level 3 (MES)
&lt;/h2&gt;

&lt;p&gt;The Information Exchange Model between Level 4 (Enterprise) and Level 3 (Manufacturing Operations Management) within the ISA-95 framework involves the communication and data exchange between the business processes at the enterprise level and the manufacturing operations processes at the operations management level. This exchange is crucial for aligning business strategies, production planning, and execution on the shop floor.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F96kqf5t6p6dkz1bsj9rp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F96kqf5t6p6dkz1bsj9rp.png" alt="Image description" width="800" height="280"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The information models can be classified as Resource, Production Capability, Product Definition, Production Schedule, and Production Performance.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Resource Availability:&lt;/strong&gt; Level 3 provides real-time updates to Level 4 about the current availability of resources and any potential constraints that might impact production. Based on production orders, Level 4 sends requests to allocate specific resources for production activities.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Production Capability:&lt;/strong&gt; Level 4 shares information about the manufacturing capacity and constraints with Level 3. Level 3 replies the utilization of manufacturing capabilities to Level 4, indicating how effectively the available resources are being utilized.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Product Definition:&lt;/strong&gt; Level 4 provides detailed specifications and requirements for the products to be manufactured. Level 3 verifies that the product specifications and requirements from Level 4 are accurate and feasible for production.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Production Schedule:&lt;/strong&gt; Level 3 receives production plans from Level 4, detailing the sequence and timing of manufacturing activities required to fulfill the orders. Then, Level 3 communicates any changes or updates to the production schedule back to Level 4, such as delays, expedited orders, or adjustments due to resource constraints.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Production Performance:&lt;/strong&gt; Level 3 shares real-time progress updates with Level 4, including information on quantities produced, completed tasks, and any deviations from the production plan. Level 3 provides data on quality inspections, test results, and any quality-related issues that arise during production.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In general, Level 4 initiates the exchange by sending production orders, work orders, and resource allocation requests to Level 3. Level 3 responds with updates on resource availability, production progress, quality data, and any changes to the production schedule.&lt;/p&gt;

&lt;h2&gt;
  
  
  Manufacturing Operations Management Activity Model
&lt;/h2&gt;

&lt;p&gt;The Manufacturing Operations Management (MOM) Activity Model is a part of the ISA-95 framework that focuses on breaking down and structuring the activities that occur within the manufacturing operations processes. It provides a detailed view of the tasks and operations that need to be executed on the shop floor to fulfill the requirements specified by higher-level processes, such as production orders and work orders.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fue7t26bn8wykvx5eh8rt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fue7t26bn8wykvx5eh8rt.png" alt="Image description" width="800" height="444"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The MOM Activity Model serves as a bridge between the high-level business processes defined at the enterprise level (Level 4) and the specific actions carried out on the shop floor at the manufacturing operations management level (Level 3).&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In conclusion, the ISA-95 standard has played a significant role in enhancing communication and integration in manufacturing, but adapting it to modern industrial management faces challenges. The evolving complexity of manufacturing, coupled with rapid technological advancements like Industry 4.0, requires flexibility that the standard's structured framework might not fully provide. In modern industrial management, &lt;a href="https://www.emqx.com/en/products/emqx" rel="noopener noreferrer"&gt;&lt;strong&gt;EMQX&lt;/strong&gt;&lt;/a&gt; and &lt;a href="https://neugates.io/" rel="noopener noreferrer"&gt;&lt;strong&gt;Neuron&lt;/strong&gt;&lt;/a&gt; are two essential components that provide an ideal solution. Leveraging them as the &lt;a href="https://www.emqx.com/en/blog/the-ultimate-guide-to-mqtt-broker-comparison" rel="noopener noreferrer"&gt;&lt;strong&gt;MQTT broker&lt;/strong&gt;&lt;/a&gt; and industrial gateway, organizations can elevate connectivity, data handling, and adaptability in dynamic production settings. Together, they seamlessly integrate into today's industrial landscape.&lt;/p&gt;

&lt;p&gt;For more information about the benefits of this combination, please refer to: &lt;a href="https://www.emqx.com/en/blog/modern-messaging-infrastructure-for-smart-manufacturing" rel="noopener noreferrer"&gt;&lt;strong&gt;Modern Messaging Infrastructure for Smart Manufacturing&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://www.emqx.com/en/blog/exploring-isa95-standards-in-manufacturing" rel="noopener noreferrer"&gt;www.emqx.com&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>mqtt</category>
    </item>
    <item>
      <title>10 Important KPIs for Measuring Smart Manufacturing Performance</title>
      <dc:creator>EMQ Technologies</dc:creator>
      <pubDate>Thu, 12 Oct 2023 15:16:16 +0000</pubDate>
      <link>https://dev.to/emqx/10-important-kpis-for-measuring-smart-manufacturing-performance-46g7</link>
      <guid>https://dev.to/emqx/10-important-kpis-for-measuring-smart-manufacturing-performance-46g7</guid>
      <description>&lt;p&gt;As described in &lt;a href="https://www.emqx.com/en/blog/a-deep-dive-into-kpis-for-smart-manufacturing" rel="noopener noreferrer"&gt;&lt;strong&gt;Part 1&lt;/strong&gt;&lt;/a&gt;, KPIs (Key Performance Indicators) are measurable values that organizations use to evaluate their progress toward achieving specific goals and objectives. In the context of manufacturing, KPIs are crucial for monitoring and optimizing various aspects of the production process. They provide quantifiable metrics that help manufacturing companies track performance, identify areas for improvement, and make informed decisions to enhance efficiency, quality, and overall productivity.&lt;/p&gt;

&lt;p&gt;In this blog, Part 2 of the series, we will delve into the 10 crucial KPIs commonly utilized in the manufacturing industry.&lt;/p&gt;

&lt;h2&gt;
  
  
  KPIs for Smart Manufacturing
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. On-time Delivery
&lt;/h3&gt;

&lt;p&gt;To uphold customer satisfaction, manufacturers must prioritize punctual deliveries. A perfect score of 100% is the goal. When deliveries fall behind schedule, various factors could be at play, such as delayed supplies, impractical production timelines, or frequent equipment issues. Maintaining a strong track record of on-time deliveries is paramount for retaining existing clients and enticing new ones.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Calculation:&lt;/strong&gt; On-Time Units Delivered ÷ Total Units Delivered&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Production Schedule Attainment
&lt;/h3&gt;

&lt;p&gt;This aids manufacturers in evaluating the effectiveness of production planning and the alignment of worker performance with set benchmarks. It enables them to identify potential performance issues that might influence timely deliveries. Simply tracking delivery punctuality isn't sufficient; it's equally important to pinpoint the production aspects that are influencing this performance. This analysis facilitates necessary adjustments to enhance delivery efficiency.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Calculation:&lt;/strong&gt; (Actual Output ÷ Planned Output) x 100&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Total Cycle Time
&lt;/h3&gt;

&lt;p&gt;This metric gauges the duration from the commencement of production to shipping, encompassing the entire process of fulfilling a customer order. Excluding intervals and idle periods, it strictly measures the active manufacturing time. The comprehensive cycle time encompasses all stages, spanning from raw materials to the final product. This value is an average derived from the cycle times of all orders. Notably, machine cycle time is part of this metric, revealing machine efficiency and necessitating a comparison with the machine's optimal cycle time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Calculation:&lt;/strong&gt; Net Production Time (NPT) ÷ Number of Units Produced&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Throughput
&lt;/h3&gt;

&lt;p&gt;This indicator provides insight into the efficiency of machine performance. It's monitored in real-time to proactively address emerging concerns before they escalate. Optimal results are achieved in throughput when workers are matched with machines aligning with their proficiency. Furthermore, maintaining machines in excellent condition and streamlining processes to minimize operator involvement yields peak throughput levels.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Calculation:&lt;/strong&gt; Number of Units Produced ÷ Total Time of Production&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Capacity Utilization
&lt;/h3&gt;

&lt;p&gt;This measurement assists in evaluating a machine's utilization of its highest potential output. Ideally, the objective is to maintain the machine in constant operational order, minimizing any periods of inactivity. Given the substantial investment in production equipment, idleness should be avoided. The emphasis lies in maximizing machine capacity to enhance efficiency and reduce expenses.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Calculation:&lt;/strong&gt; (Actual Output ÷ Potential Output) x 100&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Changeover Time
&lt;/h3&gt;

&lt;p&gt;This metric monitors the duration required to complete all tasks within a production run, including activities like unloading/loading, retooling, calibration, and programming for subsequent jobs. This data aids manufacturers in identifying potential areas for enhancement. It might lead to better organization of setup procedures or highlight the need for additional machinery training for staff. Minimizing changeover time translates to reduced production costs, making swift transitions more cost-effective.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Calculation:&lt;/strong&gt; Time to Produce First Item in a Product Batch – Time to Produce Last Item in a Product Batch&lt;/p&gt;

&lt;h3&gt;
  
  
  7. Scrap
&lt;/h3&gt;

&lt;p&gt;Materials that fail to meet quality criteria are classified as scrap. Nevertheless, certain manufacturers categorize any unused raw material as scrap. Monitoring scrap materials is essential for cost control and the production of higher-quality goods.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Calculation:&lt;/strong&gt; Total Scrap ÷ Total Product Run&lt;/p&gt;

&lt;h3&gt;
  
  
  8. Predictive Maintenance
&lt;/h3&gt;

&lt;p&gt;When evaluating the planned maintenance KPI, it's crucial to include all instances of emergency maintenance within the overall maintenance calculations. Ideally, the proportion of planned maintenance categorized as emergency work orders should remain below 15%. Emergency maintenance incurs significantly higher costs due to factors such as overtime, expedited parts, and disrupted production. It's imperative to minimize emergency maintenance occurrences to prevent negative impacts on profitability, downtime, and employee morale.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Calculation:&lt;/strong&gt; (Planned Maintenance Time ÷ Total Maintenance Time) x 100&lt;/p&gt;

&lt;h3&gt;
  
  
  9. Availability
&lt;/h3&gt;

&lt;p&gt;Availability refers to the assessment of machine operational time versus periods of inactivity. Recognizing the extent of downtime within your organization is crucial, given its substantial cost and status as a primary challenge for manufacturers. When determining availability, it's vital to consider both planned and unplanned downtime. Equally important is maintaining a record of downtime causes, enabling subsequent analysis to pinpoint potential enhancements.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Calculation:&lt;/strong&gt; Uptime ÷ (Uptime + Downtime)&lt;/p&gt;

&lt;h3&gt;
  
  
  10. Overall Equipment Effectiveness
&lt;/h3&gt;

&lt;p&gt;This vital KPI evaluates equipment productivity by combining availability, performance, and quality factors. However, it doesn't encompass machine downtime or maintenance periods. It's important to recognize that this KPI offers an incomplete perspective. While a high effectiveness rate may be observed, it's advisable to explore potential underlying issues that might contribute to this figure. In next blog Part 3, we will have a more detailed explanation about OEE because of its importance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Calculation:&lt;/strong&gt; Availability x Performance x Quality&lt;/p&gt;

&lt;h2&gt;
  
  
  Achieve Your KPIs with OMH Offering
&lt;/h2&gt;

&lt;p&gt;The Open Manufacturing Hub (OMH) solution presented by EMQ is a reference architecture for building powerful and scalable Industrial IoT applications that keep your KPIs in control.&lt;/p&gt;

&lt;p&gt;When deploying the OMH solution, it provides access to a set of pre-defined KPIs that offer two flexible options: first can either use them as they are, or second can customize them to meet specific business goals. In addition to providing these predefined KPIs, OMH also includes a robust business intelligence component. This business intelligence feature helps to delve deeper into the data, facilitating a comprehensive analysis of KPIs. Explore and extract insights to gain a richer understanding of the performance of a particular KPI and its impact on the manufacturing processes. This analytical capability is critical to identifying areas for improvement and optimizing operations.&lt;/p&gt;

&lt;p&gt;The OMH solution allows customizing the KPIs based on unique situations. Should a specific scenario require additional measurements or different performance criteria, the organization has the flexibility to define new KPIs that accurately capture the difference of that situation.&lt;/p&gt;

&lt;p&gt;All in all, OMH's comprehensive offering includes both preset and customizable KPIs, along with a powerful business intelligence module. This combination enables the organization to harness the power of data analysis to make informed decisions and continuously refine the manufacturing processes based on real-time insights.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;KPIs play a pivotal role in guiding significant business choices. Individuals overseeing these metrics in manufacturing should feel responsible for their designated areas and consistently monitor them to drive enhancements when required. Flexibility is key. KPIs may evolve to address specific circumstances. Their focus should remain on vital management concerns. Ideally, a business should work with approximately 10 KPIs, as an excessive number can overwhelm and lose effectiveness.&lt;/p&gt;

&lt;p&gt;In addition, an efficient solution is also crucial for optimizing performance and achieving KPIs. With OMH, organizations can easily build powerful, scalable, and data-driven Industrial IoT applications. They will gain real-time insights to optimize industrial processes, improve operational efficiency, and make better decisions.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://www.emqx.com/en/blog/ten-important-kpis-for-measuring-smart-manufacturing-performace" rel="noopener noreferrer"&gt;www.emqx.com&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>mqtt</category>
      <category>iot</category>
    </item>
    <item>
      <title>Modern Messaging Infrastructure for Smart Manufacturing</title>
      <dc:creator>EMQ Technologies</dc:creator>
      <pubDate>Sun, 08 Oct 2023 01:35:20 +0000</pubDate>
      <link>https://dev.to/emqx/modern-messaging-infrastructure-for-smart-manufacturing-deh</link>
      <guid>https://dev.to/emqx/modern-messaging-infrastructure-for-smart-manufacturing-deh</guid>
      <description>&lt;h2&gt;
  
  
  Challenges for Traditional Manufacturing
&lt;/h2&gt;

&lt;p&gt;Running a manufacturing business is a multifaceted and demanding endeavor. Almost all companies face significant challenges, including managing large-scale production processes, maintaining product competitiveness, and navigating various operational complexities. To remain competitive, manufacturing companies consistently seek ways to improve their overall performance. Key areas for enhancement typically include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Operational Efficiency&lt;/li&gt;
&lt;li&gt;Quality Assurance&lt;/li&gt;
&lt;li&gt;Asset Optimization&lt;/li&gt;
&lt;li&gt;Supply Chain Optimization&lt;/li&gt;
&lt;li&gt;Product Innovation&lt;/li&gt;
&lt;li&gt;Environment Sustainability&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Different industries prioritize different challenge areas based on their specific needs and goals. For example, logistics companies may focus on optimizing their supply chain management processes, while food companies may prioritize ensuring the highest standards of food quality. Each industry tailors its focus to meet the unique needs and requirements of its operations. In general, these improvements can be grouped into the six main categories mentioned above.&lt;/p&gt;

&lt;h3&gt;
  
  
  Industry 4.0 Approach
&lt;/h3&gt;

&lt;p&gt;To address these challenges, a significant number of companies are choosing to adopt Industry 4.0 technologies as part of their strategic approach. The adoption of these advanced technologies is intended to accelerate the digital transformation of their manufacturing facilities. By leveraging Industry 4.0 principles and solutions, companies aim to revolutionize their operations and achieve higher levels of automation, more comprehensive product quality tracking systems, faster production scalability, and improved sustainability.&lt;/p&gt;

&lt;h3&gt;
  
  
  Blind Spot for Adopting New Technologies
&lt;/h3&gt;

&lt;p&gt;Before budgeting and implementing new technologies, it is critical for companies to assess the capacity and capabilities of their current IT and OT infrastructure.&lt;/p&gt;

&lt;p&gt;Interoperability of disparate IT and OT systems is a common issue that most companies would overlook. It's better to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Assess the compatibility of existing IT and OT systems with new technologies to ensure no compatibility issues between different systems and devices.&lt;/li&gt;
&lt;li&gt;Plan for necessary integrations or updates to ensure seamless communication and data exchange.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In addition to interoperability, scalability is an important consideration when adopting new technologies. Companies should also consider the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Whether the current infrastructure can scale to support the companies' anticipated growth in data storage and processing requirements.&lt;/li&gt;
&lt;li&gt;The requirement of expanding server capacity, increasing storage capacity, and optimizing data management processes when adding large data processing systems.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Legacy Manufacturing Information Infrastructure
&lt;/h2&gt;

&lt;p&gt;In traditional automation systems, direct communication between management-level systems such as ERP or MES and field-level sensors and devices is limited. The primary communication flow follows a hierarchical structure within the automation pyramid, where data from field-level sensors and devices is collected and processed by control-level devices, such as PLCs and SCADAs, before being shared with the management level.&lt;/p&gt;

&lt;h3&gt;
  
  
  Cascade Data Flow
&lt;/h3&gt;

&lt;p&gt;The flow of information in the automation pyramid generally follows a cascade-like pattern, with data flowing from the bottom (field level) to the top (management level), while control commands or instructions typically flow from the top to the bottom. This pattern of information flow is a fundamental characteristic of the automation pyramid. As a result, communication between the top management IT level and the bottom device OT level is isolated. A large amount of production data is stored or neglected within OT-level systems and devices such as PLCs and SCADA.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsb3nhtzmx5j66s3pkr84.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsb3nhtzmx5j66s3pkr84.png" alt="Image description" width="800" height="1677"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Manual Data Analysis for Traditional Manufacturing
&lt;/h3&gt;

&lt;p&gt;In response to this problem, some large companies use data collection software such as Kepware to periodically collect data from field-level devices and control-level SCADA. This data includes various measurements, process variables, alarms, and other relevant information. It is critical to ensure accurate and reliable data collection to provide a solid foundation for subsequent analysis. Spreadsheet tools such as Microsoft Excel or Google Sheets are widely used for basic data analysis. In addition, tools such as Tableau, Power BI, or QlikView allow users to create visually appealing data visualizations that make it easier to explore and present insights. Of course, such data manipulation is part of manual batch processing for data analysis. It is not as efficient as automated and real-time data processing. More components and systems are added to the information infrastructure. However, more communication channels are created, making data exchange more complicated.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc0uy2fhwo8x4sy7yg4b3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc0uy2fhwo8x4sy7yg4b3.png" alt="Image description" width="800" height="804"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Central Manufacturing Data Hub
&lt;/h2&gt;

&lt;p&gt;As mentioned above, new technologies may create compatibility issues with existing components or systems within the automation pyramid. Different devices, protocols, or software may not seamlessly integrate or communicate with each other. Ensuring compatibility and establishing proper interoperability between new and existing technologies can be a significant challenge. Downtime, system reconfiguration, or training requirements can temporarily impact productivity and workflow.&lt;/p&gt;

&lt;h3&gt;
  
  
  Centralized Data Repository
&lt;/h3&gt;

&lt;p&gt;EMQ introduces a solution called Open Manufacturing Hub (OMH) to ensure interoperability and scalability of the manufacturing information infrastructure by establishing a more flexible and connected approach to data exchange. OMH establishes a centralized data repository to store and manage all data collected from different levels of the automation pyramid. This repository acts as a central hub where data from field-level devices, control-level systems, and management-level applications is consolidated.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fszcceqvyxsab3w86d3bg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fszcceqvyxsab3w86d3bg.png" alt="Image description" width="800" height="775"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the OMH architecture, data can flow bi-directionally between different levels of the automation pyramid. While the traditional cascade-like flow of data from the field level to the management level remains relevant, the OMH enables more dynamic and direct communication between different levels. Data can be accessed and used by multiple levels, enabling real-time monitoring, analysis and control.&lt;/p&gt;

&lt;p&gt;The OMH provides standardized methods for data access via the EMQX broker. It allows authorized users and applications to subscribe to data from any information system in the automation pyramid using consistent and well-defined MQTT interfaces. The OMH also provides standardized methods for device data acquisition through the Neuron gateway. It allows different devices with different data formats to communicate with any other system or device.&lt;/p&gt;

&lt;h3&gt;
  
  
  IT and OT Convergence
&lt;/h3&gt;

&lt;p&gt;The OMH can facilitate interoperability between IT and OT systems within the automation pyramid by providing a rich set of OT industrial protocol communications and IT application connectors, enforcing MQTT standardization for different data formats. It harmonizes data, ensuring consistency and compatibility between components and systems. Standardization enables smoother collaboration and convergence efforts, breaking down information silos.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4g1qj1do1tt02p386ilq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4g1qj1do1tt02p386ilq.png" alt="Image description" width="800" height="333"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By collecting and storing real-time data from OT systems, the OMH enables real-time monitoring and control of manufacturing processes. This facilitates better operational visibility, proactive decision making, and timely intervention to resolve problems or optimize performance. Real-time data from OT systems can be combined with data from IT systems to provide a comprehensive view of the manufacturing environment.&lt;/p&gt;

&lt;h3&gt;
  
  
  Contextualization
&lt;/h3&gt;

&lt;p&gt;This type of IT and OT data combination is the process of data normalization and contextualization, which means combining data from many different sources, such as field-level devices, control systems, and management-level applications, into a single source of information. This integration enables better contextualization by bringing together data from different parts of the manufacturing process.&lt;/p&gt;

&lt;p&gt;In fact, contextualized data is one of the most important features that OMH can provide to analytical applications such as AI/ML. By providing additional context and metadata, AI/ML models can better understand and interpret data, reducing errors and improving accuracy. Therefore, implementing OMH can lead to an improvement in the predictive capabilities of analytic models.&lt;/p&gt;

&lt;p&gt;In conclusion, OMH can change the cascade-like data flow in the automation pyramid to a unified namespace architecture. In general, incorporating OMH into the information infrastructure is just like implementing a unified namespace architecture, which provides the following benefits.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Simplified Data Access&lt;/li&gt;
&lt;li&gt;Improved Collaboration&lt;/li&gt;
&lt;li&gt;Contextualized Data&lt;/li&gt;
&lt;li&gt;Simplified IT Administration&lt;/li&gt;
&lt;li&gt;Scalability and Flexibility&lt;/li&gt;
&lt;li&gt;Interoperability&lt;/li&gt;
&lt;li&gt;Data Consistency&lt;/li&gt;
&lt;li&gt;Improved Data Integrity&lt;/li&gt;
&lt;li&gt;AI/ML Precise Prediction&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Multi Sites Manufacturing
&lt;/h3&gt;

&lt;p&gt;By leveraging the high throughput and low latency capabilities of the EMQX broker, OMH can provide high-speed data replication across multiple sites. High-speed data replication across multiple manufacturing sites ensures the consistency of data shared between sites. When data is replicated, each site has access to the same set of information, ensuring that decisions and actions are based on the most current and synchronized data. This promotes operational consistency, reduces inconsistencies, and enables standardized processes across all sites.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Funggdimu2yvtd6aqlgj3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Funggdimu2yvtd6aqlgj3.png" alt="Image description" width="800" height="748"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Data replication supports scalability and facilitates the expansion of manufacturing operations to new locations. As new sites are added, data can be replicated to those sites, allowing them to quickly access relevant information and integrate into the overall manufacturing ecosystem. This scalability helps streamline operations, accommodate growth, and maintain consistent data across the extended manufacturing network.&lt;/p&gt;

&lt;h2&gt;
  
  
  Distributed Stream Processing Framework
&lt;/h2&gt;

&lt;p&gt;Replicating data to multiple manufacturing sites enables local data access and processing with our edge processing application eKuiper, which is an edge lightweight IoT data analytics/streaming software. Each site can access and manipulate the replicated data locally, reducing the latency and network traffic associated with accessing data from a central location. This improves performance, enables faster response times, and ensures smoother operations within each site.&lt;/p&gt;

&lt;h3&gt;
  
  
  On-Premise Central Control Room
&lt;/h3&gt;

&lt;p&gt;With data from multiple applications and systems in multiple locations integrated into the high-speed OMH in the central control room at headquarters, operators and engineers can view real-time data, alarms and performance metrics through visual dashboards and interfaces. This real-time monitoring provides immediate insight into the status of operations, enabling timely responses and proactive management of manufacturing processes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faoiqdscjyvb2u49iqxqb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faoiqdscjyvb2u49iqxqb.png" alt="Image description" width="800" height="709"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Virtual Analytic Cloud Platform
&lt;/h3&gt;

&lt;p&gt;By leveraging data from diverse sources and various locations, the implementation of a cloud platform replaces the conventional centralized control room at headquarters. Cloud platforms offer the convenience of remote access to data and applications from anywhere with an Internet connection. This enables operators and engineers to efficiently monitor and manage manufacturing processes, promoting seamless remote collaboration and facilitating informed decision-making across the organization.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe60jrfvexz79yqn4g04k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe60jrfvexz79yqn4g04k.png" alt="Image description" width="800" height="709"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Real-time Stream Processing
&lt;/h3&gt;

&lt;p&gt;A hybrid stream processing framework is in place to handle real-time data analysis in both the central control room and the cloud platforms. Analytical tasks are distributed between these environments based on their requirements. The framework includes Apache Kafka, Node-Red, and Apache Flink, which are versatile applications suitable for cloud platforms or on-premises servers. This setup ensures efficient real-time data processing to meet the time constraints of production and effectively addresses the following challenges:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Real-time processing enables rapid response to dynamic changes in the manufacturing environment. It allows the system to continuously monitor data streams, detect deviations, and trigger alerts or automated actions in real time. This agility ensures quick adaptation to evolving conditions, minimizing disruptions and optimizing operational efficiency.&lt;/li&gt;
&lt;li&gt;Real-time processing provides the ability to optimize operational efficiency on the fly. By analyzing real-time data, the system can identify process inefficiencies, resource bottlenecks, or deviations from optimal performance. This allows for immediate adjustments, resource allocation optimization, and dynamic process optimization to enhance overall efficiency and productivity.&lt;/li&gt;
&lt;li&gt;Real-time processing helps in proactive issue detection and prevention. By monitoring data streams in real time, the system can identify patterns or early warning signs of potential issues before they escalate. This allows operators to take preventive measures, initiate maintenance activities, or implement corrective actions in a timely manner, minimizing downtime and improving reliability.&lt;/li&gt;
&lt;li&gt;Real-time processing empowers decision-makers with real-time insights and decision support tools. By analyzing data streams in real time, the system can provide decision-makers with real-time dashboards, alerts, and visualizations. This enables informed decision-making based on up-to-the-minute information, improving response time and overall decision quality.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Successful business transformation requires a shift away from traditional approaches and a renewed focus on scalability and interoperability. This can be achieved by implementing OMH, which centralizes the data repository, creates a contextualized data platform, and delivers the work process in a distributed framework. By addressing the manufacturing challenges, companies can realize the benefits of a scalable and successful data analytics strategy, ultimately leading to a successful adoption of new technologies for Industry 4.0.&lt;/p&gt;

</description>
      <category>mqtt</category>
    </item>
    <item>
      <title>Serverless MQTT: Your Key to Efficient IoT Prototyping</title>
      <dc:creator>EMQ Technologies</dc:creator>
      <pubDate>Tue, 26 Sep 2023 14:38:34 +0000</pubDate>
      <link>https://dev.to/emqx/serverless-mqtt-your-key-to-efficient-iot-prototyping-460b</link>
      <guid>https://dev.to/emqx/serverless-mqtt-your-key-to-efficient-iot-prototyping-460b</guid>
      <description>&lt;p&gt;The Internet of Things (IoT) is transforming the way we live and work, from smart homes and cities to industrial automation and healthcare. But developing an IoT project can be a complex and time-consuming process, requiring expertise in hardware, software, and cloud services. That's why rapid prototyping has become a popular approach for IoT developers, allowing them to quickly test and iterate their ideas before investing in a full-scale deployment.&lt;/p&gt;

&lt;p&gt;IoT prototyping usually contains several key parts like a hardware platform, open-source libraries and &lt;a href="http://frameworks.de/" rel="noopener noreferrer"&gt;&lt;strong&gt;frameworks&lt;/strong&gt;&lt;/a&gt;, a cloud service for data storage and management, a simulator that mimics the behavior of real-world devices, etc. One of the essentials is connecting the device to the cloud with an MQTT Broker.&lt;/p&gt;

&lt;p&gt;This blog will discuss the optimal device connection approach for quickly implementing an IoT prototype.&lt;/p&gt;

&lt;h2&gt;
  
  
  Requirements of MQTT Service in IoT Prototyping
&lt;/h2&gt;

&lt;p&gt;MQTT (Message Queuing Telemetry Transport) is a lightweight messaging protocol that is commonly used in IoT applications to enable communication between devices and servers. MQTT brokers act as intermediaries between clients and clouds, allowing for data to be sent and received in a scalable and efficient manner.&lt;/p&gt;

&lt;p&gt;Typically, you can choose a self-hosting MQTT broker or a fully-managed MQTT service for the device connection of your IoT prototyping.&lt;/p&gt;

&lt;p&gt;Hosting an MQTT broker requires some technical knowledge, and you need to create cloud-based infrastructure and maintain the instance by yourself. The open-source MQTT broker software installation and configuration may also take some time for beginners. But for a rapid IoT prototype, we should spend limited time in system and device testing rather than establish an MQTT broker.&lt;/p&gt;

&lt;p&gt;Fully-managed MQTT service addresses the challenge of infrastructure management, saving your time in setting up an MQTT broker. However, some fully managed services are generally targeted at production environments and do not have particularly low connection specifications. Also, it is best to avoid using the time package to prevent unnecessary resource consumption for a rapid IoT prototype.&lt;/p&gt;

&lt;h2&gt;
  
  
  Serverless MQTT: A Perfect Option for IoT Prototyping
&lt;/h2&gt;

&lt;p&gt;Serverless MQTT is a cutting-edge technology in the realm of MQTT cloud service. It provides a messaging service that automatically scales based on demand without manual intervention.&lt;/p&gt;

&lt;p&gt;EMQX Cloud Serverless, as a newly-offering edition of EMQX Cloud, perfectly meets the requirements we mentioned above. It is a fully managed MQTT service and provides all the capabilities of MQTT 3.1.1 and MQTT 5. Just a few clicks to connect the client to the deployment, and then you can focus on prototyping the application.&lt;/p&gt;

&lt;p&gt;EMQX Cloud Serverless is ideal for development and testing scenarios where there are only a few connections or high-throughput situations. Thanks to its large-scale, multi-tenant cluster, EMQX Cloud Serverless adopts a pay-as-you-go pricing model, ensuring cost control by charging based on actual resource consumption rather than time. It eliminates the need for users to pay for idle resources, making it especially beneficial for IoT applications with unpredictable traffic patterns.&lt;/p&gt;

&lt;h2&gt;
  
  
  Get Your Most Cost-Effective MQTT Service for IoT Prototyping
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Pay as You Go
&lt;/h3&gt;

&lt;p&gt;EMQX Cloud Serverless calculates the concurrent clients with sessions. To be more specific, the number of sessions = the number of connected clients + the disconnected clients with sessions retained in the broker. If you have no idea about retained sessions (or persistent sessions), &lt;a href="https://www.emqx.com/en/blog/mqtt-session" rel="noopener noreferrer"&gt;&lt;strong&gt;this blog&lt;/strong&gt;&lt;/a&gt; explains it well.&lt;/p&gt;

&lt;p&gt;EMQX Cloud Serverless uses &lt;strong&gt;Session Minutes&lt;/strong&gt; and &lt;strong&gt;Traffic&lt;/strong&gt; as its billing units. A Session Minute is counted for each session that connects to the Serverless deployment, regardless of its duration within a minute. Traffic is measured for both inbound and outbound data transfer of the deployment.&lt;/p&gt;

&lt;h3&gt;
  
  
  Free Quota
&lt;/h3&gt;

&lt;p&gt;Here comes the best part: EMQX Cloud Serverless offers a free quota of billing units every month. You will never get charged if your usage is always within the free quota. Theoretically, you can get a free managed MQTT server forever!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fducl97vy4o4zuxkvfx2d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fducl97vy4o4zuxkvfx2d.png" alt="Image description" width="800" height="208"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;1 million session minutes can support a small number of devices staying connected for quite a long time. In the setup process of Serverless deployment, you can set Spend Limit to 0 to get a free MQTT deployment in seconds. You can read &lt;a href="https://www.emqx.com/en/blog/how-to-get-a-forever-free-serverless-mqtt-service" rel="noopener noreferrer"&gt;&lt;strong&gt;this blog&lt;/strong&gt;&lt;/a&gt; for more information about pricing mode and free quota.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test out Your Ideas with EMQX Cloud Serverless Today
&lt;/h2&gt;

&lt;p&gt;EMQX Cloud Serverless is an ideal solution for businesses that seek ways to improve efficiency, scalability, and cost-effectiveness. Its architecture in cloud computing enables developers to concentrate on coding and deploying their IoT system without the need to manage the infrastructure. Combined with MQTT, an automated messaging service that can scale up or down based on demand becomes a cutting-edge solution for IoT developers.&lt;/p&gt;

&lt;p&gt;You can check out the following links to learn more:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.emqx.com/en/blog/a-comprehensive-guide-to-serverless-mqtt-service" rel="noopener noreferrer"&gt;&lt;strong&gt;A Comprehensive Guide to Serverless MQTT Service | EMQX Cloud&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.emqx.com/en/blog/serverless-or-hosting-choose-a-suitable-mqtt-service-for-your-project" rel="noopener noreferrer"&gt;&lt;strong&gt;Serverless or Hosting? Choose a Suitable MQTT Service for Your Project&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://www.emqx.com/en/blog/serverless-mqtt-your-key-to-efficient-iot-prototyping" rel="noopener noreferrer"&gt;www.emqx.com&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>mqtt</category>
      <category>iot</category>
    </item>
    <item>
      <title>Build an IoT Time-Series Data Application for Industrial Energy Monitoring with MQTT and Timescale</title>
      <dc:creator>EMQ Technologies</dc:creator>
      <pubDate>Tue, 26 Sep 2023 14:31:33 +0000</pubDate>
      <link>https://dev.to/emqx/build-an-iot-time-series-data-application-for-industrial-energy-monitoring-with-mqtt-and-timescale-4j78</link>
      <guid>https://dev.to/emqx/build-an-iot-time-series-data-application-for-industrial-energy-monitoring-with-mqtt-and-timescale-4j78</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;As industrial production continues to grow, monitoring energy consumption in factories is crucial for optimizing energy management strategies and reducing costs. EMQX and Timescale provide a scalable IoT platform for efficient collection and analysis of energy consumption data in real-time. This article shows how to use EMQX to collect data from the plant and integrate it with Timescale for reliable data storage and analysis.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Git&lt;/li&gt;
&lt;li&gt;Docker Engine: v20.10+&lt;/li&gt;
&lt;li&gt;Docker Compose: v2.20+&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How it Works
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fws4zzodnzfse1toy1d65.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fws4zzodnzfse1toy1d65.png" alt="Image description" width="800" height="251"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is a simple and effective architecture that avoids complex components. It utilizes the following three key components:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F68ynvhtik2qjuvy9lu64.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F68ynvhtik2qjuvy9lu64.png" alt="Image description" width="800" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In addition to the basic components, EMQX provides comprehensive observability capabilities. You can use the following components to monitor EMQX metrics and load when the system is running:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F16ikkj6vf11e5ecshup6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F16ikkj6vf11e5ecshup6.png" alt="Image description" width="800" height="184"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Clone the Project Locally
&lt;/h2&gt;

&lt;p&gt;Clone the &lt;a href="https://github.com/emqx/mqtt-to-timescaledb" rel="noopener noreferrer"&gt;&lt;strong&gt;emqx/mqtt-to-timescaledb&lt;/strong&gt;&lt;/a&gt; repository locally, and initialize the submodule to enable the EMQX Exporter (optional):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone https://github.com/emqx/mqtt-to-timescaledb
cd mqtt-to-timescaledb

# Optional
git submodule init
git submodule update

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The codebase consists of four parts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The emqx folder contains EMQX-TimescaleDB integration configurations to automatically create rules and data bridges when launching EMQX.&lt;/li&gt;
&lt;li&gt;The emqx-exporter, prometheus and grafana-provisioning folders include observability and energy consumption data visualization configurations for EMQX.&lt;/li&gt;
&lt;li&gt;The create-table.sql file defines the database table schema, which will create the tables in Timescale during initialization.&lt;/li&gt;
&lt;li&gt;The docker-compose.yml orchestrates all components to launch the project with one click.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Start MQTTX CLI, EMQX, and Timescale
&lt;/h2&gt;

&lt;p&gt;Please make sure you have installed the &lt;a href="https://www.docker.com/" rel="noopener noreferrer"&gt;&lt;strong&gt;Docker&lt;/strong&gt;&lt;/a&gt;, and then run Docker Compose in the background to start the demo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker-compose up -d 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, MQTTX CLI will simulate 10 factories connecting to EMQX, and report the energy consumption data of major equipment on their production lines at a frequency of 1 message per second. The energy data in JSON format will be sent to the topic mqttx/simulate/IEM/{clientid}.&lt;/p&gt;

&lt;p&gt;All equipment will collect the current instantaneous power usage (randomly simulated, not exceeding max power), calculate the electricity consumption for 1 second, and publish the data to EMQX.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F29oq4ixskf1vu0gku9lj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F29oq4ixskf1vu0gku9lj.png" alt="Image description" width="630" height="1042"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "factory_id": "08",
    "factory": "Miller and Sons",
    "values": {
        "air_compressor_1": 3.72,
        "air_compressor_2": 5.01,
        "lighting": 0.95,
        "cooling_equipment": 23.19,
        "heating_equipment": 52.66,
        "conveyor": 10.66,
        "coating_equipment": 5.21,
        "inspection_equipment": 2.6,
        "welding_equipment": 5.27,
        "packaging_equipment": 7.38,
        "cutting_equipment": 12.56
    },
    "timestamp": 1691144157583
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;EMQX will create a rule to ingest messages from the factory. You can also modify this rule later to add custom processing using EMQX's&lt;a href="https://docs.emqx.com/en/enterprise/v5.1/data-integration/rule-sql-builtin-functions.html" rel="noopener noreferrer"&gt; &lt;strong&gt;built-in SQL functions&lt;/strong&gt;&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT
  payload
FROM
  "mqttx/simulate/#"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After the rules process the data, EMQX will insert the energy consumption data from the message payload into the specified table in Timescale through data bridges. Configuring INSERT SQL on the data bridges allows flexibly accomplishing this operation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fncoxs2fok3kutxscg2uo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fncoxs2fok3kutxscg2uo.png" alt="Image description" width="800" height="363"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Subscribe to Data from EMQX
&lt;/h2&gt;

&lt;p&gt;Docker Compose has included a subscriber to print all energy consumption data. You can view the data with this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ docker logs -f mqttx
[8/4/2023] [10:15:57 AM] › topic: mqttx/simulate/IEM/mqttx_85df7038
payload: {"factory_id":"08","factory":"Miller and Sons","values":{"air_compressor_1":3.72,"air_compressor_2":5.01,"lighting":0.95,"cooling_equipment":23.19,"heating_equipment":52.66,"conveyor":10.66,"coating_equipment":5.21,"inspection_equipment":2.6,"welding_equipment":5.27,"packaging_equi...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To subscribe and receive the data with any &lt;a href="https://www.emqx.com/en/blog/mqtt-client-tools" rel="noopener noreferrer"&gt;&lt;strong&gt;MQTT client&lt;/strong&gt;&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mqttx sub -t mqttx/simulate/IEM/+ 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  View Enengy Data in Grafana
&lt;/h2&gt;

&lt;p&gt;To view enengy data in the Grafana dashboard, open &lt;a href="http://localhost:3000" rel="noopener noreferrer"&gt;http://localhost:3000&lt;/a&gt; in your browser, log in with username admin and password public.&lt;/p&gt;

&lt;p&gt;After successful login, go to “Home → Dashboards” page and select “Energy Monitoring data”. The dashboard comprehensively displays the key energy consumption metrics of various industrial equipment, including the cumulative energy consumption value of each equipment and the energy consumption share of each plant, which fully presents the real-time energy usage of the industrial system and facilitates data-driven energy-saving management.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcd7ssheq4pg8omybiamz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcd7ssheq4pg8omybiamz.png" alt="Image description" width="800" height="403"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this post, we have explored how to integrate EMQX and Timescale to build an industrial energy monitoring pipeline. By leveraging EMQX as a real-time &lt;a href="https://www.emqx.com/en/blog/the-ultimate-guide-to-mqtt-broker-comparison" rel="noopener noreferrer"&gt;&lt;strong&gt;MQTT broker&lt;/strong&gt;&lt;/a&gt; and utilizing its SQL data integration to ingest data into Timescale, we have created an end-to-end solution for collecting and analyzing time-series energy consumption data.&lt;/p&gt;

&lt;p&gt;This demo project provides a starting point for building scalable time-series data platforms, opening opportunities for real-time monitoring, optimization, and intelligence in industrial facilities and other time-sensitive use cases. The reliability of EMQX and the analytical power of Timescale unlock valuable insights from time-series data.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Please Visit the&lt;/em&gt; &lt;a href="https://github.com/emqx/mqtt-to-timescaledb" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;GitHub link&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;em&gt;for the Demo of ingesting time series data into Timescale.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://www.emqx.com/en/blog/build-an-iot-time-series-data-application-for-energy-storage-with-mqtt-and-timescale" rel="noopener noreferrer"&gt;www.emqx.com&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>MQTT 5.0 Packet Explained 01: CONNECT &amp; CONNACK</title>
      <dc:creator>EMQ Technologies</dc:creator>
      <pubDate>Sat, 23 Sep 2023 00:00:01 +0000</pubDate>
      <link>https://dev.to/emqx/mqtt-50-packet-explained-01-connect-connack-3c4m</link>
      <guid>https://dev.to/emqx/mqtt-50-packet-explained-01-connect-connack-3c4m</guid>
      <description>&lt;p&gt;In &lt;a href="https://www.emqx.com/en/blog/introduction-to-mqtt-control-packets" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;Introduction to MQTT 5.0 Packet&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;, we introduced that MQTT packets are composed of three parts: Fixed Header, Variable Header, and Payload, as well as common concepts in MQTT packets such as Variable Byte Integer and Property. Now, we will further introduce the composition of each type of packet according to its actual use. First, we will focus on the packets used to establish an MQTT connection.&lt;/p&gt;

&lt;p&gt;If we want to use MQTT for communication, the first step must be to establish an MQTT connection. Establishing an MQTT connection requires the use of two control packets, which are the CONNECT packet and the CONNACK packet. The CONNECT packet is the first control packet sent by the client to the server after establishing a network connection and is used to initiate a connection request. The server will return a CONNACK packet to inform the client of the connection result.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sample Packets
&lt;/h2&gt;

&lt;p&gt;We use &lt;a href="https://mqttx.app/" rel="noopener noreferrer"&gt;&lt;strong&gt;MQTTX CLI&lt;/strong&gt;&lt;/a&gt; to initiate a connection to a &lt;a href="http://broker.emqx.io/" rel="noopener noreferrer"&gt;&lt;strong&gt;Public MQTT server&lt;/strong&gt;&lt;/a&gt;. In this connection, we set the protocol version to MQTT 5.0, Clean Start to 1, Session Expiry Interval to 300 seconds, Keep Alive to 60, and the username and password to admin and public respectively. The corresponding MQTTX CLI command is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mqttx conn --hostname broker.emqx.io --mqtt-version 5 \
  --session-expiry-interval 300 --keepalive 60 --username admin --password public

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Below is the CONNECT packet sent out by MQTTX CLI captured using the Wireshark tool:&lt;/p&gt;

&lt;p&gt;The following is the CONNECT packet sent by MQTTX CLI captured using &lt;a href="https://www.wireshark.org/" rel="noopener noreferrer"&gt;&lt;strong&gt;Wireshark&lt;/strong&gt;&lt;/a&gt;. In Linux, you can use &lt;a href="https://en.wikipedia.org/wiki/Tcpdump" rel="noopener noreferrer"&gt;&lt;strong&gt;tcpdump&lt;/strong&gt;&lt;/a&gt; to capture the packet first, and then import it to Wireshark for viewing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;10 2f 00 04 4d 51 54 54 05 c2 00 3c 05 11 00 00 01 2c 00 0e 6d 71 74 74 78 5f 30 63 36 36 38 64 30 64 00 05 61 64 6d 69 6e 00 06 70 75 62 6c 69 63 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But this is a string of hexadecimal bytes that is not easy to understand unless they are converted into the following format:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4tstp0uhj4vy4rigwbqz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4tstp0uhj4vy4rigwbqz.png" alt="Image description" width="800" height="693"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Similarly, we also captured the CONNACK packet returned by the public MQTT server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;20 13 00 00 10 27 00 10 00 00 25 01 2a 01 29 01 22 ff ff 28 01 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After parsing this string of packet data, we can see that the Reason Code of the CONNACK packet is 0, which means that the connection was successful. The multiple properties that follow provide a list of features supported by the server, such as the maximum packet size supported, whether to support retained messages, etc:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcb60nl3yc7iqhmyy05ue.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcb60nl3yc7iqhmyy05ue.png" alt="Image description" width="800" height="625"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The above examples are to help everyone better understand the structure of MQTT Packets. In actual applications, you can directly view the packet details in Wireshark. Wireshark provides excellent support for MQTT. It directly lists the values of each field for us, without the need for us to analyze ourselves:&lt;/p&gt;

&lt;p&gt;Of course, Wireshark has actually listed the values of each field in the packet for us. Through the following introduction to the structure of the CONNECT and CONNACK packets, combined with the packet capture results of Wireshark, you will quickly master these two packets:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5lymsyj1tss1u7zt4ihl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5lymsyj1tss1u7zt4ihl.png" alt="Image description" width="800" height="643"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  CONNECT Packet Structure
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Fixed Header
&lt;/h3&gt;

&lt;p&gt;In the Fixed Header of the CONNECT packet, the Packet Type field located in the high 4 bits of the first byte must be 1 (0b0001), and the low 4 bits in the first byte must all be 0.&lt;/p&gt;

&lt;p&gt;Therefore, the value of the first byte of the CONNECT packet must be 0x10. We can use this to determine whether a packet is a CONNECT packet.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fed3diuuhy1xf18x2u5ba.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fed3diuuhy1xf18x2u5ba.png" alt="Image description" width="800" height="260"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Variable Header
&lt;/h3&gt;

&lt;p&gt;The Variable Header of the CONNECT packet contains the following fields in order:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fklj062fz6zvvfjqqonnn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fklj062fz6zvvfjqqonnn.png" alt="Image description" width="800" height="143"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Protocol Name&lt;/strong&gt;: This is a UTF-8 encoded string used to indicate the protocol name. In MQTT, the first two bytes of the UTF-8 encoded string are uniformly used to indicate the length of the actual character data that follows. The protocol name is fixed as MQTT in MQTT 3.1.1 and MQTT 5.0, so the corresponding complete content in hexadecimal bytes is 00 04 4d 51 54 54, where 4d 51 54 54 is the ASCII value of the string MQTT The protocol name in the earliest MQTT 3.1 is MQIsdp, so it corresponds to 00 06 4d 51 49 73 64 70.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Protocol Version&lt;/strong&gt;: This is a single-byte length unsigned integer used to indicate the protocol version. Currently, there are only three possible values, 3 represents MQTT 3.1, 4 represents MQTT 3.1.1, and 5 represents MQTT 5.0.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Connect Flags&lt;/strong&gt;: Connection flags, have a length of only one byte, but contain several flags used to indicate connection behavior or whether certain fields exist in the Payload.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbdgwhbfa3v12j1tcd8wo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbdgwhbfa3v12j1tcd8wo.png" alt="Image description" width="800" height="255"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;User Name Flag&lt;/strong&gt;: Used to indicate whether the Payload contains the Username.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Password Flag&lt;/strong&gt;: Used to indicate whether the Payload contains the Password.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.emqx.com/en/blog/use-of-mqtt-will-message" rel="noopener noreferrer"&gt;&lt;strong&gt;Will Retain&lt;/strong&gt;&lt;/a&gt;: Used to indicate whether the will message is a retained message.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Will QoS&lt;/strong&gt;: Used to indicate the QoS of the will message.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Will Flag&lt;/strong&gt;: Used to indicate whether the Payload contains relevant fields of the will message.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Clean Start&lt;/strong&gt;: Used to indicate whether the current connection is a new session or a continuation of an existing session, which determines whether the server will directly create a new session or attempt to reuse an existing session.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reserved&lt;/strong&gt;: This is a reserved bit, its value must be 0.

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.emqx.com/en/blog/mqtt-keep-alive" rel="noopener noreferrer"&gt;&lt;strong&gt;Keep Alive&lt;/strong&gt;&lt;/a&gt;: This is a double-byte length unsigned integer used to indicate the maximum time interval between two adjacent control packets sent by the client.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Properties&lt;/strong&gt;: The table below lists all available properties of the CONNECT packet.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6r3b1c657jph7rhuvowj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6r3b1c657jph7rhuvowj.png" alt="Image description" width="800" height="715"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Payload
&lt;/h3&gt;

&lt;p&gt;In the Payload of the CONNECT packet, aside from the Client ID, all other fields are optional. Their existence depends on the value of the corresponding flag in the Connect Flags of the variable header. However, if these exist, they must appear in the order of Client ID, Will Properties, Will Topic, Will Payload, User Name, and Password.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgwsyk5fx7jfuo0cxvoiy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgwsyk5fx7jfuo0cxvoiy.png" alt="Image description" width="800" height="139"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  CONNACK Packet Structure
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Fixed Header
&lt;/h3&gt;

&lt;p&gt;The value of the high 4 bits in the first byte of the Fixed Header is 2 (0b0010), indicating that this is a CONNACK packet.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fooeo1dnyj2e5m94k1ju9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fooeo1dnyj2e5m94k1ju9.png" alt="Image description" width="800" height="283"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Variable Header
&lt;/h3&gt;

&lt;p&gt;The Variable Header of the CONNACK packet contains the following fields in order:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1vb9w2mqk9xfales5lnf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1vb9w2mqk9xfales5lnf.png" alt="Image description" width="800" height="283"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Connect Acknowledge Flags: Connection confirmation flag.  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reserved (Bit 7 - 1): Reserved bits, must be set to 0.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Session Present (Bit 0)&lt;/strong&gt;: Used to indicate whether the server is using an existing session to resume communication with the client. Session Present may be 1 only when the client has set Clean Start to 0 in the CONNECT connection.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reason Code&lt;/strong&gt;: Used to indicate the result of the connection. The table below lists some common Reason Codes in the CONNACK packet, for a complete list, please refer to the &lt;a href="https://www.emqx.com/en/blog/mqtt5-new-features-reason-code-and-ack" rel="noopener noreferrer"&gt;&lt;strong&gt;MQTT 5.0 Reason Code Quick Reference Guide&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F61xo83avqlhlg3r6jl04.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F61xo83avqlhlg3r6jl04.png" alt="Image description" width="770" height="1162"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Properties&lt;/strong&gt;: The table below lists all available properties for the CONNACK packet.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;IdentifierProperty NameType&lt;/strong&gt;0x11&lt;a href="https://www.emqx.com/en/blog/mqtt5-new-feature-clean-start-and-session-expiry-interval" rel="noopener noreferrer"&gt;&lt;strong&gt;Session Expiry Interval&lt;/strong&gt;&lt;/a&gt;Four Byte Integer0x21&lt;a href="https://www.emqx.com/en/blog/mqtt5-flow-control" rel="noopener noreferrer"&gt;&lt;strong&gt;Receive Maximum&lt;/strong&gt;&lt;/a&gt;Two Byte Integer0x24Maximum QoSByte0x25Retain AvailableBytes0x27Maximum Packet SizeFour Byte Integer0x12Assigned Client IdentifierUTF-8 Encoded String0x22&lt;a href="https://www.emqx.com/en/blog/mqtt5-topic-alias" rel="noopener noreferrer"&gt;&lt;strong&gt;Topic Alias Maximum&lt;/strong&gt;&lt;/a&gt;Two Byte Integer0x1FReason StringUTF-8 Encoded String0x26&lt;a href="https://www.emqx.com/en/blog/mqtt5-user-properties" rel="noopener noreferrer"&gt;&lt;strong&gt;User Property&lt;/strong&gt;&lt;/a&gt;UTF-8 String Pair0x28Wildcard Subscription AvailableByte0x29Subscription Identifier AvailableBytes0x2AShared Subscription AvailableByte0x13Server Keep AliveTwo Byte Integer0x1AResponse InformationUTF-8 Encoded String0x1CServer ReferenceUTF-8 Encoded String0x15&lt;a href="https://www.emqx.com/en/blog/leveraging-enhanced-authentication-for-mqtt-security" rel="noopener noreferrer"&gt;&lt;strong&gt;Authentication Method&lt;/strong&gt;&lt;/a&gt;UTF-8 Encoded String0x16&lt;a href="https://www.emqx.com/en/blog/leveraging-enhanced-authentication-for-mqtt-security" rel="noopener noreferrer"&gt;&lt;strong&gt;Authentication Data&lt;/strong&gt;&lt;/a&gt;Binary Data&lt;/p&gt;

&lt;h3&gt;
  
  
  Payload
&lt;/h3&gt;

&lt;p&gt;The CONNACK packet has no Payload.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;CONNECT is the first MQTT packet sent by the client after the network connection between the client and the server is established. CONNACK, as the response packet of CONNECT, indicates the connection result through the reason code.&lt;/p&gt;

&lt;p&gt;The client and server need to use CONNECT and CONNACK packets to complete the exchange of necessary information, such as the protocol version, Client ID, user name, password used by the client, and the maximum packet size and QoS supported by the server, and whether there is a corresponding session.&lt;/p&gt;

&lt;p&gt;The above is an introduction to the MQTT CONNECT and CONNACK packets. In subsequent articles, we will continue to study the structure and composition of packets like PUBLISH, and DISCONNECT.&lt;/p&gt;

&lt;p&gt;Originally published at &lt;a href="https://www.emqx.com/en/blog/mqtt-5-0-control-packets-01-connect-connack" rel="noopener noreferrer"&gt;www.emqx.com&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>4 Reasons Why You Should Adopt MQTT in Unified Namespace</title>
      <dc:creator>EMQ Technologies</dc:creator>
      <pubDate>Tue, 19 Sep 2023 22:20:08 +0000</pubDate>
      <link>https://dev.to/emqx/4-reasons-why-you-should-adopt-mqtt-in-unified-namespace-3m3g</link>
      <guid>https://dev.to/emqx/4-reasons-why-you-should-adopt-mqtt-in-unified-namespace-3m3g</guid>
      <description>&lt;p&gt;&lt;a href="https://www.emqx.com/en/blog/unified-namespace-next-generation-data-fabric-for-iiot" rel="noopener noreferrer"&gt;&lt;strong&gt;In the last episode of the UNS series&lt;/strong&gt;&lt;/a&gt;, we explained what UNS is and why it is essential for IIoT 4.0. MQTT technology is always a first choice regarding how to build a UNS. Readers unfamiliar with MQTT might be curious why it always appears with UNS in IIoT 4.0 solutions. This episode will walk you through why MQTT is the best partner for building UNS.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is MQTT
&lt;/h2&gt;

&lt;p&gt;Before entering the world of UNS, it is important to have a basic knowledge of MQTT.&lt;/p&gt;

&lt;p&gt;MQTT (Message Queuing Telemetry Transport) is a lightweight, publish-subscribe-based messaging protocol. It was created in 1991 by Andy Stanford-Clark (IBM) and Arlen Nipper (Eurotech) to connect oil pipelines over unreliable satellite networks. Thus, since day 1, MQTT has been designed to provide efficient connectivity for resource-constrained devices and low-bandwidth, high-latency, or unreliable networks. Now it has become the de-facto standard of the IoT industry.&lt;/p&gt;

&lt;p&gt;For more details on MQTT, please refer to &lt;a href="https://www.emqx.com/en/blog/the-easiest-guide-to-getting-started-with-mqtt" rel="noopener noreferrer"&gt;&lt;strong&gt;MQTT Protocol: How It Works &amp;amp; Core Concepts Explained&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Adopt MQTT in UNS
&lt;/h2&gt;

&lt;p&gt;In our last episode, we learned a common tongue of UNS definition: It is about reflecting your business to the digital infrastructure. To create an effective UNS, it is crucial to have a technology stack that can efficiently connect numerous manufacturing devices and unify the whole business from the physical to the digital world.&lt;/p&gt;

&lt;p&gt;This is exactly why MQTT plays a pivotal role in UNS. MQTT broker is commonly used as a digital infrastructure for managing fragmented connections and connecting distributed devices in other industries (such as &lt;a href="https://www.emqx.com/en/blog/mqtt-for-internet-of-vehicles" rel="noopener noreferrer"&gt;&lt;strong&gt;IoV&lt;/strong&gt;&lt;/a&gt; ), and so is in &lt;a href="https://www.emqx.com/en/blog/iiot-explained-examples-technologies-benefits-and-challenges" rel="noopener noreferrer"&gt;&lt;strong&gt;IIoT&lt;/strong&gt;&lt;/a&gt;. Here are the reasons why you should adopt MQTT in UNS.&lt;/p&gt;

&lt;h3&gt;
  
  
  MQTT is Lightweight and Scalable
&lt;/h3&gt;

&lt;p&gt;UNS requires a data hub as a single source of truth to connect all of your manufacturing pieces, including PLC, SCADA, MES, and ERP. The amount of real-time data is huge. Usually, data hub faces thousands or even millions of concurrent connections in large-scale solutions.&lt;/p&gt;

&lt;p&gt;MQTT has very low overhead and bandwidth consumption thanks to its binary format. This lightweight design minimizes the size of messages and reduces network traffic. This feature perfectly matches UNS and IIoT.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fshdsz779dytrts7ybncx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fshdsz779dytrts7ybncx.png" alt="Image description" width="800" height="767"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftjn5gzwp2t5np4ic79p0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftjn5gzwp2t5np4ic79p0.png" alt="Image description" width="800" height="374"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Business owners need to focus more on the operation, not tangling with the expansion of infrastructure resources to support a fast-growing business. This is why the scalability of UNS matters. In the MQTT architecture, some brokers provide superb scalability that can support millions of messages per second, such as &lt;a href="https://www.emqx.com/en/products/emqx" rel="noopener noreferrer"&gt;&lt;strong&gt;EMQX&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Learn more:&lt;/em&gt; &lt;a href="https://www.emqx.com/en/blog/reaching-100m-mqtt-connections-with-emqx-5-0" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;Reaching 100M MQTT connections with EMQX 5.0&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  MQTT Connects Everything
&lt;/h3&gt;

&lt;p&gt;MQTT may be a newcomer in the world of IIoT, but it has gained immense popularity. This is because MQTT constitutes the greatest common subset of the old IIoT technology, making it an ideal tool for connecting all the components of your existing system without causing any damage.&lt;/p&gt;

&lt;p&gt;Because there is no such technology and products that fit all cases, you cannot build a UNS by &lt;a href="https://www.emqx.com/en/blog/opc-ua-over-mqtt-the-future-of-it-and-ot-convergence" rel="noopener noreferrer"&gt;&lt;strong&gt;OPC UA&lt;/strong&gt;&lt;/a&gt; alone or depend on one protocol solely, especially when you bring the cloud into consideration. UNS must combine different technologies together, and MQTT is that adapter and coordinator to unify them in one namespace.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9r62b7k2ggjximkhfkff.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9r62b7k2ggjximkhfkff.png" alt="Image description" width="800" height="775"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Many data convention tools and protocol proxy software exist in the open-source world, such as &lt;a href="https://neugates.io/" rel="noopener noreferrer"&gt;&lt;strong&gt;Neuron&lt;/strong&gt;&lt;/a&gt;, ignition and PLC4X. You can connect &lt;a href="https://www.emqx.com/en/blog/bridging-opc-ua-data-to-mqtt-for-iiot" rel="noopener noreferrer"&gt;&lt;strong&gt;OPC UA to MQTT&lt;/strong&gt;&lt;/a&gt;, the same story with Modbus and Ethercat.&lt;/p&gt;

&lt;p&gt;​&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Read our tutorials on industrial protocol to MQTT bridging:&lt;/em&gt;&lt;br&gt;&lt;br&gt;
&lt;a href="https://www.emqx.com/en/blog/bridging-opc-ua-data-to-mqtt-for-iiot" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;Bridging OPC UA Data to MQTT for IIoT&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;
&lt;a href="https://www.emqx.com/en/blog/bridging-modbus-data-to-mqtt-for-iiot" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;Bridging Modbus Data to MQTT for IIoT&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In IIoT 3.0, companies that execute digital transformation must move data through different layers of traditional systems, such as MES, ERP, CRM, and WMS. This results in a complex connectivity problem called “data spaghetti”.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feonstvenfhu06iyvbuj6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feonstvenfhu06iyvbuj6.png" alt="Image description" width="800" height="326"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With the &lt;a href="https://www.emqx.com/en/blog/the-ultimate-guide-to-mqtt-broker-comparison" rel="noopener noreferrer"&gt;&lt;strong&gt;MQTT broker&lt;/strong&gt;&lt;/a&gt; sitting in the middle, facilitating information exchange, UNS moves data in an efficient manner. This is one of the key reasons why we need MQTT to build UNS.&lt;/p&gt;

&lt;h3&gt;
  
  
  MQTT is Secure
&lt;/h3&gt;

&lt;p&gt;In the context of UNS, PLCs don't need to report polling requests from unknown sources. It only establishes one long-stand connection to a safe broker, which is known to the whole system and is the only data hub that everything needs to talk to.&lt;/p&gt;

&lt;p&gt;MQTT broker not only decouples the inputs and outputs of IIoT 4.0, but also takes over the responsibility of securing the connectivity of fragmented devices and systems. Thanks to the rich security features of MQTT, it is fully competent to act as an isolation data hub for your manufacturing lines, preventing any malformed data penetrates into fragile PLCs. In this way, UNS shifts the security burden to the broker and manages it in a unified place.&lt;/p&gt;

&lt;h3&gt;
  
  
  MQTT Enables Event-Driven Architecture
&lt;/h3&gt;

&lt;p&gt;For IIoT 4.0, data is primarily generated by devices, not people. And most of the time, PLC readings don’t change, it is no point in transmitting redundant data to UNS and overwhelming your network.&lt;/p&gt;

&lt;p&gt;However, once the value of registers changes, it is essential to report it to ERP/MES or cloud immediately to extract the maximum value, since the liquidity and marginal value of information decreases along with time. This is called “report by exception“.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6giray72wxpp2vbdiwpa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6giray72wxpp2vbdiwpa.png" alt="Image description" width="800" height="312"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Therefore, an event-driven technology such as MQTT is important to implement UNS. MQTT brokers are aware of client state changes. This awareness is enabled with SparkPlugB and the MQTT Last Will features. With last will and SparkPlugB, MQTT only communicates changes and ensures stale data is not delivered to subscribing clients.&lt;/p&gt;

&lt;h2&gt;
  
  
  MQTT Topic as Metadata of UNS
&lt;/h2&gt;

&lt;p&gt;UNS is the digital reflection of business in the physical world. It is driven by reality, not the other way around. We need the sublime context of generated data to convert it into information, such as the location of site, and which line and cell PLC belongs to. Fortunately, the Pub/Sub messaging model of MQTT provides an easy way of mapping the context of PLC into the digital world.&lt;/p&gt;

&lt;p&gt;UNS with MQTT enables users to browse all the namespaces and features. And the real-time status of every data tag.&lt;/p&gt;

&lt;p&gt;The MQTT topic is well-defined as follows:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;namespace/group_id/message_type/edge_node_id/[device_id]&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmjhmovphzds5lymi25ka.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmjhmovphzds5lymi25ka.png" alt="Image description" width="800" height="262"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From OSISoft AF&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.emqx.com/en/blog/advanced-features-of-mqtt-topics" rel="noopener noreferrer"&gt;&lt;strong&gt;MQTT Topics&lt;/strong&gt;&lt;/a&gt; have a hierarchical organization and could be easily imagined as a folder structure. By adding your namespace of each level as a topic, we can build a tree view on top of MQTT.&lt;/p&gt;

&lt;p&gt;When subscribers consume data from the topic “&lt;strong&gt;Enterprise A/Site A/Area A/Process Cell A/Bio Reactor”,&lt;/strong&gt; it automatically knows where the data origins and takes necessary action upon it. And they could use wildcards to subscribe to multiple datapoints at the same time.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foj1fe5t5e69f0tnqxlil.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foj1fe5t5e69f0tnqxlil.png" alt="Image description" width="800" height="497"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;MQTT could help you define metadata that assures consistency and accuracy across different systems in UNS.&lt;/p&gt;

&lt;h2&gt;
  
  
  OPC UA: Alternative to MQTT for Building UNS
&lt;/h2&gt;

&lt;p&gt;Precisely speaking, MQTT is the best partner for building UNS. However, it is not compulsory. Therefore, you could build the UNS with other protocols, such as OPC UA and HTTP, or even plain Modbus + TCP/UDP. Among many options, OPC UA remains a popular methodology for IIoT due to the strong commercial backup and the standard's longevity.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;The detailed comparison between them can be found at:&lt;/em&gt;&lt;br&gt;&lt;br&gt;
&lt;a href="https://www.emqx.com/en/blog/a-comparison-of-iiot-protocols-mqtt-sparkplug-vs-opc-ua" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;A Comparison of IIoT Protocols: MQTT Sparkplug vs OPC-UA&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;
&lt;a href="https://www.emqx.com/en/blog/efficiency-comparison-opc-ua-modbus-mqtt-sparkplug-http" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;Efficiency Comparison: OPC-UA, Modbus, MQTT, Sparkplug, HTTP&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;However, it is not one or the other case; the best approach is to combine the advantages from both sides by &lt;a href="https://www.emqx.com/en/blog/bridging-opc-ua-data-to-mqtt-for-iiot" rel="noopener noreferrer"&gt;&lt;strong&gt;bridging them together&lt;/strong&gt;&lt;/a&gt;, or &lt;a href="https://www.emqx.com/en/blog/opc-ua-over-mqtt-the-future-of-it-and-ot-convergence" rel="noopener noreferrer"&gt;&lt;strong&gt;using OPC UA via MQTT approach&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The General Architecture of Building UNS with MQTT
&lt;/h2&gt;

&lt;p&gt;Theoretically, UNS is a global namespace that unifies all namespaces of your business. Each factory, each site, and each PLC is a stand-alone namespace.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzqxhrjuljn5yxfpdwxd7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzqxhrjuljn5yxfpdwxd7.png" alt="Image description" width="800" height="286"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;UNS is to take technology across the business and structure it in a way you can navigate. Thus all other solutions could be built on top of it to their best effort. MQTT is responsible for connecting fragmented technologies from OT, CT and the IT world and seamlessly integrates them together.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this blog, we discussed the significance of MQTT within UNS and why MQTT is the data pump of all IT systems. Adopting MQTT in a unified namespace offers a multitude of benefits that can revolutionize how we connect and communicate in the digital world. Organizations can streamline their data flow, create more responsive and connected systems, and unlock new opportunities for innovation and growth.&lt;/p&gt;

&lt;p&gt;In the upcoming episode, we will explore the innovative contributions of EMQ to UNS regarding MQTT.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://www.emqx.com/en/blog/four-reasons-why-you-should-adopt-mqtt-in-unified-namespace" rel="noopener noreferrer"&gt;www.emqx.com&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>AWS MQTT: Managing IoT Communication in AWS (with Tutorial)</title>
      <dc:creator>EMQ Technologies</dc:creator>
      <pubDate>Mon, 18 Sep 2023 15:04:02 +0000</pubDate>
      <link>https://dev.to/emqx/aws-mqtt-managing-iot-communication-in-aws-with-tutorial-18bp</link>
      <guid>https://dev.to/emqx/aws-mqtt-managing-iot-communication-in-aws-with-tutorial-18bp</guid>
      <description>&lt;h2&gt;
  
  
  What Is AWS?
&lt;/h2&gt;

&lt;p&gt;AWS, or Amazon Web Services, is the world’s leading cloud platform. It provides a mix of infrastructure as a service (IaaS), platform as a service (PaaS), and packaged software as a service (SaaS) offerings. AWS provides a variety of services that can be used as building blocks to run organizational workloads.&lt;/p&gt;

&lt;p&gt;Running your applications in the AWS cloud can help you move faster and save substantial costs, benefiting from the scale and performance of AWS. AWS powers a wide variety of workloads including web and mobile applications, enterprise applications, data processing and warehousing, storage, and many others.&lt;/p&gt;

&lt;p&gt;AWS is known for its wide range of features and capabilities. These include on-demand computing power, database storage, content delivery, and advanced analytics capabilities. It allows organizations to tap into a global infrastructure that can serve almost any computing requirement, on-demand and without having to deploy resources on-premises.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is MQTT?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.emqx.com/en/blog/the-easiest-guide-to-getting-started-with-mqtt" rel="noopener noreferrer"&gt;&lt;strong&gt;MQTT&lt;/strong&gt;&lt;/a&gt;, or Message Queuing Telemetry Transport, is a simple and lightweight messaging protocol designed for constrained devices and low-bandwidth, high-latency networks. The design principles of MQTT are to minimize network bandwidth and device resource requirements whilst also attempting to ensure reliability and some degree of assurance of delivery.&lt;/p&gt;

&lt;p&gt;MQTT is often used in Internet of Things (IoT) applications due to its efficient use of network resources, its low power usage, and its minimized data packets. It is most useful in remote locations where a small code footprint is required, or where network bandwidth is at a premium.&lt;/p&gt;

&lt;p&gt;The MQTT protocol works by exchanging a series of &lt;a href="https://www.emqx.com/en/blog/Introduction-to-mqtt-control-packets" rel="noopener noreferrer"&gt;&lt;strong&gt;MQTT control packets&lt;/strong&gt;&lt;/a&gt; in a defined way. The client and server send each other packets to keep the connection alive, to publish data, to acknowledge receipt of data, and to adjust the quality of service (QoS) level of the connection. MQTT is a publish/subscribe messaging protocol designed for lightweight M2M communications. It was originally developed by IBM in the late 1990s and has been used in a variety of IoT settings.&lt;/p&gt;

&lt;p&gt;This is part of a series of articles about &lt;a href="https://www.emqx.com/en/blog/iot-in-the-cloud-8-key-benefits-and-how-to-get-started" rel="noopener noreferrer"&gt;&lt;strong&gt;IoT in the cloud&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  AWS IoT Core and MQTT
&lt;/h2&gt;

&lt;p&gt;AWS IoT Core is a managed cloud service that lets connected devices interact with cloud applications and other devices. AWS IoT Core fully supports MQTT, as well as HTTP and WebSockets. With AWS IoT Core, applications can keep track of and communicate with IoT devices, even when they aren’t currently connected.&lt;/p&gt;

&lt;p&gt;The AWS IoT Core service allows for secure, bi-directional communication between Internet-connected things (such as sensors, actuators, embedded devices, or smart appliances) and the AWS Cloud. This enables you to collect telemetry data from multiple devices, and store and analyze the data. You can also create applications that enable your users to control these devices from their phones or tablets.&lt;/p&gt;

&lt;p&gt;For more information on the features and capabilities of AWS IoT Core, see the &lt;a href="https://docs.aws.amazon.com/iot/index.html" rel="noopener noreferrer"&gt;&lt;strong&gt;official documentation&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Learn more about&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.emqx.com/en/blog/understanding-aws-iot-core" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;AWS IoT Core&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  AWS MQTT Pricing
&lt;/h2&gt;

&lt;p&gt;The cost of using AWS IoT Core is mainly determined by the number of messages published to AWS IoT and delivered to devices or applications. A message is a 512-byte block of data processed by AWS IoT. The total number of messages is the sum of all inbound and outbound messages.&lt;/p&gt;

&lt;p&gt;The pricing for AWS IoT Core is based on the number of messages published to AWS IoT (message ingest) and delivered by AWS IoT to devices or applications (message delivery). You are billed separately for each. As of the time of writing, the first 250 million messages per month are charged at $1.00 per million messages, and the price decreases with increasing volume.&lt;/p&gt;

&lt;p&gt;However, it's important to note that AWS offers a Free Tier for AWS IoT Core, which includes 250,000 free messages (published or delivered) per month for the first 12 months. After the first 12 months or above the free tier limit, standard AWS IoT Core pricing applies. For up-to-date pricing, refer to the &lt;a href="https://aws.amazon.com/iot-core/pricing/" rel="noopener noreferrer"&gt;&lt;strong&gt;official pricing page&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Quick Tutorial: Using AWS IoT Core with MQTT
&lt;/h2&gt;

&lt;p&gt;This brief guide will show you how to create your first 'thing' object in the AWS IoT ecosystem, connect a device to this object, and monitor the MQTT messages generated by the device. You’ll download software to the IoT device that runs an interactive tutorial, demonstrating the AWS IoT Core service.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Please note:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If your device doesn't have a compatible browser, carry out this tutorial on a computer and transfer the downloaded files to your device.&lt;/li&gt;
&lt;li&gt;Your IoT device must be able to interact with port 8443 on your AWS account’s device data endpoint.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;To run the interactive tutorial on your IoT device:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;From the browser on your IoT device, sign in to AWS IoT Console and select &lt;strong&gt;Connect&lt;/strong&gt; &amp;gt; &lt;strong&gt;Connect one device&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Prepare your device according to the instructions and register a new 'thing' under the &lt;strong&gt;Register and Secure Your Device&lt;/strong&gt; section. Choose a unique name for your 'thing' and provide additional configurations if needed. Note that a 'thing' name cannot be modified once created.
📷
Source for this and the following image: AWS&lt;/li&gt;
&lt;li&gt;In the &lt;strong&gt;Choose Platform and SDK&lt;/strong&gt; section, select your preferred platform and SDK language. For this tutorial, select the Python SDK on Linux/OS X platform.&lt;/li&gt;
&lt;li&gt;AWS IoT now provides a connection kit including various critical files. Download it to your device. Unzip the file by running unzip connect_device_package.zip or an equivalent command.&lt;/li&gt;
&lt;li&gt;Open up a terminal window on your device and follow the instructions in the AWS IoT Console. The console will provide a command to run in the directory containing the connection kit file.&lt;/li&gt;
&lt;li&gt;After you enter the command, you should see an output in the device's terminal or command window that is similar to the following. This output is from the messages the program is sending to and then receiving back from AWS IoT Core.
📷&lt;/li&gt;
&lt;li&gt;While the sample program is running, the test message Hello World! will appear in the terminal on the device.&lt;/li&gt;
&lt;li&gt;If you want to see messages from your IoT client in the AWS IoT console, from the &lt;strong&gt;Test&lt;/strong&gt; page of the console, open the &lt;strong&gt;MQTT test client&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;In the test client, use the &lt;strong&gt;Topic&lt;/strong&gt; filter, and enter a topic such as sdk/test/python to subscribe to messages from your device. The topic filters are case sensitive.&lt;/li&gt;
&lt;li&gt;After you subscribe to the test topic, run ./start.sh on your device. Messages should start to appear in the MQTT client, similar to the following. The number in square brackets should increase by one each time a new message is received.
{  "message": "Hello World!" [1]  } &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That’s it! You just registered a IoT device with AWS IoT Core and sent MQTT messages to AWS.&lt;/p&gt;

&lt;h2&gt;
  
  
  Advantages of Using AWS with MQTT
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Scalability and Performance
&lt;/h3&gt;

&lt;p&gt;AWS offers virtually unlimited scalability, allowing businesses to quickly scale up or down as their needs change. This is particularly important for IoT projects, where the number of connected devices can easily run into the thousands or even millions.&lt;/p&gt;

&lt;p&gt;In terms of performance, AWS offers a high-speed network backbone, ensuring that data is transmitted quickly and reliably. This is crucial for applications that require real-time data, such as monitoring systems or control applications. Furthermore, AWS's global infrastructure ensures that data can be transmitted and received from anywhere in the world, minimizing latency and ensuring optimal performance.&lt;/p&gt;

&lt;h3&gt;
  
  
  Security and Compliance
&lt;/h3&gt;

&lt;p&gt;Another key advantage of using AWS with MQTT is the strong security and compliance measures it provides. AWS offers a range of security features, including encryption at rest and in transit, fine-grained access control, and the ability to create private networks within the cloud. This ensures that your data is protected at all times, reducing the risk of unauthorized access or data breaches.&lt;/p&gt;

&lt;p&gt;In terms of compliance, AWS has been certified against a wide range of international and industry-specific standards, including ISO 27001, PCI DSS, and HIPAA. This means that businesses can confidently use AWS for their MQTT projects, knowing that they are in compliance with these stringent standards.&lt;/p&gt;

&lt;h3&gt;
  
  
  Integration with Other AWS Services
&lt;/h3&gt;

&lt;p&gt;AWS with MQTT also benefits from seamless integration with other AWS services. For example, data transmitted via MQTT can be stored and analyzed using AWS's data storage and analytics services, such as S3 and Redshift. This allows businesses to easily build comprehensive IoT solutions, combining real-time data with sophisticated analytics.&lt;/p&gt;

&lt;p&gt;Furthermore, integrating MQTT with other AWS services can help to streamline operations and reduce costs. For example, by integrating MQTT with AWS's Lambda service, businesses can run code in response to MQTT messages, without the need to provision or manage servers.&lt;/p&gt;

&lt;h3&gt;
  
  
  Managed Service Benefits
&lt;/h3&gt;

&lt;p&gt;Finally, using AWS with MQTT provides the benefits of a managed service. AWS takes care of all the infrastructure, maintenance, and management, allowing businesses to focus on their core competencies. This reduces the complexity of managing an IoT project, saving time and resources.&lt;/p&gt;

&lt;p&gt;In addition, managed services provide a level of reliability and uptime that would be difficult to achieve with an in-house solution. AWS's extensive infrastructure and redundancy measures ensure that the service is always available, minimizing the risk of downtime.&lt;/p&gt;

&lt;h2&gt;
  
  
  4 Best Practices for AWS MQTT Implementation
&lt;/h2&gt;

&lt;p&gt;Here are a few best practices that can help you make the most of your MQTT implementation in AWS.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Proper Configuration and Tuning
&lt;/h3&gt;

&lt;p&gt;When implementing AWS with MQTT, make sure you set up the right security measures, such as enabling encryption and setting up access controls, to protect your data.&lt;/p&gt;

&lt;p&gt;Additionally, tuning the performance of your &lt;a href="https://www.emqx.com/en/blog/the-ultimate-guide-to-mqtt-broker-comparison" rel="noopener noreferrer"&gt;&lt;strong&gt;MQTT broker&lt;/strong&gt;&lt;/a&gt; is crucial to ensure optimal performance. This includes adjusting the settings for maximum connections, message size, and message rate, among others. Remember, the goal is to achieve a balance between performance and resource usage.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Monitoring and Logging
&lt;/h3&gt;

&lt;p&gt;AWS provides several tools for monitoring your MQTT broker, such as CloudWatch, which provides real-time metrics and alarms, and X-Ray, which provides insights into the behavior of your applications.&lt;/p&gt;

&lt;p&gt;Logging, on the other hand, is crucial for troubleshooting and understanding your MQTT traffic. AWS provides CloudTrail, which logs all API calls, allowing you to track who is making calls, the source IP address, and when the calls were made.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Security and Compliance Adherence
&lt;/h3&gt;

&lt;p&gt;It is important to regularly review and update your security settings, ensure that your data is encrypted, and keep your software up to date.&lt;/p&gt;

&lt;p&gt;In terms of compliance, it is crucial to understand the specific requirements of the standards you are subject to, and to ensure that your AWS MQTT implementation meets these requirements. Regular audits and assessments can help to ensure ongoing compliance.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Resource Management
&lt;/h3&gt;

&lt;p&gt;Resource management includes monitoring your resource usage, managing your costs, and ensuring that you have the necessary resources to scale as your needs change.&lt;/p&gt;

&lt;p&gt;AWS provides several tools to help with resource management, including Cost Explorer, which provides detailed insights into your costs, and Trusted Advisor, which provides recommendations for optimizing your AWS resources.&lt;/p&gt;

&lt;h2&gt;
  
  
  AWS IoT Core + EMQX: A Better Choice for IoT Communication
&lt;/h2&gt;

&lt;p&gt;Working with AWS IoT Core can raise some challenges related to management of large-scale MQTT communications. &lt;a href="https://www.emqx.com/en/cloud" rel="noopener noreferrer"&gt;&lt;strong&gt;EMQX Cloud&lt;/strong&gt;&lt;/a&gt; can help, with a comprehensive MQTT service that is fully managed and customizable to the needs of users. This includes flexible pricing models, customizable connection specifications, and the freedom to select a cloud provider and integrate with other cloud resources.&lt;/p&gt;

&lt;p&gt;Compared to the AWS IoT, EMQX Cloud, can provide a complete solution to match the AWS IoT ecosystem.&lt;/p&gt;

&lt;h3&gt;
  
  
  EMQX Cloud Products
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.emqx.com/en/cloud/byoc" rel="noopener noreferrer"&gt;&lt;strong&gt;BYOC (Bring Your Own Cloud)&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;:&lt;/strong&gt; Seamlessly integrates the EMQX MQTT server with Amazon Web Services or other existing cloud services. Keep your data secure in your own cloud and manage it with EMQ's expertise.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.emqx.com/en/cloud/serverless-mqtt" rel="noopener noreferrer"&gt;&lt;strong&gt;Serverless&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;:&lt;/strong&gt; Provides MQTT services on a secure and scalable cluster with usage-based pricing. The service is completely free within the free quota and supports up to 1000 concurrent connections.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.emqx.com/en/cloud/dedicated" rel="noopener noreferrer"&gt;&lt;strong&gt;Dedicated Plan&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;:&lt;/strong&gt; Provides MQTT services on a dedicated EMQX cluster with high performance, reliability, and data integration, without managing your own cluster. Perfect for businesses of all sizes.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Tight Integration with AWS Services
&lt;/h3&gt;

&lt;p&gt;EMQX integrates smoothly with Amazon Web Services:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;EMQX Cloud Dedicated cluster can be deployed in 10 regions in AWS, seamlessly integrating with existing resources in AWS.&lt;/li&gt;
&lt;li&gt;EMQX Cloud provides data integration with 40+ services (connectors), including databases, message queues, and AWS services like DynamoDB.&lt;/li&gt;
&lt;li&gt;You can subscribe to EMQX Cloud from the AWS marketplace, and manage all service bills in AWS Billing.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Benefits of Using EMQX Cloud
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Hassle-Free Management:&lt;/strong&gt; EMQX Cloud fully manages setup, maintenance, and updates.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cost-Effective:&lt;/strong&gt; EMQX Cloud offers a variety of pricing models, such as by consumption or by time, which reduce the total cost of ownership.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;100% MQTT:&lt;/strong&gt; 100% compliant with MQTT 3.1, 3.1.1, and 5.0 standards with all 3 QoS level. Seamless integration with all MQTT clients.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Seamless Scalability:&lt;/strong&gt; Scale up or down on demand without any worries about server capacity or performance.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Up to 99.99% SLA:&lt;/strong&gt; EMQX Cloud Ensure maximum uptime and availability with our highly available, fault-tolerant architecture.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;24 x 7 Technical Support:&lt;/strong&gt; A dedicated team of experts is always available to assist you with any issues at any time.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  EMQX Cloud vs. AWS IoT Core
&lt;/h3&gt;

&lt;p&gt;The table below compares AWS IoT Core with EMQX Cloud in various aspects:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fas7qma7rcbbyi4e8nti8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fas7qma7rcbbyi4e8nti8.png" alt="Image description" width="800" height="592"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Originally published at &lt;a href="https://www.emqx.com/en/blog/aws-mqtt-managing-iot-communication-in-aws" rel="noopener noreferrer"&gt;www.emqx.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>mqtt</category>
      <category>iot</category>
    </item>
  </channel>
</rss>
