Skip to main content

Add an IoT Edge Device on Ubuntu

Prerequisites

Before you begin, you need:

  1. Create an IoT Edge device in the Device Visibility section.

  2. Go to the Device Overview page. Here, you can find the Serial Number and the other required parameters clicking on the Get Credentials button.

Network Requirements

To ensure proper communication between your IoT Edge device and Datalogic Connect services, make sure the following network endpoints are accessible:

EndpointPortProtocolNotes
*.azure-devices.net8883, 443MQTT, HTTPSSend diagnostic data, receive cloud commands
global.azure-devices-provisioning.net443HTTPSDevice provisioning
*.blob.core.windows.net443HTTPSFile upload, Docker image pull
crsolinfraprodeuw.azurecr.io443HTTPSContainer registry
crsolinfraprodeuw.westeurope.data.azurecr.io443HTTPSContainer registry
*.azureiotcentral.com443HTTPSDevice Smart Enrollment
Firewall Configuration

If your device is behind a corporate firewall, ensure these endpoints are whitelisted to allow proper IoT Edge functionality.

Add an IoT Edge Device on Ubuntu 22.04

  1. Install IoT Edge:
    • Installing can be done with a few commands. Open a terminal and run the following commands:
       wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
      sudo dpkg -i packages-microsoft-prod.deb
      rm packages-microsoft-prod.deb
  2. Install a container engine:
    • On the Ubuntu device, open the terminal.
    • Install the IoT Edge runtime by running the following commands:
       sudo apt-get update; \
      sudo apt-get install moby-engine
    • Run the following command to create the daemon.json with the local logging driver and restart the Docker service:
         sudo touch /etc/docker/daemon.json && echo '{ "log-driver": "local" }' | sudo tee /etc/docker/daemon.json | sudo systemctl restart docker

