Difference between revisions of "SBCX-TN-003: Deploying modules to Azure IoT Edge-enabled SBCX with Visual Studio Code"

From DAVE Developer's Wiki
Jump to: navigation, search
(Introduction)
(22 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
{{InfoBoxTop}}
 
{{InfoBoxTop}}
 +
{{AppliesToSBCX}}
 
{{AppliesToAxel}}
 
{{AppliesToAxel}}
 +
{{AppliesToAxelLite}}
 
{{AppliesToAxelEsatta}}
 
{{AppliesToAxelEsatta}}
{{AppliesToAxelLite}}
 
{{AppliesToAXEL Lite TN}}
 
{{AppliesToSMARX TN}}
 
{{AppliesToSBCX}}
 
{{AppliesToSBC Axel TN}}
 
{{AppliesToVisualStudioCode}}
 
{{AppliesTo VisualStudioCode TN}}
 
{{AppliesToIoT}}
 
{{AppliesTo IoT TN}}
 
 
{{InfoBoxBottom}}
 
{{InfoBoxBottom}}
 
{{WarningMessage|text=This technical note was validated against specific versions of hardware and software. It may not work with other versions.}}
 
{{WarningMessage|text=This technical note was validated against specific versions of hardware and software. It may not work with other versions.}}
Line 25: Line 18:
  
 
==Introduction==
 
==Introduction==
The goal of this document is to show how to deploy modules to an Azure IoT Edge-enabled [[:Category:SBC-AXEL|SBC Axel board]]. It is recalled that, [https://docs.microsoft.com/en-us/azure/marketplace/iot-edge-module according to Microsoft documentation], modules are  
+
The goal of this document is to show how to deploy modules to a Azure IoT Edge-enabled SBCX board. It is recalled that, [https://docs.microsoft.com/en-us/azure/marketplace/iot-edge-module 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''.
 
''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 [https://code.visualstudio.com/ Visual Studio Code (VSC)] to carry out such an operation on the SBCX single-board computer.
+
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 [https://code.visualstudio.com/ Visual Studio Code (VSC)] to carry out such an operation on SBCX single-board computer.
  
This article is based on this previous TN: [[SBCX-TN-002:_Running_Microsoft_Azure_IoT_Edge_runtime|''SBCX-TN-002: Running Microsoft Azure IoT Edge runtime'']]. As such, '''SBCX-TN-002 is a prerequisite to complete this TN'''.
+
This Technical Note (TN for short) is based on this previous TN: [[SBCX-TN-002:_Running_Microsoft_Azure_IoT_Edge_runtime|''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 [https://docs.microsoft.com/en-us/azure/iot-edge/how-to-deploy-modules-vscode this document], whose reading is highly recommended.
 
 
 
For more detailed information about Azure IoT Edge modules, please see [https://docs.microsoft.com/en-us/azure/iot-edge/iot-edge-modules this page].
 
  
 
==Setting up VSC==
 
==Setting up VSC==
To set up Visual Studio Code, the [https://marketplace.visualstudio.com/items?itemName=vsciot-vscode.azure-iot-tools&ssr=false#overview ''Azure IoT Tools extension package''] has to be installed.
+
To set up Visual Studio Code, the [https://marketplace.visualstudio.com/items?itemName=vsciot-vscode.azure-iot-tools&ssr=false#overview Azure IoT Tools extension package] has to be installed.
  
After installing this package, the ''Welcome to Azure IoT Tools'' tab should open automatically:
 
[[File:SBCX-VSC-Azure-IoT-Tools1.png|thumb|center|600px|''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 [https://github.com/Azure/iotedgehubdev this page].
 
 
==Deploying a simple module==
 
==Deploying a simple module==
Following the example illustrated [https://docs.microsoft.com/en-us/azure/iot-edge/how-to-deploy-modules-vscode here], the first step is to create a <code>deployment.json</code> file. In this case, the [https://azuremarketplace.microsoft.com/en-us/marketplace/apps/microsoft.edge-simulated-temperature-sensor-ga ''Simulated Temperature Sensor'' module] will be deployed to the edge device.
 
 
The following picture shows the <code>deployment.json</code> 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—<code>sbcx</code> in the example—and their running modules—<code>edgeAgent</code> and <code>edgeHub</code> in the example.
 
[[File:SBCX-VSC-Azure-IoT-Tools2.png|thumb|center|600px|The ''Azure IoT Hub Devices'' section before deploying the ''Simulated Temperature Sensor'' module]]
 
 
 
 
By right-clicking on the <code>sbcx</code> 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:
 
[[File:SBCX-VSC-Azure-IoT-Tools3.png|thumb|center|600px|The output console during the deployment process]]
 
==Verifying the transmission of data from the edge device to the cloud==
 
After refreshing the lists of the modules associated with the <code>sbcx</code> device, a new module named ''SimulatedTemperatureSensor'' should appear:
 
[[File:SBCX-VSC-Azure-IoT-Tools5.png|thumb|center|600px|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 ...
 
[[File:SBCX-Azure-IoT-hub2.png|thumb|center|600px|The ''SimulatedTemperatureSensor'' module appears on the cloud side]]
 
 
 
 
... and its status should be ''Connected'':
 
[[File:SBCX-Azure-IoT-hub3.png|thumb|center|600px|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 <code>sbcx</code> device:
 
[[File:SBCX-VSC-Azure-IoT-Tools6.png|thumb|center|600px|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:
 
<pre class="board-terminal">
 
[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"
 
  }
 
}
 
</pre>
 
 
 
The transmission of data can be verified on the edge device too by issuing the following command:
 
<pre class="board-terminal">
 
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"}]
 
 
</pre>
 
 
==What's under the hood==
 
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:
 
<pre class="board-terminal">
 
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
 
</pre>
 
 
 
Similarly, one can use <code>docker</code> command line to verify that the ''Simulated Temperature Sensor'' module is listed among running containers:
 
<pre class="board-terminal">
 
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
 
</pre>
 
 
 
The same information can be retrieved by using <code>iotedge</code> command line:
 
<pre class="board-terminal">
 
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
 
</pre>
 
 
 
It is also interesting to list the processes running inside the <code>azureiotedge-simulated-temperature-sensor</code> container:
 
<pre class="board-terminal">
 
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
 
</pre>
 
 
The <code>/usr/bin/dotnet</code> file is an ARM executable ...
 
<pre class="board-terminal">
 
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
 
</pre>
 
 
... while <code>SimulatedTemperatureSensor.dll</code> is a [https://en.wikipedia.org/wiki/Portable_Executable Portable Executable] file:
 
<pre class="board-terminal">
 
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
 
</pre>
 
 
 
 
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 [https://github.com/Warlib1975/azureiotedge-simulated-temperature-sensor here], however.
 

Revision as of 15:53, 19 August 2019

Info Box
SBC-AXEL-02.png Applies to SBC AXEL
Axel-04.png Applies to Axel Ultra
Axel-lite 02.png Applies to Axel Lite
Axel-02.png Applies to AXEL ESATTA
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 a Azure IoT Edge-enabled SBCX 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 SBCX single-board computer.

This Technical Note (TN for short) 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.

Setting up VSC[edit | edit source]

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

Deploying a simple module[edit | edit source]