Filter results by

Microsoft Azure IoT Edge

The Microsoft Azure platform provides a message mirroring system to stay synchronized – from edge device to gateway to cloud.

Microsoft Azure IoT Edge comprises infrastructure and tools for IoT Gateway solutions. It provides easy orchestration between code and services, so they flow securely between cloud and edge to distribute intelligence across IoT devices. For connectivity, Azure IoT Edge supports MQTT/HTTP/AMQP protocols for communication between edge nodes and gateways, as well as from gateways to the cloud. It uses the globally distributed, multi-model Cosmos DB.

Azure IoT Hub is the core part of the Azure Cloud service. The Hub connects, monitors and manages all of the IoT assets. It is a fully managed service that enables reliable and secure bi-directional communications between millions of devices and a solution back end.

The IoT Hub provides three options for device applications to expose functionality to a back-end app:

Method Usage

Communications that require immediate confirmation of the result. This is a two-way method. The device app can respond to the method right away. The solution back end receives the outcome contextually to the request. Used for interactive device control, like turning on/off a light.
Twin’s desired properties For long-running commands intended to put the device into a certain desired state – for example, “set the telemetry send interval to 30 minutes”.
Cloud-to-device messages Provide one-way notifications to the device app. Messages can be retained by the IoT Hub for up to 48 hours.

Device Twin – a JSON document used to store and retrieve current state information for an IoT node. It includes Tags, Desired Properties and Reported Properties. The Device Twin acts as a communication bridge between devices and the Cloud.

For each new device, the IoT Hub creates a Device Twin and uses it to maintain a persistent state of the device regardless of whether it is connected to the Internet or not. Property values are preserved in the device twin, and the device reads it the next time it connects. Property values are retrievable with the IoT Hub query language.


We ported Azure IoT Edge to a Samsung ARTIK 530 IoT gateway device. The following example shows how to collect the temperature data from an edge node based on an ARTIK 053 and send it to ARTIK 530 running Azure IoT Edge via MQTT. The ARTIK 530 processes the data and sends aggregated data to the Cloud.

In this tutorial, we will adapt existing sample code provided by IoT Edge SDK for data transfer.

Setting up cloud services

In addition to the IoT Hub services you set up in the initial article, you'll also want to set up the services that deal with message delivery. Microsoft provides a good overview of the choices.

  • Event Hub -– An event processing service that enables event and telemetry ingress to the cloud at scale.

  • Stream Analytics Job -– Data streaming service.

  • Service Bus –- Cloud-based messaging service providing queues and topics with publish/subscribe semantics and rich features.

Setting Up Azure IoT Edge

Download the Microsoft IoT Edge SDK from Github, install dependencies, and compile directly on the ARTIK gateway module.

Set up swap file

The build procedure is memory-intensive; you will exhaust the memory of the ARTIK module unless you have set up swap memory beforehand. To do so, follow this one-time procedure. In general, SWAP memory size should not be more than twice the size of available RAM.

  1. Allocate file space of 512KB.
    fallocate -l 512m /mnt/512MiB.swap
  2. Prevent users from reading the swap file contents.
    chmod 600 /mnt/512MiB.swap
  3. Format the file just created as a swapping device.
    mkswap /mnt/512MiB.swap
  4. Add the swap to the running system.
    swapon /mnt/512MiB.swap
  5. Use a text editor to open the file shown for editing.
    vi /etc/fstab
  6. To enable the swap memory on every boot, add this line to the end of /etc/fstab (which you may need to create).
    /mnt/512MiB.swap none swap sw 0 0
  7. Save and exit, then

The board will now use the flash-based swap file as needed for extending available RAM.

Install dependencies

apt update
apt install git
apt install build-essential
apt install cmake
apt install uuid-dev
apt install libssl-dev
apt install curl libcurl4-openssl-dev
apt install libglib2.0-dev

Clone Azure IoT Edge

You can clone IoT Edge wherever you prefer; we've picked azure for our examples.

mkdir azure
cd azure

apt install git

git clone


The compilation may take ~10 minutes.

cd ~/azure/iot-edge-v1/v1

cmake .

Create and build the application

There is a sample application, simulated_device_cloud_upload.c under samples/simulated_device_cloud_upload/src, which sends the simulated sensor data from the gateway to Azure cloud. We used this application as the template and used an ARTIK053 as the edge node to send real-time sensor data to the ARTIK 530 gateway. Every 10 seconds, ARTIK pushes telemetry data to Azure Cloud.

The directories noted are under your main installation directory
(such as /root/azure/iot-edge-v1/v1/).

  1. Set your deviceId and deviceKey.
    1. Go to the subdirectory noted.
      cd v1/samples/simulated_device_cloud_upload/src

    2. Find the Linux json file and modify the following lines to match your own environment.

  2. We want to publish messages from the edge node to the cloud via MQTT.
    1. Go to the subdirectory noted.
      cd v1/modules/simulated_device/src

    2. To the file simulated_device.c
      • Add #include “MQTTAsync.h” to the beginning of the code.

      • Locate the function
        onConnect(void* context, MQTTAsync_successData* response)
        and modify the following part accordingly.

    3. Go to the subdirectory noted.
      cd v1/samples/simulated_device_cloud_upload/

    4. Find the file CMakeLists.txt and modify line 30 to
      set(GCC_COVERAGE_LINK_FLAGS “-lpaho-mqtt3a”)
      We are using Eclipse Paho as the MQTT client to post data to the cloud, so this modifies the Paho link library when compiling the source code.
  3. Build the application.

    1. Go to the subdirectory noted.
      cd v1/tools/

    2. Run
      ./ –disable-native-remote-modules

  4. Update the build files with your ID and key information.

    1. Go to the subdirectory noted.
      cd v1/build/samples/simulated_device_cloud_upload/

    2. Copy the previously modified json file this directory.

Run the application

  1. Run the application.

    1. Go back to the main installation directory.
      cd v1/

    2. Edit the json file and assign your IoT Hub Name to IoTHubName, “” to IoTHubSuffix, and “MQTT” to Transport.

    3. Run ./ simulated_device_cloud_upload ./config.json

You will see the MESSAGE number from the dashboard change.

Click on the Streaming Job part of the dashboard and run the Test program from the menu, and you will hopefully see that the temperature data has come in!

Last updated on: