The IoT Hub is the gateway for data to the Microsoft Azure Portal. Data can be exchanged with the IoT Hub via MQTT. We show the MQTT connection of the IoT Hub in a step by step tutorial with OPC Router as MQTT client.

The Microsoft Azure Cloud is one of the leading cloud environments on the market. The Azure Portal provides many ready-made services that can be easily connected. Cloud applications are created by interconnecting the finished components. One of these components is the IoT Hub, which serves as the most important bidirectional connector for external data sources and IoT devices. With the OPC Router, the IoT Hub and thereby the Azure Cloud can be connected to write data to the Azure Cloud, but also to obtain data from the Cloud for the field level. The connection of the IoT Hub is realized with the OPC Router MQTT Client Plug-in. The transfer of data at the field level or the data procurement for the cloud is implemented with the various plug-ins of the OPC Router. You can find a dedicated video about this topic by visiting our tutorial stream.

Azure IoT Hub MQTT Connection

MQTT Connection of the Azure IoT Hub

For the connection the following steps are necessary, which we will explain in detail below. If you do not yet have access to the Azure portal, you can create a free Azure account here.

  1. Create an Azure IoT Hub in the Azure Portal
  2. Determining the Azure IoT Hub connections data
  3. Configuration of the MQTT Client for connecting the IoT Hub

(Click to enlarge images)

Creating a new IoT Hub in the Azure Portal

  1. Login to the Azure portal: https://portal.azure.com/#home
  2. Click on “Create a resource”:
    Create a resource

    Create a resource

  3. Put in and choose “IoT Hub”:
    New ressource IoT Hub

    New ressource IoT Hub

  4. Create the IoT Hub:
    Create IoT Hub

    Create IoT Hub

  5. Put in the following data:
    • Subscription (1)
    • Resource group (2)
    • Region (3)
    • IoT hub name (4)

    After that click on “Review + create” (5):

    Project Details IoT Hub

    Project Details IoT Hub

  6. Review and create:
    Review and create

    Review and create

Azure IoT Hub – Determining connection data

  1. After aprox. five minutes the deployment has finished. Click on “Go to resource”:
    Deployment finished

    Deployment finished

  2. Click on “Shared access policies”:
    Shared access policies

    Shared access policies

  3. Click on policy “iothubowner”:
    policy iothubowner

    policy iothubowner

  4. Copy the connection string of the primary key:
    Connection string of the primary key

    Connection string of the primary key

Creating an MQTT Plug-in in OPC Router

  1. Do following steps in OPC Router:
    • Click “Plug-ins” (1)
    • Click “MQTT” below “Cloud / IoT” (2)
    • Click on the button to create a MQTT Plug-in (3)

    Create new Plug-in

    Create new Plug-in

  2. Put in the following data on tab “Router configuration”:
    • Name (1)
    • Cloud profile (2)

    After that click on tab “Azure”:

    Router configuration

    Router configuration

  3. Do following steps on tab “Azure”:
    • Put in the connection string (1) (see step 10 of section “Creating a new IoT Hub in the Azure portal”)
    • Choose or create a device (2)
    • Check the connection (3)

    After that click on the tab “Connection properties” to have a look:

    Creating a new IoT Hub in the Azure portal

    Creating a new IoT Hub in the Azure portal

  4. The three tabs “Connection properties”, “First will”, “Last will” don’t need to be modified und you agree with the OK button:
    Connection properties

    Connection properties

    First will

    First will

    Last will

    Last will

  5. Finally here is the finished MQTT entry:
    Finished MQTT entry

    Finished MQTT entry

Example: Transfer data to the IoT device

Here is an example for the transfer of temperature data:

Example for transfer of temperature data

IoT devices and monitoring

On the left site of the IoT Hub site you will find the menue entry “IoT devices” (1). For monitoring auf the transfered data start the Shell (2).

IoT devices

IoT devices

Via marked command “az iot hub monitor-events -n HubForOPCRouter -d Heating” you can see the received data on the device “Heating” on the hub “HubForOPCRouter”.

Azure Cloud Shell

Azure Cloud Shell

Azure IoT Hub Connection via Drag & Drop!

You can use the OPC Router to connect your production systems with the Azure Cloud via MQTT in a graphical way.