You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 36 Next »

Prerequisites

Summary

The tutorial will provide step by step instructions for the following:

  • Configuring Azure IoT Hub to allow client connections to a deployed IoT Edge Hub
  • Connecting Azure Injector to the IoT Edge Hub
  • Publishing data from Azure Injector to Azure IoT Edge Hub and viewing the data

Tutorial

There are two primary ways to connect to an Azure Edge Hub via MQTT from an MQTT client. These are 'module' or 'device' connections. A module connection typically involves an application deployed as a docker container that runs in Azure Edge. This is the preferred way of connecting the Azure Injector module to Azure Edge Hub. This tutorial will use this method for connecting to Azure IoT Edge.

After completing the prerequisites, you should have an IoT Edge Device as shown below. In this example, it has a name of 'My-IoT-Edge' and is listed under the IoT Edge devices.

Note this shows an error that the '417 - The device's deployment configuration is not set'. This can be fixed by creating a deployment configuration for this Azure Edge Device. Begin by clicking the Device in the Azure Portal. After doing so, you should see something similar to what is shown below.

Now click 'Set modules' in the upper left corner. That will open the following page.

Add a new 'Container Registry Credentials' with the following parameters.

  • Name: DockerHub
  • Address: https://registry.hub.docker.com/
  • User Name: username
    • Note the Ignition image is public and doesn't require a username and password to access. However, this field must be non-empty and can be set to any non-empty value.
  • Password: password
    • Note the Ignition image is public and doesn't require a username and password to access. However, this field must be non-empty and can be set to any non-empty value.

Now click the '+ Add' drop down under 'IoT Edge Modules' and select 'IoT Edge Module' as shown below.

This will open the following page.

  • Set the following fields under 'Module Settings'.
    • IoT Edge Module Name: Ignition
    • Image URI: inductiveautomation/ignition:8.1.7
    • Restart Policy: always
    • Desired Status: running
    • Image Pull Policy: On create
    • Startup Order: 200
  • Leave the 'Environment Variables' blank
  • Under 'Container Create Options' set the following JSON as the value. The 'Binds' field is required and there to preserve Ignition configuration across container deployments.

    {
        "HostConfig": {
            "Binds": [
                "IgnitionData:/usr/local/bin/ignition/data"
            ],
            "PortBindings": {
                "8088/tcp": [
                    {
                        "HostPort": "8088"
                    }
                ],
                "8043/tcp": [
                    {
                        "HostPort": "8043"
                    }
                ],
                "8060/tcp": [
                    {
                        "HostPort": "8060"
                    }
                ]
            }
        }
    }
  • Leave the 'Module Twin Settings' blank

Finally, click 'Add'. After doing so you should see the following.

Now click 'Next: Routes'. This will open the following page.

Leave the default route in place. This will allow messages to flow from Azure IoT Edge Hub to Azure IoT Hub. This feature will be used later in this tutorial.

Now click 'Review + create' in the lower left corner. This will bring up the following page.

Finally, click 'Create' in the lower left corner. This will deploy the Ignition module to Azure Edge. It takes a few minutes. You can use the 'Refresh' button on the Device page to check the status of the deployment. Once Ignition has successfully deployed, you should see the following. Specifically note that $edgeHub and 'Ignition' now show a 'Runtime Status' of 'running'.

Now click the 'Ignition' module link near the bottom of the page. This will open the following page.

Copy the 'Connection string (primary key)' and save it for later use. This will be used in the Ignition configuration to establish an MQTT Connection from Ignition's Azure Injector module to Azure IoT Edge Hub.

At this point, Ignition is running as a Docker container in Azure Edge. You should be able to browse to http://[ip_address_of_azure_edge]:8088. Replace [ip_address_of_azure_edge] with the IP address of your Azure Edge system. You should see something similar to the following.

Select 'Ignition' or 'Ignition Edge' depending on your preference. We'll use Ignition for this tutorial. After selecting an Ignition type, you should see the following.

Accept the Inductive Automation Software License Agreement if you read and agree with the terms and conditions and click 'Next'. This will open the following page.

Now specify the username and password to use for your Ignition system. Save these for later as they will be required any time you log into the Ignition Web UI. Now click 'Finish Setup' which will open the following page.

Click 'Start Gateway'. This will take a few minutes to start the Ignition Gateway. When it is complete, you will see the following page.

If you are unfamiliar with Ignition or want to enable the 'Quick Start', select it. Otherwise, click 'start from scratch'. Now click 'Config' in the far left navigation panel. You should now see the following page. Note you may be asked to log in.

Now click 'Modules' under the 'System' section in the blue left navigation panel. This will open the following page.

Scroll to the bottom and click the 'Install or Upgrade a Module...' link near the bottom of the page. This will open the following page.

Go to https://inductiveautomation.com/downloads/third-party-modules/ and download the latest Azure Injector module. Use this on the upload form in the Ignition Web UI. After installing you should see the Azure Injector module in the modules list as shown below.

Now select 'Settings' under the Azure Injector section in the left navigation panel near the bottom. After doing so, you should see the following page.

Now select 'Azure IoT Edge Hubs' from the tabs near the top of the page. This will open the following page.

Now select the 'Certificates' tab next to 'Settings'. This will show the following page.

Click 'Create new Certificate'. Then browse to the Azure IoT Edge Device Root CA that you provisioned during the installation and configuration of the Azure IoT Edge Device. Give it a friendly name as shown below.

Now click 'Create New Certificate'. After doing so you should see something similar to the following.

Now select the 'Settings' tab directly to the left of the 'Certificates' tab. Then click the 'Create new Azure IoT Edge Hub Setting...' link. This will open the following page.

Set the following parameters in the form (leave all others in their default state)

  • Main Section
    • Setting Name: Azure IoT Edge
  •  Authentication Section
    • Password: The Connection String associated with the 'Ignition' module you captured earlier in this tutorial.
    • CA Certificate File: The 'IoT Edge Device Root CA' created in the previous step

After the parameters are set, click the 'Save Changes' button at the bottom of the page. After doing so, you should see the following.

If everything went well, you should also see 'Connected' under the Status column. Note it may take a couple of seconds to switch to a Connected status.

If the Status does not show connected, browse to the Ignition 'Status → Logs' page to see any errors that may provide clues as to why the connection failed. Common issues include:

  • Mis-configured certificates resulting in TLS errors
  • Firewall issues
    • Make sure the MQTTS port (usually 8883) is open all the way to the Azure Edge Hub


Once the system is showing connected, tags can be created in Ignition Designer. Begin by using the following document to launch Designer: https://docs.inductiveautomation.com/display/DOC80/Designer+Launcher

With Ignition Designer launched, you should see something similar to the following.

In the lower left 'Tag Browser' pane make sure the 'default' tag provider is selected. Then right click on the 'Edge Nodes' folder and select 'New Tag' and then 'New Folder'. Name the new folder 'My Group' and click OK. You should now see the following.

You may need to press the 'Refresh' button in the top bar of the Tag Browser to show the new folder

Repeat this process until you have a folder structure of 'Edge Nodes/My Group/My Edge Node/My Device' as shown below.

Now right click on the 'My Device' folder and select 'New Tag' → 'New Standard Tag' → 'Memory Tag'. In the dialog, set the following parameters and leave all other tags default.

  • Name: My Tag
  • Value: 123

After clicking 'OK', you should see the following.

Using the Azure Command Line tools you previously installed on a development machine (from the prereqs here), run the following command

az iot hub monitor-events --hub-name YOUR_HUB_NAME --consumer-group YOUR_CONSUMER_GROUP --timeout 0

You should see a message denoting the monitor is running as follows

Starting event monitor, use ctrl-c to stop...


Now from the Tag Browser dropdown menu at the top select 'Azure

This will show tags from the Azure Injector Tag Provider. Expand 'Azure Injector Control' and write a 'true' to the 'Refresh' tag boolean by clicking on the checkbox. You will be asked to change to Read/Write mode as shown below. Click 'Enable Read/Write Mode'.

After doing so, writing true to the 'Refresh' boolean tag will cause the Azure Injector to rescan the tag tree and publish the Sparkplug BIRTH sequence to Azure IoT Edge Hub. In the Azure CLI event monitor output you should see the following.

{
    "event": {
        "origin": "My-IoT-Edge",
        "payload": "{\"topic\":{\"namespace\":\"spBv1.0\",\"edgeNodeDescriptor\":\"My Group/My Edge Node\",\"groupId\":\"My Group\",\"edgeNodeId\":\"My Edge Node\",\"type\":\"NBIRTH\"},\"payload\":{\"timestamp\":1627401528598,\"metrics\":[{\"name\":\"bdSeq\",\"timestamp\":1627401528573,\"dataType\":\"Int64\",\"value\":0}],\"seq\":0}}"
    }
}
{
    "event": {
        "origin": "My-IoT-Edge",
        "payload": "{\"topic\":{\"namespace\":\"spBv1.0\",\"edgeNodeDescriptor\":\"My Group/My Edge Node\",\"groupId\":\"My Group\",\"edgeNodeId\":\"My Edge Node\",\"deviceId\":\"My Device\",\"type\":\"DBIRTH\"},\"payload\":{\"timestamp\":1627401528604,\"metrics\":[{\"name\":\"My Tag\",\"timestamp\":1627401528604,\"dataType\":\"Int32\",\"metaData\":{},\"properties\":{\"Quality\":{\"type\":\"Int32\",\"value\":192}},\"value\":123}],\"seq\":1}}"
    }
}


The messages flowing into Azure IoT Edge Hub are also automatically routed to Azure IoT Hub because of the module deployment that was specified in the Azure IoT Edge.

At this point you can also change the value of the tag that was created in Designer. The messages coming out of Azure Injector are 'event driven' meaning that a tag must change for data to flow. Changing the tag value to 122 results in the following message going to Azure Event Hub.

{
    "event": {
        "origin": "My-IoT-Edge",
        "payload": "{\"topic\":{\"namespace\":\"spBv1.0\",\"edgeNodeDescriptor\":\"My Group/My Edge Node\",\"groupId\":\"My Group\",\"edgeNodeId\":\"My Edge Node\",\"deviceId\":\"My Device\",\"type\":\"DDATA\"},\"payload\":{\"timestamp\":1627403950739,\"metrics\":[{\"name\":\"My Tag\",\"timestamp\":1627403949486,\"dataType\":\"Int32\",\"value\":122}],\"seq\":2}}"
    }
}


Additional Resources

  • No labels