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
(Deploying a simple module)
Line 68: Line 68:
  
  
In the output console, the messages relating to the transmission of such data will be visible.
+
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>
  
Another method to
+
 
 +
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>

Revision as of 08:47, 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 a 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 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.

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 we created previously on 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 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 file and the Azure IoT Hub Devices section in the bottom left corner. 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


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