When it comes to the Internet of Things (IoT), the cloud plays a major role in allowing developers to distribute computing between edge devices and remote digital services. This architecture opens up the potential for a multitude of solutions where devices and cloud services work in concert over today's high-speed communication channels using efficient protocols. Of course, supporting all of this requires strong two-way communications right from the physical layer up to the application layer.
In this blog we'll briefly review the common transport and application-layer protocols that help facilitate IoT communications, and then look at how you can get IoT devices based on Qualcomm® technologies to communicate with Microsoft Azure and AWS IoT.
A Protocol for IoT Connectivity
No matter how sophisticated edge-to-cloud IoT communications get, at the end of the day it all comes down to two-way data communications over the Internet between a device and a remote service.
Starting at the transport layer, device-to-cloud communications generally take place over TCP (Transmission Control Protocol) or UDP (User Datagram Protocol) channels. TCP is connection-oriented and reliable, meaning that every data packet sent requires acknowledgement that it was received. But with great reliability comes great overhead, and sometimes for an IoT application, the TCP header can be larger than the payload itself. UDP on the other hand, is connectionless and unreliable, meaning that it allows for the loss of data packets in the interest of speed. TCP is used where data must get through whereas UDP is employed where some data loss is acceptable (e.g., when streaming videos).
At the application layer, HTTP (HyperText Transfer Protocol) has become one of the most standardized protocols for web-based communications. It was developed as a request-response model from the client-server era where clients (e.g. browsers), open a TCP connection to send requests to servers (e.g. web servers) that return responses. TLS is often employed to secure HTTP communication over TCP, while DTLS performs similarly functionality over UDP. This setup can be used by IoT devices to communicate with the web servers using a RESTful/SOAP web service. For example, devices can talk to the server over a TCP/IP connection using HTTP GET/POST methods, and deliver the payloads formatted in XML, JSON, or some other format. Each step (TCP/IP, HTTP, XML/JSON) keeps adding overhead to the payload, which is the only relevant information that the end application is looking for. Hence, another application-layer protocol, MQTT (Message Queuing Telemetry Transport), has become popular for IoT. It's a lightweight protocol with a small code footprint suitable for constrained environments such as embedded IoT devices. Most notably, it works on a publish-subscribe model that facilitates one-to-many communications between devices through a central MQTT "broker"–just the type of communications you would typically need for IoT!
With an understanding of these underlying protocols, lets now look at how edge-to-cloud communications work. We'll look at how to accomplish this, using devices based on the Qualcomm® MDM9206 LTE Modem and those based on the Qualcomm® Snapdragon™ mobile platforms.
Connecting IoT devices with a Qualcomm MDM9206 LTE Modem to Azure
The Qualcomm MDM9206 can run Linux and ThreadX, and is a fairly specialized device that is often used as a modem in conjunction with another processor.
To facilitate communications, QTI provides the Qualcomm® LTE for IoT SDK which supports many protocols including TLS, DTLS, MQTT, and HTTP. The LTE for IoT SDK also provides a shim layer for connecting to Azure IoT Hub using their azure-iot-sdk-c package.
This shim layer includes Azure input/output (I/O) and platform shim layer libraries as part of a package for Azure application development on the Qualcomm® ThreadX platform in the user space. Azure applications use Microsoft Azure SDK-defined APIs to interact with the Azure IoT SDK C module. The Azure IoT SDK C module uses the adapter layer to interact with the Qualcomm ThreadX IoT stack. The figure below shows the Azure application architecture on a ThreadX IoT device:
This shim layer also includes a number of scripts which automatically set up a build environment to build an application for your device.
The SDK is currently available via the Qualcomm CreatePoint site. To get the SDK package, create an account on the site. Once approved, search the site's downloads section for the Qualcomm MDM920x Thread X Cellular IoT SDK and download the package. Note that before using this SDK, you'll need to download the azure-iot-sdk-c package.
Connecting IoT devices with the Qualcomm MDM9206 LTE Modem to AWS IoT
The key steps involved for connecting your device to AWS IoT are:
- Create an EC2 instance and enable the correct port;
- Add the app to the EC2 instance;
- Obtain the certificate and private key for the app from AWS IoT;
- Build the device-side application and transfer it along with the certificate and private key, and any other supporting files to the device;
- Set up the sensor map with the device to track product inventory levels;
- Launch a browser and navigate to your AWS IoT app; and
- Run the application on the device.
If you're interested in learning more, check out the project's sample app module for posting inventory levels to EC2 over MQTT. You can also see how MQTT communication works by taking a look at the aws_iot_mqtt*.c files at: https://github.com/globaledgesoft/merchant-cart-aws-iot/tree/master/sub_pub/src.
Connecting Linux-based IoT Devices Running on Snapdragon platforms to AWS IoT
Snapdragon platforms run more full-featured versions of Linux and thus provide a broad set of capabilities for IoT solutions. They also give developers the ability to integrate higher-level SDKs and libraries written in a variety of programming languages.
Communication between a Snapdragon-based device and AWS IoT using MQTT, can be accomplished with one of the AWS IoT SDKs (e.g. AWS IoT Device SDK for Python). You can see in this in our project: Four Steps to AWS IoT, which shows connecting a DragonBoard™ 410c (the Snapdragon hardware developer kit from Arrow Electronics) using AWS IoT SDK for Python.
The key steps involved with connecting to AWS IoT are:
- Create a project in AWS;
- Create a "thing"
- Connect the "thing" to a device
- Select a programming language
- Generate a certificate and policy and add them to the project
- Install the required SDK's for AWS IoT on the client/device;
- Create the device-side application with the following implementation:
- Add the AWS module to the client code.
- Instantiate a client in code passing the private key and certificate.
- Start a connection.
- Subscribe to a topic and specify a callback to receive information back.
- Publish messages as required by your app.
Device-to-cloud communication working over standard OSI-model protocols provides the backbone for cloud services. IoT-device-to-cloud connectivity can be achieved on specialized devices such as the Qualcomm MDM9206 LTE Modem, using an appropriate device-level SDK like the Qualcomm LTE for IoT SDK. Devices with broader levels of functionality provided by the OS such as Snapdragon platforms and Linux, can incorporate high-level solutions (e.g., SDKs) provided by cloud service providers.
More generally, this device-to-cloud architecture provides a rich set of options for processing on IoT devices and/or the cloud. So now that you know how to get your IoT devices talking to the cloud, what will your next IoT solution look like?
1. If you need a refresher on the seven communication layers, check out: https://en.wikipedia.org/wiki/OSI_model.
Qualcomm Snapdragon, Qualcomm MDM9206 and Qualcomm LTE for IoT SDK are products of Qualcomm Technologies, Inc. and/or its subsidiaries.