Skip to main content
Version: 1.8.5

CREATING AN AZURE IOT EDGE CONNECTION

Available since ThingPark X IoT Flow 1.7.16a.

The Azure IoT Edge connector sends the uplinks of your devices to an Azure IoT Edge gateway, which routes them to its Azure IoT hub. The connector connects to the gateway with the ID and the key of the IoT Edge device.

The data follows this path: LoRaWAN® device → ThingPark Enterprise → ThingPark X IoT Flow connection → Azure IoT Edge gateway → Azure IoT Hub.

Before you create the connection, you need an Azure IoT hub and an IoT Edge gateway that ThingPark X IoT Flow can reach. The following section sets up a test gateway on an Azure virtual machine.

Setting Up an IoT Edge Gateway on Azure​

  1. In your Azure IoT hub, open IoT Edge and click Add IoT Edge Device. Add an IoT Edge device

  2. Give a name to your IoT Edge device, such as EdgeGateway. Under Authentication type, make sure that Symmetric key is selected, and leave the Auto-generate keys box checked. Click Save.

  3. Click your new IoT Edge device to open its properties. Copy the Primary Connection String and save it in a text file for later use. Primary connection string of the IoT Edge device

  4. At the top of the blade, click Set Modules. At the top of the Set modules on device blade, click Routes, and add the following routes:

