SlideShare a Scribd company logo
Azure IoT Hub on a Toradex
Colibri VF61 – Part 1:
Sending data to the cloud
|www.toradex.com Toradex® is a registered trademark of Montadex GmbH June’16 2
CHAIRMAN
Introduction
The concept of the Internet of Things is intrinsically related to
the sending of data to the internet and its so called cloud
services. People from the electronics field are everyday more
easily connecting devices to the cloud as the evolution of technology is allowing the
use of smaller and less power-consuming electronics as time goes by. Still there is an
unanswered question for many of these electronics developers: how to make all of the
gathered data useful? Because that is what the Internet of Things is about.
|www.toradex.com Toradex® is a registered trademark of Montadex GmbH June’16 3
CHAIRMAN
There are some examples of real applications taken from the Microsoft website in
order to share a preview of what the IoT can represent: there is an elevator company
using the internet of things to improve and give predictive maintenance; an
automation company using IoT to have insights from the oil and gas industry's
supply chain, along with predictive maintenance; and a company that uses IoT to
predict drivers behaviors and optimize car utilization. By the end of this series of
articles, it is expected that the reader might have enough information and tools ready
to deploy applications that retrieve insights and/or optimize its overall system – not
only an amount of data stacked, but some useful output!
Azure is the Microsoft cloud services platform and it provides an amount of
applications such as databases, virtual machines, app services, machine learning,
data stream analysis, media and CDN services, big data solutions, among many
others, including the IoT Hub.
|www.toradex.com Toradex® is a registered trademark of Montadex GmbH June’16 4
CHAIRMAN
By itself, the vastness of services offered is already a good reason to use the Azure
services, but Microsoft goes one step ahead and compare its services with the
Amazon Web Services to reinforce that their solution is the better – a strong
statement that only users and time will confirm, or the other way around. Among the
reasons to use their services is the security offered, the easiness of integration and
the gentle learning curve.
The main goal of this article is to develop an IoT application, from the reading of field
sensors to the presentation of results and the retrieving of business intelligence. The
hardware used to collect the sensors data and send it to the cloud is: a Toradex Colibri
VF61 SoM + the Iris Carrier Board, since Toradex is an Azure IoT certified partner. .
This is, therefore, an advantage, once Toradex is an Azure IoT Certified Partner.
|www.toradex.com Toradex® is a registered trademark of Montadex GmbH June’16 5
CHAIRMAN
The application should get some sensors data and send it to an IoT service from the
Microsoft Azure cloud solution, called Azure IoT Hub. Once the data is being received on
the cloud, it can be processed in many ways by other Microsoft Azure services. That is
what will be done in the second part of this article series, but for now the focus will be
on how to configure the Azure IoT Hub and send messages to it.
The chosen IoT environment was the monitoring of a car. For demonstration purposes,
sensors were attached to a remote controlled car, to which a Toradex customized SBC
was also embedded. In the image 1 it is possible to see the picture of the demo and the
image 2 holds a block representation of the aimed application.
|www.toradex.com Toradex® is a registered trademark of Montadex GmbH June’16 6
CHAIRMAN
Image 1: The remote controlled car
|www.toradex.com Toradex® is a registered trademark of Montadex GmbH June’16 7
CHAIRMAN
Image 2: Block diagram of the application
|www.toradex.com Toradex® is a registered trademark of Montadex GmbH June’16 8
CHAIRMAN
The programming language chosen to develop the target application is the
Javascript along with Node.js: a server-side (which in this case is the Toradex
embedded system) Javascript interpreter built on the Chrome's V8 engine. Its
choice was based on the availability of libraries provided by the Azure Iot Hub
SDKs. It should be noticed that the IoT Hub SDKs are under heavy development,
with changes being made every new release (at least for Node), and it should be
taken under consideration. The release version of the Azure IoT Node packages
being used in this article is the version 1.0.1.
The setup of the whole environment, from the programming of the embedded
system to the configuration of Azure in order to receive data was divided in three
steps, described in this article:
|www.toradex.com Toradex® is a registered trademark of Montadex GmbH June’16 9
CHAIRMAN
• Configuration of the Azure environment
• Adding devices and sending messages to the IoT Hub
• Programming the Toradex embedded system application
Configuration of the Azure environment
The first step needed to start developing the whole system is to create an Azure
account: a free account can be created from the Azure website as a 30 day trial. Than
a fixed amount of azure credits can be used to deploy applications that use the Azure
services without charge; also, the IoT Hub has a free version dedicated to
development, with limited resources, also free of charge, even beyond the trial
period. For more details about the pricing and the IoT Hub per se, the IoT Hub page
can be visited.
|www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 10
CHAIRMAN
After setting an Azure account, it is first needed to create an IoT Hub. For that,
the Azure portal should be accessed using the newly created account and the
options +New > Internet of Things > Azure IoT Hub selected. The configuration
screen for the new IoT Hub is shown in image 3. The option "Free" should be
selected in the Pricing and scale tier; a new resource group should be created in
the Resource Group field and the Location selected must match the location of the
other services to be deployed later. Any Name can be chosen and the IoT Hub
Units and Device-to-cloud partitions fields cannot be edited in the free version.
After clicking create, the service will be deployed – and it might take a few
seconds.
|www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 11
|www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 12
CHAIRMAN
That being done, the IoT Hub should appear in the Dashboard, that is, the main
Azure Portal page. After clicking it, a page like in the image 4 should open: there
will be some Essentials information such as the region of the IoT Hub; an Usage
section that gives a feedback to the system administrator regarding how many
messages were sent from devices to this service and the number of registered
devices; and a Monitoring section where the number of messages received over
time are displayed.
Image 3: Creating an IoT Hub from the Azure Portal
|www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 13
CHAIRMAN
|www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 14
CHAIRMAN
Image 4: IoT Hub main panel
Still on the panel from image 4, in order to gain access to the service from other
applications, the Shared access policies option over the Settings tab should be selected.
In the new tab Shared access policies that will open, there will be a policy called
"iothubowner", which has all possible permissions to this IoT Hub and it should be
clicked. The iothubowner tab will open and its Connection string – primary key should
be copied for later usage: it is the key that will allow management and monitoring of
this IoT Hub devices in the next steps. The tabs described in this paragraph to get the
connection string are illustrated in the image 5.
|www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 15
CHAIRMAN
|www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 16
CHAIRMAN
Adding devices and sending messages to the IoT Hub
Now that everything is configured in the cloud, the iothub-exporer tool needs to be
installed on the development machine so that devices can be added to the IoT Hub.
There is another tool named Device Explorer, only available for Windows systems,
so if Windows is being used in the development machine, this option might be
checked out. Since in this article the Ubuntu 14.04 is being used, I will stick to the
iothub-explorer. It should be noted that the Node version running needs to be at
least 0.12.x (it says a version 4.x or higher is needed for all the features to work),
but at the time this article was written, the apt-get tool was currently installing
some 0.10.x version. To solve this issue, the Node Version Manager (NVM) and,
subsequently, the Node version 0.12.9 were installed. From the terminal, the
iothub-explorer can be installed using the NPM (Node Package Manager):
Image 5: Getting the iothubowner connection string
|www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 17
CHAIRMAN
leonardo@leonardo:~$ npm install iothub-explorer@latest
Then the iothub-explorer can be run with the help option to see its usage possibilities:
leonardo@leonardo:~$ iothub-explorer help
As it can be seen in the terminal from the previous command, among the iothub-
explorer options there are create and monitor-events. In order to use this tool, the
connection string acquired in the image 5 must be used. First of all, a device named
"tdx_iot_car" will be created, as in the command below. Note the option –connection-
string that displays the device connection string (not to be confused with the IoT Hub
connection string). It should be copied since it is the key used to connect this newly
created device to the IoT Hub, by enabling the Colibri VF61 application to send
messages to the Hub.
|www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 18
CHAIRMAN
leonardo@leonardo:~$ iothub-explorer "HostName=toradex.azure-
devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=putyoursharedacc
esskeyfromtheconnectionstringhere" create tdx_iot_car --connection-string
Created device tdx_iot_car
-
deviceId: tdx_iot_car
generationId: 635931262207620183
etag: MA==
connectionState: Disconnected
status: enabled
statusReason: null
connectionStateUpdatedTime: 0001-01-01T00:00:00
statusUpdatedTime: 0001-01-01T00:00:00
lastActivityTime: 0001-01-01T00:00:00
cloudToDeviceMessageCount: 0
|www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 19
CHAIRMAN
authentication:
SymmetricKey:
primaryKey: somesharedaccesskeyreturned
secondaryKey: somesecondaryaccesskeyreturned
-
connectionString: HostName=toradex.azure-
devices.net;DeviceId=tdx_iot_car;SharedAccessKey=somesharedaccesskeyreturned
Programming the Toradex embedded system application
Now a Colibri VF61 SoM + Iris Carrier Board should be set. In this article a pre-build
image (Colibri_VF_LinuxConsoleImageV2.5) that can be downloaded here was used.
Instructions on how to flash the image to the Colibri module can be found here. In
order to install the Node.js, the NPM package and git, the following instructions were
issued – be aware that it might take a few minutes to complete, especially the curl
instruction:
|www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 20
CHAIRMAN
The repository where are the packages installer and the node file regarding this
article example – send_data.js – can be cloned into the the board. To clone and install
the node packages, the following commands must be run:
|www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 21
CHAIRMAN
Now the code that sends data to the IoT Hub can be run, but first let's explain some
points about it: it is used the HTTP protocol to provide communication, but the AMQP
and MQTT protocols are also supported; The variable named connectionString value
must be the same string got from a few steps above, while creating the device with the
iothub-explorer:
var connectionString = "HostName=toradex.azure-
devices.net;DeviceId=tdx_iot_car;SharedAccessKey=somesharedaccesske
yreturned"
Inside the setInterval() loop many values are randomly created to be sent to the IoT
Hub as if it were data from some sensors, such as temperature, distance from an
ultrasonic sensor, acceleration and gyro, some gps coordinates and the date/time
from the board.
|www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 22
CHAIRMAN
How to get this data from real sensors will be addressed in the next article from this
series. The JSON.Stringify() function generates a JSON encoded string from the data
and it is encapsulated in a Message object to be sent. Below an example of a a JSON
formatted string is presented:
|www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 23
CHAIRMAN
In case everything goes well, the callback function from the sendEvent() method
should not print anything to the console while the code is running. The following
command runs the Colibri VF61 code and displays the feedback message
continuously printed to the console when all goes right:
|www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 24
CHAIRMAN
As a feedback to guarantee that the data is being received, the IoT Hub section of the
Azure Portal should update the daily message count and the monitoring graph should
present with a spike, as shown in image 6. Note that it might take from a few seconds to
more than a minute until this information gets updated in the portal.
|www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 25
CHAIRMAN
|www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 26
CHAIRMAN
Image 6: Checking in the Azure Portal that data is being received
|www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 27
CHAIRMAN
To see the data stream that is coming into the IoT Hub, the iothub-explorer tool
may be used. To achieve this, the monitor-events option must be used with the
device id. Note that, for this to work, the Colibri VF61 application must be running
at the same time that the iothub-explorer, whereas to see the statistics from the
Azure Portal there is no need for it. The image 7 displays the iothub-explorer
receiving the data while the board was sending it simultaneously. The command to
monitor the events is displayed above, before the image:
leonardo@leonardo:~$ iothub-explorer
"your_iothub_connection_string" monitor-events yourdevice
|www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 28
CHAIRMAN
Image 7: Receiving data from the board into the iothub-explorer
|www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 29
CHAIRMAN
The Microsoft Azure website has plenty of documentation about the Iot Hub as more
information is needed to develop more complex and/or robust applications. There are
things such as creating a device, or getting messages sent from devices to the Hub, that
can be accomplished programatically – refering to the documentation is a good way to
obtain more information on the matter. Also, in the next article the focus will be in
interfacing some sensors to the Colibri VF61 + Iris Carrier Board and than, as real data
is sent to the IoT Hub, it can be used as an input to other Azure services that can
generate insights and/or add some control variables to the deployed application.
|www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 30
CHAIRMAN
I hope it was a helpful introductory article on how to join a Toradex SBC solution with
the Azure IoT Hub service and that you may find it useful! Also, I would like to thank the
Grupo Viceri team from Brazil for their expertise regarding Azure and Business
Intelligence, that led to the partnership that which resulted in the IoT Car project. See
you soon in the next article.
This blog post was originally featured on Embarcados.com in Portuguese. See here.
|www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 31
Thank
you!

