By now you know that the Samsung ARTIK IoT platform provides a range of IoT modules — true systems on module — to power your IoT products, from the entry level 0 series for edge nodes to the high end 7 series for gateways. In addition to working with ARTIK cloud services, ARTIK systems on module work with a variety cloud services. In this tutorial, we’ll talk about running Microsoft Azure IoT Edge on a Samsung ARTIK 530. This tutorial is fairly basic, but we’ll do some deep dives in upcoming posts.
Microsoft Azure IoT Edge is a new product released this year, with 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 globally distributed, multi-model Cosmo 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:
- Direct methods for 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. Direct methods are often used for interactive control of devices such as 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”.
A Device Twin is a JSON document that is used to store and retrieve current state information for an IoT node. 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 the device 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. The Device Twin is a communication bridge between the devices and the Cloud.
The Device Twin JSON document includes Tags, Desired Properties and Reported Properties.
- Cloud-to-device messages provide one-way notifications to the device app. Messages can be retained by IoT Hub for up to 48 hours.
We ported Azure IoT Edge to a Samsung ARTIK 530, which we often use for IoT gateway devices. 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.
Set up Azure IoT Edge on the ARTIK 530
Download the Microsoft IoT Edge SDK from Github and compile on ARTIK 530.
There are several package dependencies you need to install before the compilation. The packages include: CMake, libuuid-devel, OpenSSL-devel, libcurl-devel, glib, libtool.
Set up an Azure IoT account
You need to set up the following services:
- Azure IoT Hub – The core service; enables the communications between devices and cloud.
- Event Hub – An event processing service that enables event and telemetry ingress to the cloud at scale.
- Streaming Job – Data streaming service.
- Service Bus – Cloud-based messaging service providing queues and topics with publish/subscribe semantics and rich features.
You can then create devices with tokens in the IoT Hub.
There is a sample application simulated_device_cloud_upload.c under /root/iot-edge/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.
- Find the json file in /root/iot-edge/samples/simulated_device_cloud_upload/src. Modify the following lines to match your own environment:
- Go to /root/iot-edge/modules/simulated_device/src. Modify simulated_device.c
- Add #include “MQTTAsync.h” to the beginning of the code.
- Locate the function void onConnect(void* context, MQTTAsync_successData* response) and modify the following part accordingly. The purpose is to publish the message from the edge node to the cloud via MQTT.
- Find the file CMakeLists.txt from /root/iot-edge/samples/simulated_device_cloud_upload.
Modify the line set(GCC_COVERAGE_LINK_FLAGS “-lpaho-mqtt3a”) at line 30. We are using Eclipse Paho as the MQTT client to post data to cloud, so this modifies the Paho link library when compiling the source code.
- Under /root/iot-edge/tools, run ./build.sh –disable-native-remote-modules
- Copy the previously modified json file to /root/iot-edge/build/samples/simulated_device_cloud_upload/
- Under /root/iot-edge/ folder, edit the json file and assign your IoT Hub Name to IoTHubName, “azure-devices.net” to IoTHubSuffix, and “MQTT” to Transport.
- 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!
That’s it for part one. Stay tuned for more detailed tutorials coming soon.