SBCX-TN-003: Deploying modules to Azure IoT Edge-enabled SBCX with Visual Studio Code

From DAVE Developer's Wiki
Jump to: navigation, search
Info Box
Axel-04.png Applies to Axel Ultra
Axel-02.png Applies to AXEL ESATTA
Axel-lite 02.png Applies to Axel Lite
SBC-AXEL-02.png Applies to SBC AXEL
1200px-Visual Studio Code 1.35 icon.svg.png Applies to Visual Studio Code
Cloud-computing-banner.jpg Applies to IoT
Warning-icon.png This technical note was validated against specific versions of hardware and software. It may not work with other versions. Warning-icon.png

History[edit | edit source]

Version Date Notes
1.0.0 August 2019 First public release

Introduction[edit | edit source]

The goal of this document is to show how to deploy modules to an Azure IoT Edge-enabled SBC Axel board. It is recalled that, according to Microsoft documentation, modules are

the smallest computation units managed by IoT Edge, and can contain Microsoft services (such as Azure Stream Analytics), 3rd-party services or your own solution-specific code.

There are different methods to deploy such modules to the IoT Edge-enabled devices. This Technical Note (TN for short) will describe how to use Visual Studio Code (VSC) to carry out such an operation on the SBCX single-board computer.

This article is based on this previous TN: SBCX-TN-002: Running Microsoft Azure IoT Edge runtime. As such, SBCX-TN-002 is a prerequisite to complete this TN.

The procedure illustrated here is based on this document, whose reading is highly recommended.

For more detailed information about Azure IoT Edge modules, please see this page.

Setting up VSC[edit | edit source]

To set up Visual Studio Code, the Azure IoT Tools extension package has to be installed.

After installing this package, the Welcome to Azure IoT Tools tab should open automatically:

Welcome to Azure IoT Tools tab


This tab is extremely convenient to establish the connection between VSC and the IoT hub the we created previously on the Azure platform.

After installing the Azure IoT Tools extension package, VSC suggests to install the iotedgehubdev as well. Although it is not necessary, this package may be useful for debugging tasks. For more details, please refer to this page.

Deploying a simple module[edit | edit source]

Following the example illustrated here, the first step is to create a deployment.json file. In this case, the Simulated Temperature Sensor module will be deployed to the edge device.

The following picture shows the deployment.json file and the Azure IoT Hub Devices section in the bottom left corner of VSC window. This section in turn lists the connected edge devices—sbcx in the example—and their running modules—edgeAgent and edgeHub in the example.

The Azure IoT Hub Devices section before deploying the Simulated Temperature Sensor module


By right-clicking on the sbcx device, the Create Deployment for Single Device item can be selected. This action starts the deployment process. At the end of this process, the Deployment succeeded message should appear on the output console:

The output console during the deployment process

Verifying the transmission of data from the edge device to the cloud[edit | edit source]

After refreshing the lists of the modules associated with the sbcx device, a new module named SimulatedTemperatureSensor should appear:

The list of the modules after deploying SimulatedTemperatureSensor


The SimulatedTemperatureSensor module should appear in the list of the modules on the cloud side as well ...

The SimulatedTemperatureSensor module appears on the cloud side


... and its status should be Connected:

The SimulatedTemperatureSensor module is properly connected to the IoT Hub


There are different ways to verify that the Simulated Temperature Sensor module is sending data to the cloud. In VSC, it is possible to monitor the data stream by clicking the Start Monitoring Built-in Event Endpoint item in the drop-down menu associated with the sbcx device:

Messages associated with data generated by the Simulated Temperature Sensor module


In the output console, the messages relating to the transmission of such data will be visible:

[IoTHubMonitor] [5:16:56 PM] Message received from [sbcx/SimulatedTemperatureSensor]:
{
  "body": {
    "machine": {
      "temperature": 100.66939129711574,
      "pressure": 10.076259768025844
    },
    "ambient": {
      "temperature": 20.67014677551116,
      "humidity": 24
    },
    "timeCreated": "2019-08-19T15:16:56.5401594Z"
  },
  "applicationProperties": {
    "sequenceNumber": "184",
    "batchId": "39f619d0-72ff-4c1f-9474-294158b70db2"
  }
}


The transmission of data can be verified on the edge device too by issuing the following command:

armbian@sbcx:~$ sudo iotedge logs SimulatedTemperatureSensor -f
[2019-08-19 15:00:52 +00:00]: Starting Module
SimulatedTemperatureSensor Main() started.
Initializing simulated temperature sensor to send 500 messages, at an interval of 5 seconds.
To change this, set the environment variable MessageCount to the number of messages that should be sent (set it to -1 to send unlimited messages).
Information: Trying to initialize module client using transport type [Amqp_Tcp_Only].
Information: Successfully initialized module client of transport type [Amqp_Tcp_Only].
        08/19/2019 15:01:32> Sending message: 1, Body: [{"machine":{"temperature":20.830871543186191,"pressure":0.9807322011224775},"a
mbient":{"temperature":20.538326477649775,"humidity":26},"timeCreated":"2019-08-19T15:01:31.9148845Z"}]
        08/19/2019 15:01:38> Sending message: 2, Body: [{"machine":{"temperature":21.013124713447468,"pressure":1.0014952205193317},"a
mbient":{"temperature":21.149835604079922,"humidity":26},"timeCreated":"2019-08-19T15:01:38.1592817Z"}]
        08/19/2019 15:01:43> Sending message: 3, Body: [{"machine":{"temperature":22.038820587465921,"pressure":1.1183466492049783},"a
mbient":{"temperature":21.027865147929575,"humidity":25},"timeCreated":"2019-08-19T15:01:43.206327Z"}]

What's under the hood[edit | edit source]

For readers interested in the technologies underlying the Azure IoT Edge solution, it is worth remembering that modules are implemented as Docker containers. After deploying the Simulated Temperature Sensor module, for instance, it is easy to verify that a new container image is installed on the edge device:

armbian@sbcx:~$ sudo docker image ls
REPOSITORY                                                    TAG                 IMAGE ID            CREATED             SIZE
mcr.microsoft.com/azureiotedge-simulated-temperature-sensor   1.0                 a626b1a36236        4 weeks ago         200MB
mcr.microsoft.com/azureiotedge-hub                            1.0                 3a84bfb86c7d        4 weeks ago         252MB
mcr.microsoft.com/azureiotedge-agent                          1.0                 58276103181c        4 weeks ago         238MB
mcr.microsoft.com/azureiotedge-diagnostics                    1.0.8               a480fa622e2a        4 weeks ago         7.34MB


Similarly, one can use docker command line to verify that the Simulated Temperature Sensor module is listed among running containers:

armbian@sbcx:~$ sudo docker container ls
CONTAINER ID        IMAGE                                                             COMMAND                   CREATED             STATUS              PORTS                         NAMES
145db7780bec        mcr.microsoft.com/azureiotedge-simulated-temperature-sensor:1.0   "/bin/sh -c 'echo \"$…"   18 hours ago        Up 17 hours                                       SimulatedTemperatureSensor
200e8563544f        mcr.microsoft.com/azureiotedge-hub:1.0                            "/bin/sh -c 'echo \"$…"   18 hours ago        Up 17 hours         443/tcp, 5671/tcp, 8883/tcp   edgeHub
da40f11b4c33        mcr.microsoft.com/azureiotedge-agent:1.0                          "/bin/sh -c 'echo \"$…"   10 days ago         Up 17 hours                                       edgeAgent


The same information can be retrieved by using iotedge command line:

armbian@sbcx:~$ sudo iotedge list
NAME                        STATUS           DESCRIPTION      CONFIG
edgeHub                     running          Up 17 hours      mcr.microsoft.com/azureiotedge-hub:1.0
SimulatedTemperatureSensor  running          Up 17 hours      mcr.microsoft.com/azureiotedge-simulated-temperature-sensor:1.0
edgeAgent                   running          Up 17 hours      mcr.microsoft.com/azureiotedge-agent:1.0


It is also interesting to list the processes running inside the azureiotedge-simulated-temperature-sensor container:

root@sbcx:~# docker container top 145db7780bec
UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
armbian             2612                2586                0                   10:24               ?                   00:00:20            /usr/bin/dotnet SimulatedTemperatureSensor.dll

The /usr/bin/dotnet file is an ARM executable ...

root@sbcx:/var/lib/docker/overlay2/b4cc9541e8175bae26aa42952490a0b2fcdd5895bfe18f8092b58c27531259b6/merged/usr/share/dotnet# file dotnet
dotnet: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 2.6.32, BuildID[sha1]=ef6dc8332270899ce1c7de629bdbcc95168fc710, stripped

... while SimulatedTemperatureSensor.dll is a Portable Executable file:

root@sbcx:/var/lib/docker/overlay2/b4cc9541e8175bae26aa42952490a0b2fcdd5895bfe18f8092b58c27531259b6# file merged/app/SimulatedTemperatureSensor.dll
merged/app/SimulatedTemperatureSensor.dll: PE32 executable (console) Intel 80386 Mono/.Net assembly, for MS Windows


Unfortunately, at the time of this writing, the official source code of the Simulated Temperature Sensor module was not available. The original repository was cloned here, however.