More Related Content

PDF
Congatec_Global Vendor for Innovative Embedded Solutions_Ankara
PPTX
PDF
Fraud Detection using Hadoop
PPTX
Go Serverless with Azure Functions
PPTX
SQLSaturday #230 - Introduction to Microsoft Big Data (Part 1)
PPTX
Azure api app métricas com application insights
PPTX
Belgian Windows Server 2012 Launch windows azure insights for the enterprise ...
PPTX
Microsoft NYC 14
Congatec_Global Vendor for Innovative Embedded Solutions_Ankara
Fraud Detection using Hadoop
Go Serverless with Azure Functions
SQLSaturday #230 - Introduction to Microsoft Big Data (Part 1)
Azure api app métricas com application insights
Belgian Windows Server 2012 Launch windows azure insights for the enterprise ...
Microsoft NYC 14

Viewers also liked (20)

PPTX
Big data streaming with Apache Spark on Azure
PDF
Enterprise Data Workflows with Cascading and Windows Azure HDInsight
PPTX
Azure Stream Analytics : Analyse Data in Motion
PPTX
2016-08-25 TechExeter - going serverless with Azure
PPTX
Going serverless
PDF
Azure HDInsight
PPTX
Software scope
PPTX
Azure functions
PPTX
Open up to a better learning ecosystem
PPTX
Spark on Azure HDInsight - spark meetup seattle
PPTX
Building big data solutions on azure
PDF
Microsoft Azure For Solutions Architects
PDF
Going serverless
PDF
Industrial Internet of Things in Cleantech
PPTX
DC Spark bake off - Realtime TCP Packet Analysis using Spark and Azure Event ...
PPTX
Getting started with azure event hubs and stream analytics services
PPTX
Spark in yarn managed multi-tenant clusters
PPTX
Azure Stream Analytics
PPTX
Big data solutions in azure
PPTX
Event Hub & Azure Stream Analytics
Big data streaming with Apache Spark on Azure
Enterprise Data Workflows with Cascading and Windows Azure HDInsight
Azure Stream Analytics : Analyse Data in Motion
2016-08-25 TechExeter - going serverless with Azure
Going serverless
Azure HDInsight
Software scope
Azure functions
Open up to a better learning ecosystem
Spark on Azure HDInsight - spark meetup seattle
Building big data solutions on azure
Microsoft Azure For Solutions Architects
Going serverless
Industrial Internet of Things in Cleantech
DC Spark bake off - Realtime TCP Packet Analysis using Spark and Azure Event ...
Getting started with azure event hubs and stream analytics services
Spark in yarn managed multi-tenant clusters
Azure Stream Analytics
Big data solutions in azure
Event Hub & Azure Stream Analytics
Ad

