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
(Verifying the transmission of data from the edge device to the cloud)
(Introduction)
Line 18: Line 18:
  
 
==Introduction==
 
==Introduction==
The goal of this document is to show how to deploy modules to a 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 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 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 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 the 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 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'''.
  
The procedure illustrated here is based on [https://docs.microsoft.com/en-us/azure/iot-edge/how-to-deploy-modules-vscode this document].
+
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.
  
 
==Setting up VSC==
 
==Setting up VSC==
Line 32: Line 32:
  
 
After installing this package, the ''Welcome to Azure IoT Tools'' tab should open automatically:
 
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]]
  
 
[[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 we created previously on Azure platform.
+
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 tefer to [https://github.com/Azure/iotedgehubdev this page].
+
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.
 
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 file and the ''Azure IoT Hub Devices'' section in the bottom left corner. 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).
+
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]]
 
[[File:SBCX-VSC-Azure-IoT-Tools2.png|thumb|center|600px|The ''Azure IoT Hub Devices'' section before deploying the ''Simulated Temperature Sensor'' module]]
  
Line 51: Line 48:
  
 
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:
 
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]]
 
[[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==
 
==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:
 
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'']]
 
[[File:SBCX-VSC-Azure-IoT-Tools5.png|thumb|center|600px|The list of the modules after deploying ''SimulatedTemperatureSensor'']]
  
Line 63: Line 56:
  
 
The ''SimulatedTemperatureSensor'' module should appear in the list of the modules on the cloud side as well ...
 
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]]
  
 
[[File:SBCX-Azure-IoT-hub2.png|thumb|center|600px|The ''SimulatedTemperatureSensor'' module appears on the cloud side]]
 
  
  
Line 73: Line 65:
  
  
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 by clicking the ''Start Monitoring Built-in Event Endpoint'' item in the drop-down menu associated with the <code>sbcx</code> device:
+
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]]
 
[[File:SBCX-VSC-Azure-IoT-Tools6.png|thumb|center|600px|Messages associated with data generated by the ''Simulated Temperature Sensor'' module]]
  

Revision as of 09:04, 20 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 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.

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"}]