--- title: "Azure IoT Hub Example" slug: "azure-iot-hub-example" description: "MQTT Client is a N3uron module designed to connect to any MQTT broker in order to send and receive tag events. MQTT Client implements a bidirectional…" updated: 2025-09-30T15:55:31Z published: 2025-12-23T10:03:05Z canonical: "docs.n3uron.com/azure-iot-hub-example" --- > ## Documentation Index > Fetch the complete documentation index at: https://docs.n3uron.com/llms.txt > Use this file to discover all available pages before exploring further. # Azure IoT Hub Example ## Azure IoT Hub [Embedded content](https://www.youtube.com/embed/imVzT21zVhs?&wmode=opaque&rel=0) ### Creating a new IoT Hub - **Step 1:** Log into Microsoft Azure and go to [](https://portal.azure.com/)[Microsoft Azure Portal](https://portal.azure.com/)[](https://portal.azure.com/). ![Figure 93- Microsoft Azure Portal](https://cdn.document360.io/54093ab5-6b22-4542-a265-04377931f11a/Images/Documentation/Figure%2093-%20Microsoft%20Azure%20Portal.png) Once logged in, you’ll need to create the Azure resources that your device, in our case a **N3uron** node, will require to connect to the Azure IoT Hub and start exchanging messages. - **Step 2:**  From the Azure homepage, select the **+ Create a resource** option and then enter IoT Hub in the **Search the Marketplace** field. - **Step 3:** Select **IoT Hub** from the search results and then select **Create**. ![Figure 94- Create an IoT Hub](https://cdn.document360.io/54093ab5-6b22-4542-a265-04377931f11a/Images/Documentation/Figure%2094-%20Create%20an%20IoT%20Hub.png) - **Step 4:** In the **Basics** tab, complete the fields as follows, - **Subscription:** In this case, Azure subscription 1 . - **Resource Group:** In this case, CS_N3uron . - **Region:** Select the location closest to you. - **IoT Hub Name:** In this case, N3-IoT. ![Figure 95- IoT Hub Basics](https://cdn.document360.io/54093ab5-6b22-4542-a265-04377931f11a/Images/Documentation/Figure%2095-%20IoT%20Hub%20Basics.png) - **Step 5:** Select **Next: Networking** to continue creating your hub. Choose the endpoints that the devices can use to connect to your IoT Hub and select the **Public access** default setting. ![Figure 96- IoT Hub Networking](https://cdn.document360.io/54093ab5-6b22-4542-a265-04377931f11a/Images/Documentation/Figure%2096-%20IoT%20Hub%20Networking.png) - **Step 6:** Select **Next: Management** to continue creating your hub. - Accept the default settings here. - **Step 7:** Select **Next: Tags** to continue to the next screen. Accept the default settings here. - **Step 8:** Select **Next: Review + create** to review your choices. You should see something similar to this screen but with the values you selected when creating the hub. - **Step 9:**  Select **Create** to start the deployment of your new hub. Your deployment will remain in progress for a few minutes while the hub is being created. Once the deployment is complete, select **Go to resource** to open the new hub. ![Figure 97- IoT Hub Review and Creation](https://cdn.document360.io/54093ab5-6b22-4542-a265-04377931f11a/Images/Documentation/Figure%2097-%20%20IoT%20Hub%20Review%20and%20Creation.png) ### **Configuring Your Shared Access Policy** You can choose between two different mechanisms provided by Azure IoT Hub to authenticate devices and services: **Security Tokens** and **X.509 Certificates**. In this example, we are going to use **Security Tokens**. These **Security Tokens** are also known as Shared Access Signature (SAS) tokens. For more details about configuration using **X.509 Certificates**, [](/v122/docs/mqtt-client-connecting-different-brokers)[click here](/v122/docs/mqtt-client-connecting-different-brokers)[](/v122/docs/mqtt-client-connecting-different-brokers). - **Step 1:** In the resource panel of the IoT Hub you have just created, select **Shared access policies**. - **Step 2:** Click on **iothub****owner** and copy the **Primary connection string** from the right-hand panel. ![Figure 98- Shared Access Policies](https://cdn.document360.io/54093ab5-6b22-4542-a265-04377931f11a/Images/Documentation/Figure%2098-%20Shared%20Access%20Policies.png) - **Step 3:** Start the **Azure IoT Explorer, click on the + Add connection** button, and paste the **Primary connection string** in the **Connection String** text box. Next click **Save**. ![Figure 99- Configuring Azure IoT Device Explorer](https://cdn.document360.io/54093ab5-6b22-4542-a265-04377931f11a/Images/Documentation/Figure%2099-%20Configuring%20Azure%20IoT%20Device%20Explorer.png) - **Step 4:** In the **Devices** section, click on the **+New button** and enter a name for your device. In this example, we have named it “N3uron_Gateway**”**. In **Authentication type,** select **Symmetric key**, check the **Auto-generate keys** field, and click on **Create.** ![Figure 100- Creating Security Keys](https://cdn.document360.io/54093ab5-6b22-4542-a265-04377931f11a/Images/Documentation/Figure%20100-%20Creating%20Security%20Keys.png) - **Step 5:** After creating the new identity, expand the **Connection string with SAS token** section. In the **Symmetric key** drop-down menu, select Primary Key, enter a sufficiently high figure in **Expiration (minutes)**, click on the **Generate Button,** and copy the part of the **SAS token connection string** form ***SharedAccessSignature=*** onwards. ![Figure 101- Obtaining the SAS Token](https://cdn.document360.io/54093ab5-6b22-4542-a265-04377931f11a/Images/Documentation/Figure%20101-%20Obtaining%20the%20SAS%20Token.png) ## Start Configuring the N3uron IIoT Platform ### **Create a Module Instance Within N3uron's WebUI Interface** - **Step 1:** In the **Navigation** panel, select **Config.** - **Step 2:** In the **Explorer** panel, select **Modules**. - **Step 3:** Click on the **Model** menu and select **New Module**. - **Step 4:** The instance can be given any name but for this example, we will use MQTT. ![Figure 102- Create a new module](https://cdn.document360.io/54093ab5-6b22-4542-a265-04377931f11a/Images/Documentation/Figure%20102-%20Create%20a%20new%20module.png) - **Step 5:** Provide a name for the module, in this case, MQTT, set the module type, in this case, MqttClient. Leave the rest of the properties as their default values and click **Save**. ![Figure 103- Configure the module(1)](https://cdn.document360.io/54093ab5-6b22-4542-a265-04377931f11a/Images/Documentation/Figure%20103-%20Configure%20the%20module(1).png) ### **Configuring N3uron's MQTT Module within the WebUI's Explorer Panel** - **Step 1:** In the **Explorer** panel, select the **MQTT** instance you have just created. - **Step 2:** Click on the Model menu bottom bar and select **New Connection**. - **Step 3:** Give the new connection a name. In this example, it has been named AZURE. - **Step 4:** Configure the connection properties: - **Destination Broker:** Microsoft Azure. - **Client ID : N3uron_Gateway.** **Note:Ensure the Client ID matches the device name configured earlier in the Azure IoT Explorer settings.** - **Username**: Enter the Hostname of your Azure IoT Hub followed by “/” and the name of your device. In this case, N3-IoT.azure devices.net/N3uron_Gateway. - **Password:** Enter the string you copied from the SAS Token. - **Broker URL:** Enter the **Hostname** of your Azure IoT Hub. In our case, this is N3-IoT.azure-devices.net.[](//N3-IoT.azure-devices.net)**[](//N3-IoT.azure-devices.net)** - Leave the rest of the properties as their default values and click on **Save**. ![AzureConnection](https://cdn.document360.io/54093ab5-6b22-4542-a265-04377931f11a/Images/Documentation/AzureConnection.png) Now, navigate back to **Azure IoT Explorer** where, providing that everything has been properly configured, you should see your device connected to your IoT Hub. ![Figure 105- Azure IoT Explorer displaying our N3uron node connected](https://cdn.document360.io/54093ab5-6b22-4542-a265-04377931f11a/Images/Documentation/Figure%20105-%20Azure%20IoT%20Explorer%20displaying%20our%20N3uron%20node%20connected.png) ### Publishing & Subscribing Data via N3uron and Azure IoT Hub - **Step 1:** Within the **Model** panel, right-click on the AZURE Connection you have just configured, select **New Publisher,** and give it a name. In this example, we will simply use Publisher. - **Step 2:** Click on it and add a name in the **Topic** field. To publish an MQTT message to Azure, you cannot use any topic name, as it must be named according to the following format **devices/{device_id}/messages/events/**. In our example, we have used devices/N3uron_Gateway/messages/events/ - **Step 3:** Click on the **Tag Filter** button, select **New Tag Filter,** and change the default name. In this example, we have used Filter. Leave **Mode**, **Path,** and **Regex pattern** as their default values. With this configuration, every tag configured in N3uron will be published to our Azure Broker. ![AzurePub](https://cdn.document360.io/54093ab5-6b22-4542-a265-04377931f11a/Images/Documentation/AzurePub.png) - **Step 4:** In the **Explorer panel,** select **Tags**. - **Step 5:** In the **Model** menu, right-click on the folder icon, select **New Tag,** and give it a name. In this example, we will use Process_value. - **Step 6:** Within the **Configuration** panel, set the following properties using the values shown below, leaving the rest of them as their default values: - **Type**: Number. - **Simulation/Enabled**: Yes ![Figure 107- Tag configuration settings in N3uron's MQTT module panel](https://cdn.document360.io/54093ab5-6b22-4542-a265-04377931f11a/Images/Documentation/Figure%20107-%20Tag%20configuration%20settings%20in%20N3uron's%20MQTT%20module%20panel.png) - **Step 7:** Go to the **Azure IoT Explorer** and in the **Telemetry Tab** of your device, you should see the messages being sent by your N3uron node in real-time, as shown in the image below. ![Figure 108- Azure IoT Explorer Displayingthe messages sent by N3uron](https://cdn.document360.io/54093ab5-6b22-4542-a265-04377931f11a/Images/Documentation/Figure%20108-%20Azure%20IoT%20Explorer%20Displayingthe%20messages%20sent%20by%20N3uron.png) ### **Subscribe to a Topic Using N3uron's MQTT Module** - **Step 1:** In the **Model** panel, right-click on the AZURE Connection, select **New Subscriber** and give it a name. In this example, we will simply use Subscriber. - **Step 2:** Click on it and add a name in the **Topic** field. Since IoT Hub is not a general-purpose pub-sub messaging broker, it only supports the documented topic names and topic filters. IoT Hub delivers messages with the Topic Name **devices/{device_id}/messages/devicebound/**, or **devices/{device_id}/messages/devicebound/{property_bag}** if there are any message properties. In this example, we are going to enter the following string in the **Topic**: devices/N3uron_Gateway/messages/devicebound/# - **Step 3:** Set the following properties using the values shown below, leaving the rest of them as their default values: - **Qos**: QoS 0. - **Encoding**: UTF8 - **Compression**: None - **Serialization**: JSON - **Data parser/Type**: MqttClient JSON ![Figure - AZURE Subscriber](https://cdn.document360.io/54093ab5-6b22-4542-a265-04377931f11a/Images/Documentation/Figure%20-%20AZURE%20Subscriber.png) - **Step 4:** Within the **Explorer panel,** select **Tags**. - **Step 5:** In the **Model** menu, right-click on the folder icon, select **New Tag,** and give it a name. In this example, we will use Subscribed_Value. - Step 6: In the **Configuration** panel, set the following properties using the values shown below, leaving the rest of them as their default values: - **Type**: Number - **Source/Enabled**: Yes - **Module Type**: MqttClient - **Module name**: MQTT - **Config/Subscriber**: Azure/Subscriber - **Step 7:** Click **Save.** ![Figure 110-Subscribed tag configuration settings in N3uron's WebUI interface](https://cdn.document360.io/54093ab5-6b22-4542-a265-04377931f11a/Images/Documentation/Figure%20110-Subscribed%20tag%20configuration%20settings%20in%20N3uron's%20WebUI%20interface.png) - **Step 8:** Go to the **Azure IoT Explorer,** and click on the **Cloud-to-device-message** tab of your device. - **Step 9:** In the Message Body enter the following in **Message Payload**: ```shell { "/Subscribed_value": [{ "v": 3.14159, "q": 192, "ts": 1630668488618 }] } ``` - **Step 10:** Click on the **Add system property** drop-down menu and select **messageid**. In the Value field enter Test2, as shown below. ![Figure 111- Sending a message from Azure IoT Platform](https://cdn.document360.io/54093ab5-6b22-4542-a265-04377931f11a/Images/Documentation/Figure%20111-%20Sending%20a%20message%20from%20Azure%20IoT%20Platform.png) - **Step 11:** Click on the **Send message to device** button. - **Step 12:** Navigate back to the **N3uron WebUI interface** and select **Data/Real Time** from the left-hand panel. You should now see the Subscribed_Value tag you created previously with a value of 3.14159. ![Figure 112- Real-time values in N3uron's WebUI interface](https://cdn.document360.io/54093ab5-6b22-4542-a265-04377931f11a/Images/Documentation/Figure%20112-%20Real-time%20values%20in%20N3uron's%20WebUI%20interface.png) [MQTT Client Full Product Details](https://n3uron.com/iiot-platform-modules/mqtt-client/)