Similar to Azure IoT Hub on a Toradex Colibri VF61 – Part 1 - Sending data to the cloud (20)

PPTX
IoT Parking Lot Demo on Toradex Modules
PDF
Simplifying IoT App Development - A Whitepaper by RapidValue
PPTX
Azure IoT Hub on a Toradex Colibri VF61 – Part 2 - Interfacing sensors and th...
PPTX
Learn how to make your IoT pilot projects and POCs successful
PDF
ONLINE FOOD ORDERS THROUGH WHATSAPP AUTOMATION BOT
PDF
IOT Based Smart City: Weather, Traffic and Pollution Monitoring System
PPTX
Windows Azure(Pr-1).ppt.pptx
PDF
The Security Of Cloud Computing
PDF
Seminar_report on Microsoft Azure Service
PDF
IBM Bluemix Nice Meetup #1 - CEEI NCA - 20160630 -
PDF
Cloud computing in iot seminar report
PPTX
Modular Embedded Design to Accelerate IoT Proliferation
PDF
How to Choose the Right Tech Stack for IoT Software Development
PPTX
Ultimate list of 50 Best IoT platforms of 2019
PDF
8 pre launch steps to go with the web rtc based application development
PDF
IRJET- IoT based Vending Machine with Cashless Payment
PDF
A unified dashboard for collaborative robot management system
PDF
IRJET- Smart Parking System using IoT
PDF
Iot App Demt (2).pdf
PDF
IRJET - Multitenancy using Cloud Computing Features
IoT Parking Lot Demo on Toradex Modules
Simplifying IoT App Development - A Whitepaper by RapidValue
Azure IoT Hub on a Toradex Colibri VF61 – Part 2 - Interfacing sensors and th...
Learn how to make your IoT pilot projects and POCs successful
ONLINE FOOD ORDERS THROUGH WHATSAPP AUTOMATION BOT
IOT Based Smart City: Weather, Traffic and Pollution Monitoring System
Windows Azure(Pr-1).ppt.pptx
The Security Of Cloud Computing
Seminar_report on Microsoft Azure Service
IBM Bluemix Nice Meetup #1 - CEEI NCA - 20160630 -
Cloud computing in iot seminar report
Modular Embedded Design to Accelerate IoT Proliferation
How to Choose the Right Tech Stack for IoT Software Development
Ultimate list of 50 Best IoT platforms of 2019
8 pre launch steps to go with the web rtc based application development
IRJET- IoT based Vending Machine with Cashless Payment
A unified dashboard for collaborative robot management system
IRJET- Smart Parking System using IoT
Iot App Demt (2).pdf
IRJET - Multitenancy using Cloud Computing Features
Ad