Once these steps are completed, the Docker daemon's logging driver will be set to the local logging driver. You can modify the daemon.json file to configure other Docker settings if needed.

  1. Install the IoT Edge runtime:

    • On the Ubuntu device, open the terminal.

    • Install the IoT Edge runtime by running the following commands:

       sudo apt-get update; \
      sudo apt-get install aziot-edge
      sudo mkdir -p /srv/redis /srv/mosquitto/log /srv/mosquitto/config /srv/mosquitto/config/certs /srv/MqttTranslationModule/log /srv/MqttTranslationModule/certs /srv/DeviceHubModule/log /srv/DeviceHubModule/certs /srv/DeviceHubModule/config /srv/StorageModule/log /srv/StorageModule/config /srv/ProvisioningModule/log /srv/ProvisioningModule/config /tmp/edgeAgent /tmp/edgeHub /srv/shared/download /srv/shared/certs /srv/shared/certs/server /srv/otel
      sudo chown 1000 /srv/redis /srv/mosquitto/log /srv/mosquitto/config /srv/mosquitto/config/certs /srv/MqttTranslationModule/log /srv/MqttTranslationModule/certs /srv/DeviceHubModule/log /srv/DeviceHubModule/certs /srv/DeviceHubModule/config /srv/StorageModule/log /srv/StorageModule/config /srv/ProvisioningModule/log /srv/ProvisioningModule/config /srv/shared/download /srv/otel
      sudo chown 1001 /srv/shared/certs /srv/shared/certs/server
      sudo chmod 755 /srv/shared/certs /srv/shared/certs/server
  2. Configure Mosquitto MQTT Broker:

    • Create the mosquitto configuration file by running the following command:

       sudo nano /srv/mosquitto/config/mosquitto.conf
    • Paste the following configuration:

      mosquitto.conf
      per_listener_settings true

      listener 1883
      protocol mqtt
      allow_anonymous true
      require_certificate false
      listener 9883
      protocol mqtt
      cafile /mosquitto/config/certs/bundle-ca.crt
      certfile /mosquitto/config/certs/server/server.crt
      keyfile /mosquitto/config/certs/server/server.key
      require_certificate true
      allow_anonymous true

    This configuration sets up two MQTT listeners:

    • Port 1883: Standard MQTT without TLS for local/development connections
    • Port 9883: Secure MQTT with mutual TLS (mTLS) for production use
  3. Configure Storage Module:

    • Create the storage module configuration by running the following command:

       sudo nano /srv/StorageModule/config/config.yaml
    • Paste the following configuration, replacing {SAS_EDGE_STORAGE_KEY} with the value retrieved from the Datalogic Connect in the Sas Edge Storage Key field of the edge device configuration:

      app:
      azure:
      blob-storage-url: { SAS_EDGE_STORAGE_KEY }
  4. Configure Provisioning Module:

    • Create the provisioning module configuration by running the following command:

       sudo nano /srv/ProvisioningModule/config/certificates.yaml
    • Paste the following configuration, replacing the placeholders with your actual values. At least one of the parameters must be replaced and if one is not used, it must be removed from the configuration:

      certificates:
      common-name: ${certificates_common_name:REPLACE_WITH_CERTIFICATES_COMMON_NAME}
      server-ip-address: ${certificates_server_ip_address:REPLACE_WITH_CERTIFICATES_SERVER_IP_ADDRESS}
      • A couple of examples of valid configurations:

        certificates:
        common-name: "my-iot-edge-device"
        certificates:
        server-ip-address: "192.168.1.100"
        certificates:
        common-name: "my-iot-edge-device"
        server-ip-address: "192.168.1.100"
  5. Configure Open Telemetry Collector:

    • Create the Open Telemetry collector configuration file by running the following command:

       sudo nano /srv/otel/config.yml
    • Paste the following configuration:

      receivers:
      otlp:
      protocols:
      grpc:
      endpoint: 0.0.0.0:4317

      exporters:
      debug:
      verbosity: detailed
      azuremonitor:
      spaneventsenabled: true
      extensions:
      zpages:
      processors:
      filter:
      error_mode: ignore
      logs:
      log_record:
      - "severity_number < SEVERITY_NUMBER_WARN"

      service:
      extensions: [zpages]
      pipelines:
      traces:
      receivers: [otlp]
      exporters: [debug, azuremonitor]
      metrics:
      receivers: [otlp]
      exporters: [debug, azuremonitor]
      logs:
      receivers: [otlp]
      processors: [filter]
      exporters: [debug, azuremonitor]
  6. Configure IoT Edge:

    • Configure the IoT Edge configuration file by running the following command:

       sudo nano /etc/aziot/config.toml
    • In the provisioning section, set the following parameters:

      [provisioning]
      source = "dps"
      global_endpoint = "https://global.azure-devices-provisioning.net"
      id_scope = "<SCOPE_ID>"

      [provisioning.attestation]
      method = "symmetric_key"
      registration_id = "<SERIAL_NUMBER>"
      symmetric_key = { value = "<PRIMARY_KEY>" }

      [image_garbage_collection]
      enabled = true
      cleanup_recurrence = "1d"
      image_age_cleanup_threshold = "7d"
      cleanup_time = "00:00"

      Make sure to replace <SCOPE_ID>, <SERIAL_NUMBER>, and <PRIMARY_KEY> with the values from your device credentials.

    • Run the following command to apply the configuration changes:

       sudo iotedge config apply

Once these steps are completed, the IoT Edge device should be successfully registered and connected to the Datalogic Connect. You can verify the device's status by running the sudo iotedge list command in the device's terminal.

  1. Update edge configuration on Redis:
    • Run the following command to open redis-cli:

       sudo docker exec -it redis /bin/sh -c 'redis-cli HMSET itmConfig scopeId "<SCOPE_ID>" tenantId "<ORGANIZATION_ID>" modulePrimaryKey "<SAS_DEVICES_KEY>" deviceHubApiKey "<SAS_SMART_ENROLLMENT_KEY>"'
      sudo iotedge system restart
    • Replace the placeholders with your actual values from the device credentials:

      • <SCOPE_ID>: Your Scope ID
      • <ORGANIZATION_ID>: Your Organization ID
      • <SAS_DEVICES_KEY>: Your SAS Devices Key
      • <SAS_SMART_ENROLLMENT_KEY>: Your SAS Smart Enrollment Key

Now the IoT Edge device is successfully connected to the Datalogic Connect and ready to receive and process messages from the leaf devices.