NameValue
allMessagesToHubFROM /messages/* INTO $upstream
allDownstreamToHubFROM /messages/* WHERE NOT IS_DEFINED ($connectionModuleId) INTO $upstream

At the bottom of the blade, click Review + create.

Routes of the IoT Edge device

  1. From the Azure home page, select Create a resource -> Template deployment. Create a resource from a template

  2. Select Build your own template in the editor. Build your own template in the editor

  3. Copy the following template into the editor, and click Save.

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.4.451.19169",
"templateHash": "12841244634154159240"
}
},
"parameters": {
"virtualMachineName": {
"type": "string",
"metadata": {
"description": "The unique name for the VM."
}
},
"deviceConnectionString": {
"type": "string",
"defaultValue": "",
"metadata": {
"description": "IoT Edge Device Connection String"
}
},
"virtualMachineSize": {
"type": "string",
"defaultValue": "Standard_DS1_v2",
"metadata": {
"description": "VM size"
}
},
"ubuntuOSVersion": {
"type": "string",
"defaultValue": "18.04-LTS",
"metadata": {
"description": "The Ubuntu version for the VM. This will pick a fully patched image of this given Ubuntu version."
}
},
"adminUsername": {
"type": "string",
"metadata": {
"description": "User name for the Virtual Machine."
}
},
"authenticationType": {
"type": "string",
"defaultValue": "password",
"metadata": {
"description": "Type of authentication to use on the Virtual Machine. SSH key is recommended for production."
},
"allowedValues": [
"sshPublicKey",
"password"
]
},
"adminPasswordOrKey": {
"type": "secureString",
"metadata": {
"description": "SSH Key or password for the Virtual Machine. SSH key is recommended."
}
},
"allowSSH": {
"type": "bool",
"defaultValue": true,
"metadata": {
"description": "Allow SSH traffic through the firewall"
}
}
},
"functions": [],
"variables": {
"imagePublisher": "Canonical",
"imageOffer": "UbuntuServer",
"nicName_var": "[format('nic-{0}', parameters('virtualMachineName'))]",
"vmName_var": "[parameters('virtualMachineName')]",
"virtualNetworkName_var": "[format('vnet-{0}', parameters('virtualMachineName'))]",
"publicIPAddressName_var": "[format('ip-{0}', parameters('virtualMachineName'))]",
"addressPrefix": "10.0.0.0/16",
"subnet1Name": "[format('subnet-{0}', parameters('virtualMachineName'))]",
"subnet1Prefix": "10.0.0.0/24",
"publicIPAddressType": "Dynamic",
"vnetID": "[resourceId('Microsoft.Network/virtualNetworks', variables('virtualNetworkName_var'))]",
"subnet1Ref": "[format('{0}/subnets/{1}', variables('vnetID'), variables('subnet1Name'))]",
"linuxConfiguration": {
"disablePasswordAuthentication": true,
"ssh": {
"publicKeys": [
{
"path": "[format('/home/{0}/.ssh/authorized_keys', parameters('adminUsername'))]",
"keyData": "[parameters('adminPasswordOrKey')]"
}
]
}
},
"dcs": "[parameters('deviceConnectionString')]",
"networkSecurityGroupName_var": "[format('nsg-{0}', parameters('virtualMachineName'))]",
"sshRule": [
{
"name": "default-allow-22",
"properties": {
"priority": 1000,
"access": "Allow",
"direction": "Inbound",
"destinationPortRange": "22",
"protocol": "Tcp",
"sourceAddressPrefix": "*",
"sourcePortRange": "*",
"destinationAddressPrefix": "*"
}
}
],
"noRule": []
},
"resources": [
{
"type": "Microsoft.Network/publicIPAddresses",
"apiVersion": "2015-06-15",
"name": "[variables('publicIPAddressName_var')]",
"location": "[resourceGroup().location]",
"properties": {
"publicIPAllocationMethod": "[variables('publicIPAddressType')]",
"dnsSettings": {
"domainNameLabel": "[parameters('virtualMachineName')]"
}
}
},
{
"type": "Microsoft.Network/networkSecurityGroups",
"apiVersion": "2019-08-01",
"name": "[variables('networkSecurityGroupName_var')]",
"location": "[resourceGroup().location]",
"properties": {
"securityRules": "[if(parameters('allowSSH'), variables('sshRule'), variables('noRule'))]"
}
},
{
"type": "Microsoft.Network/virtualNetworks",
"apiVersion": "2015-06-15",
"name": "[variables('virtualNetworkName_var')]",
"location": "[resourceGroup().location]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"[variables('addressPrefix')]"
]
},
"subnets": [
{
"name": "[variables('subnet1Name')]",
"properties": {
"addressPrefix": "[variables('subnet1Prefix')]",
"networkSecurityGroup": {
"id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName_var'))]"
}
}
}
]
},
"dependsOn": [
"[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName_var'))]"
]
},
{
"type": "Microsoft.Network/networkInterfaces",
"apiVersion": "2015-06-15",
"name": "[variables('nicName_var')]",
"location": "[resourceGroup().location]",
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName_var'))]"
},
"subnet": {
"id": "[variables('subnet1Ref')]"
}
}
}
]
},
"dependsOn": [
"[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName_var'))]",
"[resourceId('Microsoft.Network/virtualNetworks', variables('virtualNetworkName_var'))]"
]
},
{
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2016-04-30-preview",
"name": "[variables('vmName_var')]",
"location": "[resourceGroup().location]",
"properties": {
"hardwareProfile": {
"vmSize": "[parameters('virtualMachineSize')]"
},
"osProfile": {
"computerName": "[variables('vmName_var')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPasswordOrKey')]",
"customData": "[base64(format('#cloud-config\n\napt:\n preserve_sources_list: true\n sources:\n msft.list:\n source: \"deb https://packages.microsoft.com/ubuntu/18.04/multiarch/prod bionic main\"\n key: |\n -----BEGIN PGP PUBLIC KEY BLOCK-----\n Version: GnuPG v1.4.7 (GNU/Linux)\n\n mQENBFYxWIwBCADAKoZhZlJxGNGWzqV+1OG1xiQeoowKhssGAKvd+buXCGISZJwT\n LXZqIcIiLP7pqdcZWtE9bSc7yBY2MalDp9Liu0KekywQ6VVX1T72NPf5Ev6x6DLV\n 7aVWsCzUAF+eb7DC9fPuFLEdxmOEYoPjzrQ7cCnSV4JQxAqhU4T6OjbvRazGl3ag\n OeizPXmRljMtUUttHQZnRhtlzkmwIrUivbfFPD+fEoHJ1+uIdfOzZX8/oKHKLe2j\n H632kvsNzJFlROVvGLYAk2WRcLu+RjjggixhwiB+Mu/A8Tf4V6b+YppS44q8EvVr\n M+QvY7LNSOffSO6Slsy9oisGTdfE39nC7pVRABEBAAG0N01pY3Jvc29mdCAoUmVs\n ZWFzZSBzaWduaW5nKSA8Z3Bnc2VjdXJpdHlAbWljcm9zb2Z0LmNvbT6JATUEEwEC\n AB8FAlYxWIwCGwMGCwkIBwMCBBUCCAMDFgIBAh4BAheAAAoJEOs+lK2+EinPGpsH\n /32vKy29Hg51H9dfFJMx0/a/F+5vKeCeVqimvyTM04C+XENNuSbYZ3eRPHGHFLqe\n MNGxsfb7C7ZxEeW7J/vSzRgHxm7ZvESisUYRFq2sgkJ+HFERNrqfci45bdhmrUsy\n 7SWw9ybxdFOkuQoyKD3tBmiGfONQMlBaOMWdAsic965rvJsd5zYaZZFI1UwTkFXV\n KJt3bp3Ngn1vEYXwijGTa+FXz6GLHueJwF0I7ug34DgUkAFvAs8Hacr2DRYxL5RJ\n XdNgj4Jd2/g6T9InmWT0hASljur+dJnzNiNCkbn9KbX7J/qK1IbR8y560yRmFsU+\n NdCFTW7wY0Fb1fWJ+/KTsC4=\n =J6gs\n -----END PGP PUBLIC KEY BLOCK-----\npackages:\n - moby-cli\n - moby-engine\nruncmd:\n - dcs=\"{0}\"\n - |\n set -x\n (\n echo \"Device connection string: $dcs\"\n\n # Wait for docker daemon to start\n while [ $(ps -ef | grep -v grep | grep docker | wc -l) -le 0 ]; do\n sleep 3\n done\n\n apt install aziot-identity-service\n apt install aziot-edge\n\n if [ ! -z $dcs ]; then\n mkdir /etc/aziot\n wget https://raw.githubusercontent.com/Azure/iotedge-vm-deploy/1.2.0/config.toml -O /etc/aziot/config.toml\n sed -i \"s#\\(connection_string = \\).*#\\1\\\"$dcs\\\"#g\" /etc/aziot/config.toml\n\n echo \"Setup certificates\"\n mkdir /etc/gw-ssl\n git clone https://github.com/Azure/iotedge.git /etc/gw-ssl/iotedge\n\n mkdir /tmp/lab12\n cp /etc/gw-ssl/iotedge/tools/CACertificates/*.cnf /tmp/lab12\n cp /etc/gw-ssl/iotedge/tools/CACertificates/certGen.sh /tmp/lab12\n\n echo \"Generate certs\"\n chmod +x /tmp/lab12/certGen.sh\n /tmp/lab12/certGen.sh create_root_and_intermediate\n /tmp/lab12/certGen.sh create_edge_device_ca_certificate \"MyEdgeDeviceCA\"\n\n echo \"wait for certs\"\n\n echo \"Copy certs to Iot Edge folder\"\n cp /tmp/lab12/certs/azure-iot-test-only.root.ca.cert.pem /etc/aziot\n cp /tmp/lab12/certs/iot-edge-device-ca-MyEdgeDeviceCA-full-chain.cert.pem /etc/aziot\n cp /tmp/lab12/private/iot-edge-device-ca-MyEdgeDeviceCA.key.pem /etc/aziot\n\n chmod 666 /etc/aziot/azure-iot-test-only.root.ca.cert.pem\n chmod 666 /etc/aziot/iot-edge-device-ca-MyEdgeDeviceCA-full-chain.cert.pem\n chmod 666 /etc/aziot/iot-edge-device-ca-MyEdgeDeviceCA.key.pem\n\n echo \"Update config file\"\n\n echo \"\" >> /etc/aziot/config.toml\n echo \"trust_bundle_cert = ''file:///etc/aziot/azure-iot-test-only.root.ca.cert.pem''\" >> /etc/aziot/config.toml\n echo \"\" >> /etc/aziot/config.toml\n echo \"[edge_ca]\" >> /etc/aziot/config.toml\n echo \"cert = ''file:///etc/aziot/iot-edge-device-ca-MyEdgeDeviceCA-full-chain.cert.pem''\" >> /etc/aziot/config.toml\n echo \"pk = ''file:///etc/aziot/iot-edge-device-ca-MyEdgeDeviceCA.key.pem''\" >> /etc/aziot/config.toml\n\n chmod 755 /tmp/lab12\n chmod 755 /tmp/lab12/certs\n chmod 755 /tmp/lab12/private\n chmod 666 /tmp/lab12/certs/*\n chmod 666 /tmp/lab12/private/*\n\n iotedge config apply -c /etc/aziot/config.toml\n fi\n\n apt install -y deviceupdate-agent\n apt install -y deliveryoptimization-plugin-apt\n systemctl restart adu-agent\n\n ) &\n\n', variables('dcs')))]",
"linuxConfiguration": "[if(equals(parameters('authenticationType'), 'password'), json('null'), variables('linuxConfiguration'))]"
},
"storageProfile": {
"imageReference": {
"publisher": "[variables('imagePublisher')]",
"offer": "[variables('imageOffer')]",
"sku": "[parameters('ubuntuOSVersion')]",
"version": "latest"
},
"osDisk": {
"createOption": "FromImage"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName_var'))]"
}
]
}
},
"dependsOn": [
"[resourceId('Microsoft.Network/networkInterfaces', variables('nicName_var'))]"
]
}
],
"outputs": {
"PublicFQDN": {
"type": "string",
"value": "[reference(resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName_var'))).dnsSettings.fqdn]"
},
"PublicSSH": {
"type": "string",
"value": "[format('ssh {0}@{1}', reference(resourceId('Microsoft.Compute/virtualMachines', variables('vmName_var'))).osProfile.adminUsername, reference(resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName_var'))).dnsSettings.fqdn)]"
}
}
}
  1. The Custom deployment page is displayed. Fill in the fields:

    • Device Connection String: the primary connection string of the IoT Edge device, copied at step 3.
    • Virtual Machine Size: make sure that Standard_DS1_v2 is entered.
    • Ubuntu OS Version: make sure that 18.04-LTS is entered.
    • Admin Username: a user name.
    • Authentication Type: make sure that Password is selected.
    • Admin Password Or Key: the password you want to use. Keep a record of your user name and password in your text file: you need the password to open your SSH session.
    • Allow SSH: make sure that true is selected.

    To validate the template, click Review + create. If the validation passes, click Create. Custom deployment of the IoT Edge virtual machine

  2. Once the deployment is complete, open its Outputs pane, and record the following values in your text file:

    • PublicFQDN
    • PublicSSH
  3. In the Network security group blade, in the left menu under Settings, click Inbound security rules. At the top of the Inbound security rules pane, click Add. Inbound security rules

    In the Add inbound security rule pane:

    • Source: make sure that it is set to Any, to allow the traffic from any source.
    • Destination: make sure that it is set to Any.
    • Destination port ranges: 8883, the port of the MQTT protocol.
    • Protocol: TCP. MQTT uses TCP.
    • Action: make sure that Allow is selected.
    • Priority: a default value is supplied, in most cases 1010. It must be unique. Rules are processed in priority order; the lower the number, the higher the priority.
    • Name: MQTT.
    • Leave the other settings at their default value, and click Add. This inbound security rule allows the MQTT communication to the IoT Edge gateway. MQTT inbound security rule

After the MQTT rule, add two more rules with the following values, to open the ports of the AMQP and HTTPS protocols:

Destination Port RangesProtocolName
5671TCPAMQP
443TCPHTTPS
  1. Connect to the virtual machine with the PublicSSH command recorded at step 9. During the first start of the virtual machine, a script configured IoT Edge. This script:

    • Installed the aziot-identity-service package.
    • Installed the aziot-edge package.
    • Downloaded an initial version of config.toml (the configuration file of IoT Edge) to /etc/aziot/config.toml.
    • Added the device connection string supplied to the template to /etc/aziot/config.toml.
    • Cloned the IoT Edge git repository to /etc/gw-ssl/iotedge.
    • Created a /tmp/lab12 directory and copied the IoT Edge gateway SSL test tools from /etc/gw-ssl/iotedge.
    • Generated the test SSL certificates in /tmp/lab12 and copied them to /etc/aziot.
    • Added the certificates to /etc/aziot/config.toml.
    • Applied the updated /etc/aziot/config.toml to the IoT Edge runtime.
  2. To determine the version of IoT Edge that was installed, enter the following command:

    iotedge --version
  1. To view the IoT Edge configuration, enter the following command:
    cat /etc/aziot/config.toml

The output will be similar to

    hostname = "tpx-iot-edge.francecentral.cloudapp.azure.com"

trust_bundle_cert = 'file:///etc/aziot/azure-iot-test-only.root.ca.cert.pem'

[edge_ca]
cert = 'file:///etc/aziot/iot-edge-device-identity-EdgeGateway-full-chain.cert.pem'
pk = 'file:///etc/aziot/iot-edge-device-identity-EdgeGateway.key.pem'
auto_generated_edge_ca_expiry_days = 180

[provisioning]
source = "manual"
connection_string = "HostName=TPX-Connector.azure-devices.net;DeviceId=EdgeGateway;SharedAccessKey={YOUR-SHARED-ACCESS-KEY}"

[agent]
name = "edgeAgent"
type = "docker"

[agent.config]
image = "mcr.microsoft.com/azureiotedge-agent:1.2"

[connect]
workload_uri = "unix:///var/run/iotedge/workload.sock"
management_uri = "unix:///var/run/iotedge/mgmt.sock"

[listen]
workload_uri = "fd://aziot-edged.workload.socket"
management_uri = "fd://aziot-edged.mgmt.socket"

[moby_runtime]
uri = "unix:///var/run/docker.sock"
network = "azure-iot-edge"

  1. To ensure the IoT Edge daemon is running, enter the following command:
    sudo iotedge system status

This command will display output similar to:

   System services:
aziot-edged Running
aziot-identityd Running
aziot-keyd Running
aziot-certd Running
aziot-tpmd Ready

Use 'iotedge system logs' to check for non-fatal errors.
Use 'iotedge check' to diagnose connectivity and configuration issues.
  1. To verify the IoT Edge runtime has connected, run the following command:
    sudo iotedge check

This runs a number of checks and displays the results. For this lab, ignore the Configuration checks warnings/errors. The Connectivity checks should succeed and be similar to:

    Configuration checks (aziot-identity-service)
---------------------------------------------
√ keyd configuration is well-formed - OK
√ certd configuration is well-formed - OK
√ tpmd configuration is well-formed - OK
√ identityd configuration is well-formed - OK
√ daemon configurations up-to-date with config.toml - OK
√ identityd config toml file specifies a valid hostname - OK
‼ aziot-identity-service package is up-to-date - Warning
Installed aziot-identity-service package has version 1.4.1 but 1.4.6 is the latest stable version available.
Please see https://aka.ms/aziot-update-runtime for update instructions.
√ host time is close to reference time - OK
√ preloaded certificates are valid - OK
√ keyd is running - OK
√ certd is running - OK
√ identityd is running - OK
√ read all preloaded certificates from the Certificates Service - OK
√ read all preloaded key pairs from the Keys Service - OK
√ check all EST server URLs utilize HTTPS - OK
√ ensure all preloaded certificates match preloaded private keys with the same ID - OK

Connectivity checks (aziot-identity-service)
--------------------------------------------
√ host can connect to and perform TLS handshake with iothub AMQP port - OK
√ host can connect to and perform TLS handshake with iothub HTTPS / WebSockets port - OK
√ host can connect to and perform TLS handshake with iothub MQTT port - OK

Configuration checks
--------------------
√ aziot-edged configuration is well-formed - OK
√ configuration up-to-date with config.toml - OK
√ container engine is installed and functional - OK
√ configuration has correct URIs for daemon mgmt endpoint - OK
‼ aziot-edge package is up-to-date - Warning
Installed IoT Edge daemon has version 1.4.3 but 1.4.20 is the latest stable version available.
Please see https://aka.ms/iotedge-update-runtime for update instructions.
√ container time is close to host time - OK
‼ DNS server - Warning
Container engine is not configured with DNS server setting, which may impact connectivity to IoT Hub.
Please see https://aka.ms/iotedge-prod-checklist-dns for best practices.
You can ignore this warning if you are setting DNS server per module in the Edge deployment.
‼ production readiness: logs policy - Warning
Container engine is not configured to rotate module logs which may cause it run out of disk space.
Please see https://aka.ms/iotedge-prod-checklist-logs for best practices.
You can ignore this warning if you are setting log policy per module in the Edge deployment.
‼ production readiness: Edge Agent's storage directory is persisted on the host filesystem - Warning
The edgeAgent module is not configured to persist its /tmp/edgeAgent directory on the host filesystem.
Data might be lost if the module is deleted or updated.
Please see https://aka.ms/iotedge-storage-host for best practices.
‼ production readiness: Edge Hub's storage directory is persisted on the host filesystem - Warning
The edgeHub module is not configured to persist its /tmp/edgeHub directory on the host filesystem.
Data might be lost if the module is deleted or updated.
Please see https://aka.ms/iotedge-storage-host for best practices.
√ Agent image is valid and can be pulled from upstream - OK
√ proxy settings are consistent in aziot-edged, aziot-identityd, moby daemon and config.toml - OK

Connectivity checks
-------------------
√ container on the default network can connect to upstream AMQP port - OK
√ container on the default network can connect to upstream HTTPS / WebSockets port - OK
√ container on the IoT Edge module network can connect to upstream AMQP port - OK
√ container on the IoT Edge module network can connect to upstream HTTPS / WebSockets port - OK
29 check(s) succeeded.
6 check(s) raised warnings. Re-run with --verbose for more details.
2 check(s) were skipped due to errors from other checks. Re-run with --verbose for more details.
  1. Download the certificates generated in /tmp/lab12 from the virtual machine to your local machine. The MyEdgeDeviceCA certificate is one of them:
mkdir lab12
scp -r -p {username}@{FQDN}:/tmp/lab12 .

Replace {username} with the user name of the admin user of the virtual machine, and {FQDN} with the fully qualified domain name of the virtual machine (PublicFQDN).

Collecting Expected Information​

Parameters required

UI FieldDescription
NameName of the connection.
HostnameHost name of your Azure IoT hub: its name followed by .azure-devices.net, for example TPX-Connector.azure-devices.net.
Gateway Host NameHost name of the IoT Edge gateway, declared in the hostname parameter of its configuration file (/etc/aziot/config.toml). It's referred to in the connection string of the downstream device. It must resolve to an IP address, either with DNS or with a host file entry on the downstream device.
The IoT Edge Device IDID of the IoT Edge device, for example EdgeGateway.
Shared access keyPrimary key of the IoT Edge device.
CA CertificateThe MyEdgeDeviceCA certificate downloaded from the virtual machine of the gateway (step 16 of Setting Up an IoT Edge Gateway on Azure).
DescriptionOptional description of the connection.

The following settings are in the Advanced Settings section of the connection details, once the connection is created:

UI FieldDescription
Downlink EnabledEstablishes the downstream link that supports the downlinks.
Uplink ValidityMaximum age of an uplink, for example 1m: an older uplink is not sent to the cloud service, and an alarm event is saved in the events log. While a connection is not started or is down, uplinks accumulate, and most of them expire before the connection is up again. Examples: 60m, 12h, 3d12h60m.
Debug ModeLogs more details about the connection. It turns itself off after two days.

Creating a Connection With UI​

  1. In ThingPark Enterprise, click Connections -> + Add Connection -> ThingPark X IoT Flow. Add a ThingPark X IoT Flow connection in ThingPark Enterprise

  2. In ThingPark X IoT Flow, click Azure IoT Edge in the list of connectors. Select the Azure IoT Edge connector

  3. Fill in the form:

    • Name: a clear name for the connection, for example My Azure IoT Edge Connection.
    • Hostname: the name of your IoT hub followed by .azure-devices.net.
    • Gateway Host Name: the host name declared in the configuration file of the IoT Edge gateway.
    • The IoT Edge Device ID: the ID of the IoT Edge device created in your IoT hub.
    • Shared access key: the primary key of the IoT Edge device.
    • CA Certificate: click the attachment button and select the MyEdgeDeviceCA certificate downloaded from the virtual machine of the gateway, if your gateway requires it.
    • Description: optional. Set your Azure IoT Edge connection
  4. Click Create. A notification confirms that the connection has been created, and the connection details open.

  5. In the connection details, check that the connection is OPENED (see Connection States).

Note

Parameters marked with * are mandatory.

Creating a Connection With API​

You need to use the following endpoints:

  • POST/connections for creation
  • PUT/connections for modification
  • DELETE/connections for deletion
Note

When you want to update a configuration property on a Connection, you must provide all configuration properties again.

Example of the creation of a Connection.

POST /connections
{
"connectorId": "actility-azure-iot-edge",
"name": "Azure IoT-Edge Connection",
"configuration": {
"hostName": "TPX-Connector.azure-devices.net",
"gatewayHostName": "iot-flow-edge.francecentral.cloudapp.azure.com",
"deviceId": "EdgeGateway",
"sharedAccessKey": "{YOUR-SHARED-ACCESS-KEY}",
"iotHubTier": "S1",
"iotHubUnits": 1,
"trustedCaCertificate": "-----BEGIN CERTIFICATE-----{CONTENT-OF-THE-MYEDGEDEVICECA-CERTIFICATE}-----END CERTIFICATE-----"
}
}

The following table lists the properties applicable to a connection instance.

FieldDescription
connectorIdMust be set to actility-azure-iot-edge.
configuration/hostNameHost name of the Azure IoT hub (Hostname).
configuration/gatewayHostNameHost name of the IoT Edge gateway (Gateway Host Name).
configuration/deviceIdID of the IoT Edge device (The IoT Edge Device ID).
configuration/sharedAccessKeyPrimary key of the IoT Edge device (Shared access key).
configuration/trustedCaCertificateContent of the CA certificate (CA Certificate).
Important note

All properties are not present in this example. You can check the rest of these properties in the common parameters section.

Displaying Information to Know if It Worked​

To check the connection, view the messages that go through the IoT Edge hub in the verbose logs of the runtime containers. The edgeHub and edgeAgent modules both have a RuntimeLogLevel environment variable, set to info by default. Set it to debug for the edgeHub module in the deployment manifest:

  1. Select your IoT Edge device in your Azure IoT hub, and click the Set modules tab. Set modules of the IoT Edge device
  2. Click the Runtime Settings tab, and select the Edge Hub tab in the right pane. Under Environment Variables, add a variable named RuntimeLogLevel with the value debug. Click Apply. RuntimeLogLevel of the Edge Hub
  3. Click Next: Routes >. Next: Routes
  4. Click Next: Review + create >. Next: Review and create
  5. Connect to the virtual machine with the PublicSSH command recorded at step 9 of Setting Up an IoT Edge Gateway on Azure.
  6. Restart the edgeHub and edgeAgent modules for the changes to take effect:
    sudo iotedge restart edgeAgent && sudo iotedge restart edgeHub
  7. Make a device associated with the connection send an uplink. The edgeHub logs (sudo iotedge logs edgeHub) show that the gateway receives the uplinks from the ThingPark X IoT Flow connection, with entries similar to the following:
     <7> 2024-01-10 13:02:26.555 +00:00 [DBG] [Microsoft.Azure.Devices.Edge.Hub.Core.Routing.RoutingEdgeHub] - Received 1 message(s) from EdgeGateway with message Id(s) [RD.TPX.DEV.Tpx.ConnectionId.4828_0_9778]
    <7> 2024-01-10 13:02:26.556 +00:00 [DBG] [Microsoft.Azure.Devices.Edge.Hub.Amqp.LinkHandlers.EventsLinkHandler] - EventsLinkHandler processed 1 messages for EdgeGateway
    <7> 2024-01-10 13:02:26.556 +00:00 [DBG] [Microsoft.Azure.Devices.Edge.Hub.Core.Storage.MessageStore] - Getting next batch for endpoint iothub starting from 204 with batch size 100.
    <7> 2024-01-10 13:02:26.556 +00:00 [DBG] [Microsoft.Azure.Devices.Edge.Hub.Core.Storage.MessageStore] - Obtained next batch for endpoint iothub with batch size 1. Next start offset = 205.
    <7> 2024-01-10 13:02:26.556 +00:00 [DBG] [Microsoft.Azure.Devices.Edge.Hub.Core.Storage.MessageStore] - Getting next batch for endpoint iothub starting from 205 with batch size 99.
    <7> 2024-01-10 13:02:26.556 +00:00 [DBG] [Microsoft.Azure.Devices.Edge.Hub.Core.Storage.MessageStore] - Obtained next batch for endpoint iothub with batch size 0. Next start offset = 205.
    <7> 2024-01-10 13:02:26.556 +00:00 [DBG] [Microsoft.Azure.Devices.Edge.Hub.Core.Routing.CloudEndpoint] - Sending 1 message(s) upstream.
    <7> 2024-01-10 13:02:26.556 +00:00 [DBG] [Microsoft.Azure.Devices.Edge.Hub.Core.Routing.CloudEndpoint] - Sending 1 message(s) upstream, divided into 1 groups. Processing maximum 10 groups in parallel.
    <7> 2024-01-10 13:02:26.556 +00:00 [DBG] [Microsoft.Azure.Devices.Edge.Hub.Core.ConnectionManager] - Obtained cloud connection for device EdgeGateway
    <7> 2024-01-10 13:02:26.557 +00:00 [DBG] [Microsoft.Azure.Devices.Edge.Hub.Core.Routing.CloudEndpoint] - Finished processing messages to upstream
    <7> 2024-01-10 13:02:26.577 +00:00 [DBG] [Microsoft.Azure.Devices.Edge.Hub.CloudProxy.DeviceConnectivityManager] - IotHub call succeeded
    <7> 2024-01-10 13:02:26.577 +00:00 [DBG] [Microsoft.Azure.Devices.Edge.Hub.CloudProxy.ConnectivityAwareClient] - Operation SendEventAsync succeeded for EdgeGateway
    <7> 2024-01-10 13:02:26.577 +00:00 [DBG] [Microsoft.Azure.Devices.Edge.Hub.CloudProxy.CloudProxy] - Sending message for EdgeGateway

Limitations​

There are currently no known limitations to the Azure IoT Edge connector.

Troubleshooting​

  • The connection is not OPENED: check the hostname, the gateway host name, the IoT Edge device ID and the shared access key, and that the gateway is reachable from the internet on the ports opened at step 10 of Setting Up an IoT Edge Gateway on Azure. The Events section of the connection details gives the error.
  • Connectivity issues of the gateway: run sudo iotedge check on the virtual machine (step 15).