More from Toradex (20)

PDF
How to Choose the Right Embedded Computing Provider: Why Toradex Stands Out
PDF
Linux Support for SMARC: How Toradex Empowers Embedded Developers
PDF
Torizon collaborates with Texas Instruments to Simplify Cybersecurity Complia...
PDF
Toradex's New SMARC SoM Family: Reliable, Cost-Effective, and Ready for Tomor...
PDF
Press Release: Toradex Japan Showcases Latest Embedded Technology at Key Indu...
PDF
Whitepaper Cybersecurity in Medical Devices
PDF
プレスリリース:電子機器2024トータルソリューション展にToradexの代理店が参加します!.pdf
PDF
Toradex Strengthens Custom Solutions Offering with Acquisition of Linear Comp...
PDF
プレスリリース:ToradexがJapan IT Week【春】2024年に出展
PDF
Introducing Aquila: The Next Generation Toradex SoM Family
PDF
Join Toradex at Japan IT Week Spring 2024
PDF
Toradex announces Titan Eval Kit w/ NXP's i.MX 95 - Early Access Program
PDF
ToradexがJapan IT Week【春】2023年に出展
PDF
NXP Semiconductors elevates Toradex to Platinum Partner status
PDF
Webinar: Secure Offline and Online Updates for Linux Devices
PDF
Toradex opens office in Tokyo, reaffirming its growth strategy in the Asia-Pa...
PDF
Toradex launches Verdin featuring NXP i.MX 8M Mini/Nano SoMs
PPTX
Ethernet Compliance Testing at Toradex
PPTX
Webinar On-demand: Introducing the new Colibri SoM based on the NXP i.MX 6ULL...
PDF
Starting with OpenCV on i.MX 6 Processors
How to Choose the Right Embedded Computing Provider: Why Toradex Stands Out
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Torizon collaborates with Texas Instruments to Simplify Cybersecurity Complia...
Toradex's New SMARC SoM Family: Reliable, Cost-Effective, and Ready for Tomor...
Press Release: Toradex Japan Showcases Latest Embedded Technology at Key Indu...
Whitepaper Cybersecurity in Medical Devices
プレスリリース:電子機器2024トータルソリューション展にToradexの代理店が参加します!.pdf
Toradex Strengthens Custom Solutions Offering with Acquisition of Linear Comp...
プレスリリース:ToradexがJapan IT Week【春】2024年に出展
Introducing Aquila: The Next Generation Toradex SoM Family
Join Toradex at Japan IT Week Spring 2024
Toradex announces Titan Eval Kit w/ NXP's i.MX 95 - Early Access Program
ToradexがJapan IT Week【春】2023年に出展
NXP Semiconductors elevates Toradex to Platinum Partner status
Webinar: Secure Offline and Online Updates for Linux Devices
Toradex opens office in Tokyo, reaffirming its growth strategy in the Asia-Pa...
Toradex launches Verdin featuring NXP i.MX 8M Mini/Nano SoMs
Ethernet Compliance Testing at Toradex
Webinar On-demand: Introducing the new Colibri SoM based on the NXP i.MX 6ULL...
Starting with OpenCV on i.MX 6 Processors

Recently uploaded (20)

PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Cloud computing and distributed systems.
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
cuic standard and advanced reporting.pdf
PPTX
Big Data Technologies - Introduction.pptx
PPTX
A Presentation on Artificial Intelligence
PDF
Approach and Philosophy of On baking technology
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Machine learning based COVID-19 study performance prediction
PDF
Review of recent advances in non-invasive hemoglobin estimation
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Encapsulation_ Review paper, used for researhc scholars
Network Security Unit 5.pdf for BCA BBA.
Cloud computing and distributed systems.
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Understanding_Digital_Forensics_Presentation.pptx
cuic standard and advanced reporting.pdf
Big Data Technologies - Introduction.pptx
A Presentation on Artificial Intelligence
Approach and Philosophy of On baking technology
CIFDAQ's Market Insight: SEC Turns Pro Crypto
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Machine learning based COVID-19 study performance prediction
Review of recent advances in non-invasive hemoglobin estimation
The AUB Centre for AI in Media Proposal.docx
Encapsulation_ Review paper, used for researhc scholars

Azure IoT Hub on a Toradex Colibri VF61 – Part 1 - Sending data to the cloud

  • 1. Azure IoT Hub on a Toradex Colibri VF61 – Part 1: Sending data to the cloud
  • 2. |www.toradex.com Toradex® is a registered trademark of Montadex GmbH June’16 2 CHAIRMAN Introduction The concept of the Internet of Things is intrinsically related to the sending of data to the internet and its so called cloud services. People from the electronics field are everyday more easily connecting devices to the cloud as the evolution of technology is allowing the use of smaller and less power-consuming electronics as time goes by. Still there is an unanswered question for many of these electronics developers: how to make all of the gathered data useful? Because that is what the Internet of Things is about.
  • 3. |www.toradex.com Toradex® is a registered trademark of Montadex GmbH June’16 3 CHAIRMAN There are some examples of real applications taken from the Microsoft website in order to share a preview of what the IoT can represent: there is an elevator company using the internet of things to improve and give predictive maintenance; an automation company using IoT to have insights from the oil and gas industry's supply chain, along with predictive maintenance; and a company that uses IoT to predict drivers behaviors and optimize car utilization. By the end of this series of articles, it is expected that the reader might have enough information and tools ready to deploy applications that retrieve insights and/or optimize its overall system – not only an amount of data stacked, but some useful output! Azure is the Microsoft cloud services platform and it provides an amount of applications such as databases, virtual machines, app services, machine learning, data stream analysis, media and CDN services, big data solutions, among many others, including the IoT Hub.
  • 4. |www.toradex.com Toradex® is a registered trademark of Montadex GmbH June’16 4 CHAIRMAN By itself, the vastness of services offered is already a good reason to use the Azure services, but Microsoft goes one step ahead and compare its services with the Amazon Web Services to reinforce that their solution is the better – a strong statement that only users and time will confirm, or the other way around. Among the reasons to use their services is the security offered, the easiness of integration and the gentle learning curve. The main goal of this article is to develop an IoT application, from the reading of field sensors to the presentation of results and the retrieving of business intelligence. The hardware used to collect the sensors data and send it to the cloud is: a Toradex Colibri VF61 SoM + the Iris Carrier Board, since Toradex is an Azure IoT certified partner. . This is, therefore, an advantage, once Toradex is an Azure IoT Certified Partner.
  • 5. |www.toradex.com Toradex® is a registered trademark of Montadex GmbH June’16 5 CHAIRMAN The application should get some sensors data and send it to an IoT service from the Microsoft Azure cloud solution, called Azure IoT Hub. Once the data is being received on the cloud, it can be processed in many ways by other Microsoft Azure services. That is what will be done in the second part of this article series, but for now the focus will be on how to configure the Azure IoT Hub and send messages to it. The chosen IoT environment was the monitoring of a car. For demonstration purposes, sensors were attached to a remote controlled car, to which a Toradex customized SBC was also embedded. In the image 1 it is possible to see the picture of the demo and the image 2 holds a block representation of the aimed application.
  • 6. |www.toradex.com Toradex® is a registered trademark of Montadex GmbH June’16 6 CHAIRMAN Image 1: The remote controlled car
  • 7. |www.toradex.com Toradex® is a registered trademark of Montadex GmbH June’16 7 CHAIRMAN Image 2: Block diagram of the application
  • 8. |www.toradex.com Toradex® is a registered trademark of Montadex GmbH June’16 8 CHAIRMAN The programming language chosen to develop the target application is the Javascript along with Node.js: a server-side (which in this case is the Toradex embedded system) Javascript interpreter built on the Chrome's V8 engine. Its choice was based on the availability of libraries provided by the Azure Iot Hub SDKs. It should be noticed that the IoT Hub SDKs are under heavy development, with changes being made every new release (at least for Node), and it should be taken under consideration. The release version of the Azure IoT Node packages being used in this article is the version 1.0.1. The setup of the whole environment, from the programming of the embedded system to the configuration of Azure in order to receive data was divided in three steps, described in this article:
  • 9. |www.toradex.com Toradex® is a registered trademark of Montadex GmbH June’16 9 CHAIRMAN • Configuration of the Azure environment • Adding devices and sending messages to the IoT Hub • Programming the Toradex embedded system application Configuration of the Azure environment The first step needed to start developing the whole system is to create an Azure account: a free account can be created from the Azure website as a 30 day trial. Than a fixed amount of azure credits can be used to deploy applications that use the Azure services without charge; also, the IoT Hub has a free version dedicated to development, with limited resources, also free of charge, even beyond the trial period. For more details about the pricing and the IoT Hub per se, the IoT Hub page can be visited.
  • 10. |www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 10 CHAIRMAN After setting an Azure account, it is first needed to create an IoT Hub. For that, the Azure portal should be accessed using the newly created account and the options +New > Internet of Things > Azure IoT Hub selected. The configuration screen for the new IoT Hub is shown in image 3. The option "Free" should be selected in the Pricing and scale tier; a new resource group should be created in the Resource Group field and the Location selected must match the location of the other services to be deployed later. Any Name can be chosen and the IoT Hub Units and Device-to-cloud partitions fields cannot be edited in the free version. After clicking create, the service will be deployed – and it might take a few seconds.
  • 11. |www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 11
  • 12. |www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 12 CHAIRMAN That being done, the IoT Hub should appear in the Dashboard, that is, the main Azure Portal page. After clicking it, a page like in the image 4 should open: there will be some Essentials information such as the region of the IoT Hub; an Usage section that gives a feedback to the system administrator regarding how many messages were sent from devices to this service and the number of registered devices; and a Monitoring section where the number of messages received over time are displayed. Image 3: Creating an IoT Hub from the Azure Portal
  • 13. |www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 13 CHAIRMAN
  • 14. |www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 14 CHAIRMAN Image 4: IoT Hub main panel Still on the panel from image 4, in order to gain access to the service from other applications, the Shared access policies option over the Settings tab should be selected. In the new tab Shared access policies that will open, there will be a policy called "iothubowner", which has all possible permissions to this IoT Hub and it should be clicked. The iothubowner tab will open and its Connection string – primary key should be copied for later usage: it is the key that will allow management and monitoring of this IoT Hub devices in the next steps. The tabs described in this paragraph to get the connection string are illustrated in the image 5.
  • 15. |www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 15 CHAIRMAN
  • 16. |www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 16 CHAIRMAN Adding devices and sending messages to the IoT Hub Now that everything is configured in the cloud, the iothub-exporer tool needs to be installed on the development machine so that devices can be added to the IoT Hub. There is another tool named Device Explorer, only available for Windows systems, so if Windows is being used in the development machine, this option might be checked out. Since in this article the Ubuntu 14.04 is being used, I will stick to the iothub-explorer. It should be noted that the Node version running needs to be at least 0.12.x (it says a version 4.x or higher is needed for all the features to work), but at the time this article was written, the apt-get tool was currently installing some 0.10.x version. To solve this issue, the Node Version Manager (NVM) and, subsequently, the Node version 0.12.9 were installed. From the terminal, the iothub-explorer can be installed using the NPM (Node Package Manager): Image 5: Getting the iothubowner connection string
  • 17. |www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 17 CHAIRMAN leonardo@leonardo:~$ npm install iothub-explorer@latest Then the iothub-explorer can be run with the help option to see its usage possibilities: leonardo@leonardo:~$ iothub-explorer help As it can be seen in the terminal from the previous command, among the iothub- explorer options there are create and monitor-events. In order to use this tool, the connection string acquired in the image 5 must be used. First of all, a device named "tdx_iot_car" will be created, as in the command below. Note the option –connection- string that displays the device connection string (not to be confused with the IoT Hub connection string). It should be copied since it is the key used to connect this newly created device to the IoT Hub, by enabling the Colibri VF61 application to send messages to the Hub.
  • 18. |www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 18 CHAIRMAN leonardo@leonardo:~$ iothub-explorer "HostName=toradex.azure- devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=putyoursharedacc esskeyfromtheconnectionstringhere" create tdx_iot_car --connection-string Created device tdx_iot_car - deviceId: tdx_iot_car generationId: 635931262207620183 etag: MA== connectionState: Disconnected status: enabled statusReason: null connectionStateUpdatedTime: 0001-01-01T00:00:00 statusUpdatedTime: 0001-01-01T00:00:00 lastActivityTime: 0001-01-01T00:00:00 cloudToDeviceMessageCount: 0
  • 19. |www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 19 CHAIRMAN authentication: SymmetricKey: primaryKey: somesharedaccesskeyreturned secondaryKey: somesecondaryaccesskeyreturned - connectionString: HostName=toradex.azure- devices.net;DeviceId=tdx_iot_car;SharedAccessKey=somesharedaccesskeyreturned Programming the Toradex embedded system application Now a Colibri VF61 SoM + Iris Carrier Board should be set. In this article a pre-build image (Colibri_VF_LinuxConsoleImageV2.5) that can be downloaded here was used. Instructions on how to flash the image to the Colibri module can be found here. In order to install the Node.js, the NPM package and git, the following instructions were issued – be aware that it might take a few minutes to complete, especially the curl instruction:
  • 20. |www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 20 CHAIRMAN The repository where are the packages installer and the node file regarding this article example – send_data.js – can be cloned into the the board. To clone and install the node packages, the following commands must be run:
  • 21. |www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 21 CHAIRMAN Now the code that sends data to the IoT Hub can be run, but first let's explain some points about it: it is used the HTTP protocol to provide communication, but the AMQP and MQTT protocols are also supported; The variable named connectionString value must be the same string got from a few steps above, while creating the device with the iothub-explorer: var connectionString = "HostName=toradex.azure- devices.net;DeviceId=tdx_iot_car;SharedAccessKey=somesharedaccesske yreturned" Inside the setInterval() loop many values are randomly created to be sent to the IoT Hub as if it were data from some sensors, such as temperature, distance from an ultrasonic sensor, acceleration and gyro, some gps coordinates and the date/time from the board.
  • 22. |www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 22 CHAIRMAN How to get this data from real sensors will be addressed in the next article from this series. The JSON.Stringify() function generates a JSON encoded string from the data and it is encapsulated in a Message object to be sent. Below an example of a a JSON formatted string is presented:
  • 23. |www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 23 CHAIRMAN In case everything goes well, the callback function from the sendEvent() method should not print anything to the console while the code is running. The following command runs the Colibri VF61 code and displays the feedback message continuously printed to the console when all goes right:
  • 24. |www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 24 CHAIRMAN As a feedback to guarantee that the data is being received, the IoT Hub section of the Azure Portal should update the daily message count and the monitoring graph should present with a spike, as shown in image 6. Note that it might take from a few seconds to more than a minute until this information gets updated in the portal.
  • 25. |www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 25 CHAIRMAN
  • 26. |www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 26 CHAIRMAN Image 6: Checking in the Azure Portal that data is being received
  • 27. |www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 27 CHAIRMAN To see the data stream that is coming into the IoT Hub, the iothub-explorer tool may be used. To achieve this, the monitor-events option must be used with the device id. Note that, for this to work, the Colibri VF61 application must be running at the same time that the iothub-explorer, whereas to see the statistics from the Azure Portal there is no need for it. The image 7 displays the iothub-explorer receiving the data while the board was sending it simultaneously. The command to monitor the events is displayed above, before the image: leonardo@leonardo:~$ iothub-explorer "your_iothub_connection_string" monitor-events yourdevice
  • 28. |www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 28 CHAIRMAN Image 7: Receiving data from the board into the iothub-explorer
  • 29. |www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 29 CHAIRMAN The Microsoft Azure website has plenty of documentation about the Iot Hub as more information is needed to develop more complex and/or robust applications. There are things such as creating a device, or getting messages sent from devices to the Hub, that can be accomplished programatically – refering to the documentation is a good way to obtain more information on the matter. Also, in the next article the focus will be in interfacing some sensors to the Colibri VF61 + Iris Carrier Board and than, as real data is sent to the IoT Hub, it can be used as an input to other Azure services that can generate insights and/or add some control variables to the deployed application.
  • 30. |www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 30 CHAIRMAN I hope it was a helpful introductory article on how to join a Toradex SBC solution with the Azure IoT Hub service and that you may find it useful! Also, I would like to thank the Grupo Viceri team from Brazil for their expertise regarding Azure and Business Intelligence, that led to the partnership that which resulted in the IoT Car project. See you soon in the next article. This blog post was originally featured on Embarcados.com in Portuguese. See here.
  • 31. |www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 31 Thank you!